Making generic ld testcases pass on more targets
Alan Modra
amodra@bigpond.net.au
Wed Feb 16 14:15:00 GMT 2005
There are a number of ld testcases that fail on various targets, all due
to relocation problems. The typical testcase does something like
.long foo
and expects this to work regardless of the size of addresses. On 64-bit
targets, the default linker script might locate foo somewhere above 4G,
which will mean a reloc overflow. Also, some 64-bit targets don't
support 32-bit relocations in shared libraries. At the other extreme, a
16-bit target might not even have 32-bit relocs.
So it would be nice to have a means of creating a suitably sized
address, if only for the ld testsuite. One possibility is to define a
symbol (or trickery a la md_parse_name) which could be tested. eg.
.ifle __address_size - 32
.ifle __address_size - 16
.word foo
.else
.long foo
.endif
.else
.quad foo
.endif
Another way is to define a new pseudo, .dc.a say, that magically does
the above. Easily hacked together like the following, but I'd like to
solicit opinion on which approach is better (or something else entirely)
before I commit.
* read.c (potable): Add "dc.a".
(cons_worker): Handle dc.a.
Index: gas/read.c
===================================================================
RCS file: /cvs/src/src/gas/read.c,v
retrieving revision 1.88
diff -u -p -r1.88 read.c
--- gas/read.c 31 Jan 2005 14:26:08 -0000 1.88
+++ gas/read.c 16 Feb 2005 11:41:01 -0000
@@ -263,6 +263,9 @@ static const pseudo_typeS potable[] = {
{"common.s", s_mri_common, 1},
{"data", s_data, 0},
{"dc", cons, 2},
+#ifdef BFD_ASSEMBLER
+ {"dc.a", cons, 0},
+#endif
{"dc.b", cons, 1},
{"dc.d", float_cons, 'd'},
{"dc.l", cons, 4},
@@ -3339,6 +3342,18 @@ cons_worker (register int nbytes, /* 1=.
return;
}
+#ifdef BFD_ASSEMBLER
+ if (nbytes == 0)
+ {
+ /* Choose smallest of 1, 2, 4, 8 bytes that is large enough to
+ contain an address. */
+ nbytes = (stdoutput->arch_info->bits_per_address - 1) / 8;
+ nbytes |= nbytes >> 1;
+ nbytes |= nbytes >> 2;
+ nbytes += 1;
+ }
+#endif
+
#ifdef md_cons_align
md_cons_align (nbytes);
#endif
--
Alan Modra
IBM OzLabs - Linux Technology Centre
More information about the Binutils
mailing list