This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Committed: add new CRIS TLS reloc: R_CRIS_32_IE
- From: Hans-Peter Nilsson <hans-peter dot nilsson at axis dot com>
- To: binutils at sourceware dot org
- Date: Sat, 20 Dec 2008 01:33:44 +0100
- Subject: Committed: add new CRIS TLS reloc: R_CRIS_32_IE
Doh. I mistakenly thought no non-pic reloc was needed for the
initial-exec model. I could abuse R_CRIS_32_GOT_TPREL or *16
and add _GLOBAL_OFFSET_TABLE_, but I'd still have to tweak
tc-cris.c anyway to allow that decoration without -pic (and add
tests to the gas testsuite; the ld testsuite already covers
that). Albeit a smaller change, since it's not the best choice,
better add the "missing" reloc. Committed.
Other than that, allowing [foo:IE] and [foo:GD] (TLS decorations
on double-indirect addressing mode) makes sense, so I added
that. It doesn't make sense for PIC relocs, that's why it
wasn't there, and the addressing mode isn't supported for CRIS
v32 so it doesn't get focus.
Tested cris-elf, committed... except for tls-ie-78.d which
requires the ld_after_inputfiles feature (still awaiting
approval); the actually committed ChangeLog adjusted.
include:
* cris.h (R_CRIS_32_IE): New relocation.
bfd:
* elf32-cris.c (cris_elf_howto_table): Add entry for R_CRIS_32_IE.
(cris_reloc_map): Similarly.
(cris_elf_relocate_section, cris_elf_gc_sweep_hook)
(cris_elf_check_relocs): Handle R_CRIS_32_IE.
* reloc.c (bfd_reloc_code_type): Add entry for R_CRIS_32_IE.
* bfd-in2.h, libbfd.h: Regenerate.
gas:
* config/tc-cris.c (cris_process_instruction): Handle
BFD_RELOC_CRIS_32_IE, in the test whether the relocation fits.
(get_3op_or_dip_prefix_op): Handle TLS/PIC decoration for the
"double indirect" addressing mode.
(cris_get_reloc_suffix): Add entry for :IE for BFD_RELOC_CRIS_32_IE.
(cris_number_to_imm, tc_gen_reloc): Handle BFD_RELOC_CRIS_32_IE.
gas/testsuite:
* gas/cris/rd-tls-1.s, gas/cris/rd-tls-1.d: Test :IE and
decoration on double-indirect.
* gas/cris/tls-err-1.s: Test :IE on wrong-size operand.
ld/testsuite:
* ld-cris/tls-err-77.d, ld-cris/tls-ie-78.d, ld-cris/tls-gc-79.d,
ld-cris/tls-ie-8e.s, ld-cris/tls-ie-8e1.d: New tests.
Index: ld-cris/tls-err-77.d
===================================================================
RCS file: ld-cris/tls-err-77.d
diff -N ld-cris/tls-err-77.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld-cris/tls-err-77.d 20 Dec 2008 00:03:06 -0000
@@ -0,0 +1,7 @@
+#source: tls-ie-8e.s
+#source: tls-x.s
+#as: --no-underscore --em=criself
+#ld: --shared -m crislinux
+#error: \A[^\n]*\.o, [^\n]*\n[^\n]*mixup[^\n]*\n[^\n]*Invalid operation\Z
+
+# Check that a R_CRIS_32_IE in input to a DSO is flagged as an error.
Index: ld-cris/tls-ie-78.d
===================================================================
RCS file: ld-cris/tls-ie-78.d
diff -N ld-cris/tls-ie-78.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld-cris/tls-ie-78.d 20 Dec 2008 00:03:06 -0000
@@ -0,0 +1,44 @@
+#source: start1.s
+#source: tls128.s
+#source: tls-ie-8e.s
+#as: --no-underscore --em=criself
+#ld: -m crislinux
+#ld_after_inputfiles: tmpdir/tls-dso-xz-1.so
+#objdump: -s -h -t -T -R -r -p
+
+# Check that we have proper NPTL/TLS markings and GOT for a
+# R_CRIS_32_IE, for an executable, symbol defined elsewhere.
+
+.*: file format elf32-cris
+
+Program Header:
+#...
+ TLS off .*
+ filesz 0x0+80 memsz 0x0+80 flags r--
+
+Dynamic Section:
+ NEEDED tmpdir/tls-dso-xz-1.so
+#...
+private flags = 0:
+#...
+ 8 .got[ ]+0+10 .*
+ CONTENTS, ALLOC, LOAD, DATA
+SYMBOL TABLE:
+#...
+0+ \*UND\* 0+ x
+#...
+DYNAMIC SYMBOL TABLE:
+0+ D \*UND\* 0+ x
+#...
+DYNAMIC RELOCATION RECORDS
+OFFSET TYPE VALUE
+0+822d4 R_CRIS_32_TPREL x
+
+Contents of section .interp:
+#...
+Contents of section \.text:
+ 801bc 41b20000 6faed422 08000000 .*
+Contents of section \.tdata:
+#...
+Contents of section \.got:
+ 822c8 48220800 00000000 00000000 00000000 .*
Index: ld-cris/tls-gc-79.d
===================================================================
RCS file: ld-cris/tls-gc-79.d
diff -N ld-cris/tls-gc-79.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld-cris/tls-gc-79.d 20 Dec 2008 00:03:06 -0000
@@ -0,0 +1,34 @@
+#source: start1.s
+#source: tls128.s
+#source: tls-ie-8e.s
+#source: tls-x.s
+#as: --no-underscore --em=criself
+#ld: -m crislinux --gc-sections
+#objdump: -s -t -r -p
+
+# An executable with a single R_CRIS_32_IE, with gc. Check that we
+# have nothing left but the start symbol and its code. Can't get rid
+# of the GOT just yet.
+
+.*: file format elf32-cris
+
+Program Header:
+ LOAD off 0x0+ vaddr 0x0+80000 paddr 0x0+80000 align 2\*\*13
+ filesz 0x0+78 memsz 0x0+78 flags r-x
+ LOAD off 0x0+78 vaddr 0x0+82078 paddr 0x0+82078 align 2\*\*13
+ filesz 0x0+c memsz 0x0+c flags rw-
+private flags = 0:
+
+SYMBOL TABLE:
+0+80074 l d .text 0+ .text
+0+82078 l d .got 0+ .got
+0+82078 l O .got 0+ .hidden _GLOBAL_OFFSET_TABLE_
+0+80074 g .text 0+ _start
+0+82084 g \*ABS\* 0+ __bss_start
+0+82084 g \*ABS\* 0+ _edata
+0+820a0 g \*ABS\* 0+ _end
+
+Contents of section .text:
+ 80074 41b20+ .*
+Contents of section .got:
+ 82078 0+ 0+ 0+ .*
Index: ld-cris/tls-ie-8e.s
===================================================================
RCS file: ld-cris/tls-ie-8e.s
diff -N ld-cris/tls-ie-8e.s
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld-cris/tls-ie-8e.s 20 Dec 2008 00:03:06 -0000
@@ -0,0 +1,8 @@
+ .text
+ .global tlsfn
+ .type tlsfn,@function
+ .p2align 1
+tlsfn:
+ move.d x:IE,$r10
+.Lfe8:
+ .size tlsfn,.Lfe8-tlsfn
Index: ld-cris/tls-ie-8e1.d
===================================================================
RCS file: ld-cris/tls-ie-8e1.d
diff -N ld-cris/tls-ie-8e1.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld-cris/tls-ie-8e1.d 20 Dec 2008 00:03:06 -0000
@@ -0,0 +1,42 @@
+#as: --no-underscore --em=criself
+#ld: -m crislinux
+#source: start1.s
+#source: tls-ie-8e.s
+#source: tls128g.s
+#source: tls-x.s
+#objdump: -d -s -h -t -r -p
+
+# Executable with a single R_CRIS_32_IE, defined in the executable.
+# Check that we have proper NPTL/TLS markings and a constant GOT.
+
+.*: file format elf32-cris
+
+Program Header:
+#...
+ TLS off 0x0+a0 vaddr 0x0+820a0 paddr 0x0+820a0 align 2\*\*2
+ filesz 0x0+84 memsz 0x0+84 flags r--
+private flags = 0:
+
+Sections:
+#...
+ 2 .got[ ]+ 0+10 .*
+ CONTENTS, ALLOC, LOAD, DATA
+
+SYMBOL TABLE:
+#...
+0+80 g \.tdata 0+4 x
+#...
+Contents of section .text:
+ 80094 41b20000 6fae3021 08000000 .*
+#...
+Contents of section .got:
+ 82124 00000000 00000000 00000000 80000000 .*
+
+Disassembly of section .text:
+
+00080094 <_start>:
+ 80094: 41b2 moveq 1,\$r11
+#...
+00080098 <tlsfn>:
+ 80098: 6fae 3021 0800 move.d 82130 <_GLOBAL_OFFSET_TABLE_\+0xc>,\$r10
+#pass
Index: gas/cris/rd-tls-1.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/cris/rd-tls-1.d,v
retrieving revision 1.2
diff -p -u -r1.2 rd-tls-1.d
--- gas/cris/rd-tls-1.d 19 Nov 2008 06:16:54 -0000 1.2
+++ gas/cris/rd-tls-1.d 19 Dec 2008 23:49:17 -0000
@@ -25,4 +25,7 @@ Disassembly of section \.text:
[ ]+2e:[ ]+R_CRIS_16_TPREL extsym14\+0xffffff00
[ ]+32:[ ]+6fad 0000 0000 287a[ ]+add\.d \[\$?r10\+0 <start>\],\$?r7,\$?r8
[ ]+34:[ ]+R_CRIS_32_TPREL extsym3\+0x38
-[ ]+\.\.\.
+[ ]+3a:[ ]+7f0d 0000 0000 611a[ ]+move.d \[0 <start>],\$?r1
+[ ]+3c:[ ]+R_CRIS_32_IE[ ]+extsym5
+[ ]+42:[ ]+2fbe 0000 0000[ ]+add\.d 0 <start>,\$?r11
+[ ]+44:[ ]+R_CRIS_32_IE[ ]+extsym7
Index: gas/cris/rd-tls-1.s
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/cris/rd-tls-1.s,v
retrieving revision 1.2
diff -p -u -r1.2 rd-tls-1.s
--- gas/cris/rd-tls-1.s 19 Nov 2008 06:16:54 -0000 1.2
+++ gas/cris/rd-tls-1.s 19 Dec 2008 23:49:17 -0000
@@ -21,3 +21,5 @@ start:
move.d [r7=r3+extsym10:GD-330],r13
move.d [r11+extsym14:TPOFF16-256],r9
add.d [r10+extsym3:TPOFF+56],r7,r8
+ move.d [extsym5:IE],r1
+ add.d extsym7:IE,r11
Index: gas/cris/tls-err-1.s
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/cris/tls-err-1.s,v
retrieving revision 1.1
diff -p -u -r1.1 tls-err-1.s
--- gas/cris/tls-err-1.s 4 Oct 2008 17:23:44 -0000 1.1
+++ gas/cris/tls-err-1.s 19 Dec 2008 23:49:17 -0000
@@ -14,3 +14,5 @@ start:
move.b extsym15:GD,r7 ; { dg-error "TLS relocation size does not match" }
move.w extsym6:GD,r5 ; { dg-error "TLS relocation size does not match" }
move extsym8:TPOFF16,srp ; { dg-error "TLS relocation size does not match" }
+ move.b extsym5:IE,r7 ; { dg-error "TLS relocation size does not match" }
+ move.w extsym16:IE,r5 ; { dg-error "TLS relocation size does not match" }
Index: config/tc-cris.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-cris.c,v
retrieving revision 1.43
diff -p -u -r1.43 tc-cris.c
--- config/tc-cris.c 19 Nov 2008 06:16:04 -0000 1.43
+++ config/tc-cris.c 19 Dec 2008 23:44:45 -0000
@@ -2208,6 +2208,7 @@ cris_process_instruction (char *insn_tex
as_bad (out_insnp->reloc == BFD_RELOC_CRIS_32_GD
|| out_insnp->reloc == BFD_RELOC_CRIS_32_TPREL
|| out_insnp->reloc == BFD_RELOC_CRIS_16_TPREL
+ || out_insnp->reloc == BFD_RELOC_CRIS_32_IE
? _("TLS relocation size does not match operand size")
: _("PIC relocation size does not match operand size"));
}
@@ -3045,6 +3046,10 @@ get_3op_or_dip_prefix_op (char **cPP, st
prefixp->kind = PREFIX_DIP;
prefixp->opcode = DIP_OPCODE | (AUTOINCR_BIT << 8) | REG_PC;
prefixp->reloc = BFD_RELOC_32;
+
+ /* For :GD and :IE, it makes sense to have TLS specifiers here. */
+ if ((pic || tls) && **cPP == RELOC_SUFFIX_CHAR)
+ cris_get_reloc_suffix (cPP, &prefixp->reloc, &prefixp->expr);
}
else
/* Neither '[' nor register nor expression. We lose. */
@@ -3489,6 +3494,7 @@ cris_get_reloc_suffix (char **cPP, bfd_r
TLSMAP ("GD", BFD_RELOC_CRIS_32_GD),
PICTLSMAP ("DTPREL16", BFD_RELOC_CRIS_16_DTPREL),
PICTLSMAP ("DTPREL", BFD_RELOC_CRIS_32_DTPREL),
+ TLSMAP ("IE", BFD_RELOC_CRIS_32_IE),
PICTLSMAP ("TPOFFGOT16", BFD_RELOC_CRIS_16_GOT_TPREL),
PICTLSMAP ("TPOFFGOT", BFD_RELOC_CRIS_32_GOT_TPREL),
TLSMAP ("TPOFF16", BFD_RELOC_CRIS_16_TPREL),
@@ -3630,6 +3636,7 @@ cris_number_to_imm (char *bufp, long val
case BFD_RELOC_CRIS_32_GOT_GD:
case BFD_RELOC_CRIS_16_GOT_GD:
case BFD_RELOC_CRIS_32_GD:
+ case BFD_RELOC_CRIS_32_IE:
case BFD_RELOC_CRIS_32_DTPREL:
case BFD_RELOC_CRIS_16_DTPREL:
case BFD_RELOC_CRIS_32_GOT_TPREL:
@@ -3911,6 +3918,7 @@ tc_gen_reloc (asection *section ATTRIBUT
case BFD_RELOC_CRIS_32_GOT_GD:
case BFD_RELOC_CRIS_16_GOT_GD:
case BFD_RELOC_CRIS_32_GD:
+ case BFD_RELOC_CRIS_32_IE:
case BFD_RELOC_CRIS_32_DTPREL:
case BFD_RELOC_CRIS_16_DTPREL:
case BFD_RELOC_CRIS_32_GOT_TPREL:
Index: cris.h
===================================================================
RCS file: /cvs/src/src/include/elf/cris.h,v
retrieving revision 1.9
diff -p -u -r1.9 cris.h
--- cris.h 25 Nov 2008 03:08:13 -0000 1.9
+++ cris.h 19 Dec 2008 23:01:18 -0000
@@ -166,6 +166,11 @@ START_RELOC_NUMBERS (elf_cris_reloc_type
(usually the fourth one). */
RELOC_NUMBER (R_CRIS_DTPMOD, 30)
+ /* Similar to R_CRIS_32_GOT_TPREL, but the value is the absolute
+ address of the GOT entry. Disallowed in DSOs created with
+ -shared. Assembly syntax: "sym:IE". */
+ RELOC_NUMBER (R_CRIS_32_IE, 31)
+
/* No other relocs must be visible outside the assembler. */
END_RELOC_NUMBERS (R_CRIS_max)
Index: elf32-cris.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-cris.c,v
retrieving revision 1.93
diff -p -u -r1.93 elf32-cris.c
--- elf32-cris.c 17 Dec 2008 02:31:16 -0000 1.93
+++ elf32-cris.c 19 Dec 2008 22:40:41 -0000
@@ -436,7 +436,8 @@ static reloc_howto_type cris_elf_howto_t
TLSHOWTO16S (R_CRIS_16_GOT_TPREL),
TLSHOWTO32 (R_CRIS_32_TPREL),
TLSHOWTO16S (R_CRIS_16_TPREL),
- TLSHOWTO32 (R_CRIS_DTPMOD)
+ TLSHOWTO32 (R_CRIS_DTPMOD),
+ TLSHOWTO32 (R_CRIS_32_IE)
};
/* Map BFD reloc types to CRIS ELF reloc types. */
@@ -479,7 +480,8 @@ static const struct cris_reloc_map cris_
{ BFD_RELOC_CRIS_16_GOT_TPREL, R_CRIS_16_GOT_TPREL },
{ BFD_RELOC_CRIS_32_TPREL, R_CRIS_32_TPREL },
{ BFD_RELOC_CRIS_16_TPREL, R_CRIS_16_TPREL },
- { BFD_RELOC_CRIS_DTPMOD, R_CRIS_DTPMOD }
+ { BFD_RELOC_CRIS_DTPMOD, R_CRIS_DTPMOD },
+ { BFD_RELOC_CRIS_32_IE, R_CRIS_32_IE }
};
static reloc_howto_type *
@@ -1832,6 +1834,17 @@ cris_elf_relocate_section (output_bfd, i
the GOT entry. */
break;
+ case R_CRIS_32_IE:
+ if (info->shared)
+ {
+ bfd_set_error (bfd_error_invalid_operation);
+
+ /* We've already informed in cris_elf_check_relocs that
+ this is an error. */
+ return FALSE;
+ }
+ /* Fall through. */
+
case R_CRIS_32_GOT_TPREL:
case R_CRIS_16_GOT_TPREL:
if (rel->r_addend != 0)
@@ -1884,7 +1897,8 @@ cris_elf_relocate_section (output_bfd, i
else
off &= ~3;
- relocation = sgot->output_offset + off;
+ relocation = sgot->output_offset + off
+ + (r_type == R_CRIS_32_IE ? sgot->output_section->vma : 0);
}
else
{
@@ -1944,10 +1958,12 @@ cris_elf_relocate_section (output_bfd, i
else
off &= ~3;
- relocation = sgot->output_offset + off;
+ relocation = sgot->output_offset + off
+ + (r_type == R_CRIS_32_IE ? sgot->output_section->vma : 0);
}
- /* The GOT-relative offset to the GOT entry is the relocation. */
+ /* The GOT-relative offset to the GOT entry is the relocation,
+ or for R_CRIS_32_GD, the actual address of the GOT entry. */
break;
case R_CRIS_16_TPREL:
@@ -2559,6 +2575,7 @@ cris_elf_gc_sweep_hook (bfd *abfd,
: &local_got_refcounts[LGOT_DTP_NDX (r_symndx)];
break;
+ case R_CRIS_32_IE:
case R_CRIS_16_GOT_TPREL:
case R_CRIS_32_GOT_TPREL:
specific_refcount = h != NULL
@@ -2572,6 +2589,7 @@ cris_elf_gc_sweep_hook (bfd *abfd,
switch (r_type)
{
+ case R_CRIS_32_IE:
case R_CRIS_32_GD:
case R_CRIS_16_GOT_TPREL:
case R_CRIS_32_GOT_TPREL:
@@ -3115,6 +3133,7 @@ cris_elf_check_relocs (abfd, info, sec,
elf_cris_hash_table (info)->dtpmod_refcount++;
/* Fall through. */
+ case R_CRIS_32_IE:
case R_CRIS_32_GD:
case R_CRIS_16_GOT_GD:
case R_CRIS_32_GOT_GD:
@@ -3188,6 +3207,7 @@ cris_elf_check_relocs (abfd, info, sec,
break;
/* Fall through. */
+ case R_CRIS_32_IE:
case R_CRIS_32_GD:
case R_CRIS_16_GOT_GD:
case R_CRIS_32_GOT_GD:
@@ -3234,6 +3254,7 @@ cris_elf_check_relocs (abfd, info, sec,
/* Warn and error for invalid input. */
switch (r_type)
{
+ case R_CRIS_32_IE:
case R_CRIS_32_TPREL:
case R_CRIS_16_TPREL:
case R_CRIS_32_GD:
@@ -3271,11 +3292,12 @@ cris_elf_check_relocs (abfd, info, sec,
elsewhere. */
break;
+ case R_CRIS_32_IE:
case R_CRIS_32_GOT_TPREL:
case R_CRIS_16_GOT_TPREL:
r_symndx_lgot = LGOT_TPREL_NDX (r_symndx);
- /* Those two relocs also require that a DSO is of type
+ /* Those relocs also require that a DSO is of type
Initial Exec. Like other targets, we don't reset this
flag even if the relocs are GC:ed away. */
if (info->shared)
@@ -3306,6 +3328,7 @@ cris_elf_check_relocs (abfd, info, sec,
GOT entry for it, so handle it like a GOT reloc. */
/* Fall through. */
+ case R_CRIS_32_IE:
case R_CRIS_32_GD:
case R_CRIS_16_GOT_GD:
case R_CRIS_32_GOT_GD:
@@ -3356,6 +3379,7 @@ cris_elf_check_relocs (abfd, info, sec,
elf_cris_hash_entry (h)->dtp_refcount++;
break;
+ case R_CRIS_32_IE:
case R_CRIS_32_GOT_TPREL:
case R_CRIS_16_GOT_TPREL:
if (elf_cris_hash_entry (h)->tprel_refcount == 0)
Index: reloc.c
===================================================================
RCS file: /cvs/src/src/bfd/reloc.c,v
retrieving revision 1.179
diff -p -u -r1.179 reloc.c
--- reloc.c 27 Nov 2008 12:26:49 -0000 1.179
+++ reloc.c 19 Dec 2008 22:40:44 -0000
@@ -4746,6 +4746,8 @@ ENUMX
BFD_RELOC_CRIS_16_TPREL
ENUMX
BFD_RELOC_CRIS_DTPMOD
+ENUMX
+ BFD_RELOC_CRIS_32_IE
ENUMDOC
Relocs used in TLS code for CRIS.
brgds, H-P