public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* mips64-elf .rel.dyn sections
@ 2012-11-30 23:41 Jim Wilson (jimwilso)
  2012-12-03  4:22 ` Alan Modra
  0 siblings, 1 reply; 7+ messages in thread
From: Jim Wilson (jimwilso) @ 2012-11-30 23:41 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 2650 bytes --]

The mips64-elf toolchain is creating .rel.dyn sections, even though it does not support dynamic linking, and does not create dynamic sections.  I attached a testcase.

Both old and new binutils call mips_elf_rel_dyn_section to create the .rel.dyn section when a R_MIPS_32 reloc is seen, in case it is needed.  In old binutils, this gets removed as a zero-size section in _bfd_mips_elf_size_dynamic_sections.  In new binutils, we call allocate_dynrelocs first, which creates dummy relocs in the .rel.dyn section, and now it can't be removed as it is no longer a zero size section.

The bug seems to be in allocate_dynrelocs in elfxx-mips.c, which does
  if (! info->relocatable
      && hmips->possibly_dynamic_relocs != 0
      && (h->root.type == bfd_link_hash_defweak
          || !h->def_regular
          || info->shared))

However, we are looking at a reference here, not a definition, so none of the h->def_* bits are set, though we do have h->ref_* bits set.  

Breakpoint 2, allocate_dynrelocs (h=0x817c8ec, inf=0x81692e0) at ../../new-combined/bfd/elfxx-mips.c:8551
(gdb) print *h
$1 = {root = {root = {next = 0x817c574, string = 0x8198b86 "i", hash = 13803625\
}, type = bfd_link_hash_defined, non_ir_ref = 0, u = {undef = {next = 0x0, abfd\
 = 0x8193a54}, def = {next = 0x0, section = 0x8193a54, value = 0}, i = {next = \
0x0, link = 0x8193a54, warning = 0x0}, c = {next = 0x0, p = 0x8193a54, size = 0\
}}}, indx = -1, dynindx = -1, got = {refcount = -1, offset = 184467440737095516\
15, glist = 0xffffffff, plist = 0xffffffff}, plt = {refcount = -1, offset = 184\
46744073709551615, glist = 0xffffffff, plist = 0xffffffff}, size = 4, type = 1,\
 other = 0, target_internal = 0, ref_regular = 1, def_regular = 0, ref_dynamic \
= 0, def_dynamic = 0, ref_regular_nonweak = 1, dynamic_adjusted = 0, needs_copy\
 = 0, needs_plt = 0, non_elf = 0, hidden = 0, forced_local = 0, dynamic = 0, ma\
rk = 0, non_got_ref = 0, dynamic_def = 0, dynamic_weak = 0, pointer_equality_ne\
eded = 0, unique_global = 0, dynstr_index = 0, u = {weakdef = 0x0, elf_hash_val\
ue = 0}, verinfo = {verdef = 0x0, vertree = 0x0}, vtable = 0x0}
(gdb)

This suggests that maybe the line
    || !h->def_regular
Should instead be
    || (!h->def_regular && !h->ref_regular)
I am not sure if the h->ref_regular_nonweak bit needs to be tested also or instead of ref_regular.

I don't have any mips-linux system using PLTs and copy-relocs yet, so I don't have an easy way to test that.  I also don't have a binutils assignment yet, so I can't formally contribute a patch for this.  I can open a bugzilla bug report if necessary.

Jim


[-- Attachment #2: mips64-elf-rel-dyn.txt --]
[-- Type: text/plain, Size: 3274 bytes --]

jimwilso-lnx:2127$ cat tmp.c
int i;
static int *ptr = &i;
int main (void) { return 0; }
jimwilso-lnx:2128$ mips64-elf-gcc tmp.c
/home/jimwilso/FOSS/COMBINED-TREE/install/lib/gcc/mips64-elf/4.8.0/../../../../mips64-elf/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000400038
jimwilso-lnx:2129$ mips64-elf-readelf -S a.out
There are 21 section headers, starting at offset 0x1418:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .reginfo          MIPS_REGINFO    00400000 0012dc 000018 01      0   0  4
  [ 2] .rel.dyn          REL             00400000 001000 000010 08   A  0   0  4
  [ 3] .init             PROGBITS        00400010 001010 000024 00  AX  0   0  1
  [ 4] .text             PROGBITS        00400038 001038 000268 00  AX  0   0  8
  [ 5] .fini             PROGBITS        004002a0 0012a0 00001c 00  AX  0   0  1
  [ 6] .eh_frame         PROGBITS        004002bc 0012bc 000004 00   A  0   0  4
  [ 7] .ctors            PROGBITS        004012c0 0012c0 000008 00  WA  0   0  4
  [ 8] .dtors            PROGBITS        004012c8 0012c8 000008 00  WA  0   0  4
  [ 9] .jcr              PROGBITS        004012d0 0012d0 000004 00  WA  0   0  4
  [10] .sdata            PROGBITS        004012d4 0012d4 000008 00 WAp  0   0  4
  [11] .sbss             NOBITS          004012dc 0012dc 000004 00 WAp  0   0  4
  [12] .bss              NOBITS          004012e0 0012dc 000020 00  WA  0   0  8
  [13] .comment          PROGBITS        00000000 0012f4 000041 01  MS  0   0  1
  [14] .pdr              PROGBITS        00000000 001338 000020 00      0   0  4
  [15] .gnu.attributes   LOOS+ffffff5    00000000 001358 000010 00      0   0  1
  [16] .mdebug.abiO64    PROGBITS        00000000 001368 000000 00      0   0  1
  [17] .gcc_compiled_lon PROGBITS        00000000 001368 000000 00      0   0  1
  [18] .shstrtab         STRTAB          00000000 001368 0000b0 00      0   0  1
  [19] .symtab           SYMTAB          00000000 001760 0003d0 10     20  42  4
  [20] .strtab           STRTAB          00000000 001b30 000231 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)
jimwilso-lnx:2130$ mips64-elf-readelf -r a.out

Relocation section '.rel.dyn' at offset 0x1000 contains 2 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  00000000 R_MIPS_NONE      
00000000  00000000 R_MIPS_NONE      
jimwilso-lnx:2131$ mips64-elf-gcc -v
Using built-in specs.
COLLECT_GCC=mips64-elf-gcc
COLLECT_LTO_WRAPPER=/home/jimwilso/FOSS/COMBINED-TREE/install/libexec/gcc/mips64-elf/4.8.0/lto-wrapper
Target: mips64-elf
Configured with: ../new-combined/configure --target=mips64-elf --prefix=/home/jimwilso/FOSS/COMBINED-TREE/install --with-newlib --enable-languages=c,c++
Thread model: single
gcc version 4.8.0 20121128 (experimental) [trunk revision 193911] (GCC) 
jimwilso-lnx:2132$ mips64-elf-ld -v
GNU ld (GNU Binutils) 2.23.51.20121129
jimwilso-lnx:2133$ 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: mips64-elf .rel.dyn sections
  2012-11-30 23:41 mips64-elf .rel.dyn sections Jim Wilson (jimwilso)
@ 2012-12-03  4:22 ` Alan Modra
  2012-12-04  0:40   ` Jim Wilson (jimwilso)
  2012-12-04 19:32   ` Jim Wilson (jimwilso)
  0 siblings, 2 replies; 7+ messages in thread
From: Alan Modra @ 2012-12-03  4:22 UTC (permalink / raw)
  To: Jim Wilson (jimwilso); +Cc: binutils

On Fri, Nov 30, 2012 at 11:41:09PM +0000, Jim Wilson (jimwilso) wrote:
> The mips64-elf toolchain is creating .rel.dyn sections, even though it does not support dynamic linking, and does not create dynamic sections.  I attached a testcase.

A C testcase is generally only of use to people who have the relevant
target C compilers, but in this case I'll make a guess at the
problem..

> This suggests that maybe the line
>     || !h->def_regular
> Should instead be
>     || (!h->def_regular && !h->ref_regular)
> I am not sure if the h->ref_regular_nonweak bit needs to be tested also or instead of ref_regular.

This is very unlikely to be the correct solution.  See the comment on
ref_regular.  Your testcase has a common variable, so I'll guess the
line should be

    || (!h->def_regular && !ELF_COMMON_DEF_P (h))

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: mips64-elf .rel.dyn sections
  2012-12-03  4:22 ` Alan Modra
@ 2012-12-04  0:40   ` Jim Wilson (jimwilso)
  2012-12-04 19:32   ` Jim Wilson (jimwilso)
  1 sibling, 0 replies; 7+ messages in thread
From: Jim Wilson (jimwilso) @ 2012-12-04  0:40 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

[-- Attachment #1: Type: text/plain, Size: 1021 bytes --]

> A C testcase is generally only of use to people who have the relevant
> target C compilers, but in this case I'll make a guess at the
> problem..

OK.  I worked up a small assembly testcase extracted from my C example that shows the same problem.  Attached.

> This is very unlikely to be the correct solution.  See the comment on
> ref_regular.  Your testcase has a common variable, so I'll guess the
> line should be
>     || (!h->def_regular && !ELF_COMMON_DEF_P (h))

It didn't occur to me to look at the common variable.  Now that you mention it, I see that the .rel.dyn section disappears if I initialize the variable.  Grepping for uses of ELF_COMMON_DEF_P, I see a use in _bfd_elf_dynamic_symbol_p in elflink.c which looks like the problematic code in elfxx-mips.c allocate_dynrelocs.  So, yes, this does look like the right solution.  I tried this on my simple testcase and it works.

I can try this on a full router image build here to see what happens.  This will probably take a day.

Jim


[-- Attachment #2: mips64-elf-rel-dyn-2.txt --]
[-- Type: text/plain, Size: 1509 bytes --]

jimwilso-lnx:2054$ more tmp2.s
        .comm   i,4,4
        .section        .sdata,"aw",@progbits
        .align  2
ptr:
        .word   i
        .text
        .align  2
        .globl  _start
_start:
        nop
jimwilso-lnx:2054$ mips64-elf-as tmp2.s -o tmp2.o
jimwilso-lnx:2055$ mips64-elf-ld tmp2.o
jimwilso-lnx:2056$ mips64-elf-readelf -S a.out
There are 9 section headers, starting at offset 0x1070:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .reginfo          MIPS_REGINFO    00400000 001018 000018 01      0   0  4
  [ 2] .rel.dyn          REL             00400000 001000 000010 08   A  0   0  4
  [ 3] .text             PROGBITS        00400010 001010 000004 00  AX  0   0  4
  [ 4] .sdata            PROGBITS        00401014 001014 000004 00 WAp  0   0  4
  [ 5] .sbss             NOBITS          00401018 001018 000004 00 WAp  0   0  4
  [ 6] .shstrtab         STRTAB          00000000 001030 000040 00      0   0  1
  [ 7] .symtab           SYMTAB          00000000 0011d8 000120 10      8  10  4
  [ 8] .strtab           STRTAB          00000000 0012f8 000045 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)
jimwilso-lnx:2057$

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: mips64-elf .rel.dyn sections
  2012-12-03  4:22 ` Alan Modra
  2012-12-04  0:40   ` Jim Wilson (jimwilso)
@ 2012-12-04 19:32   ` Jim Wilson (jimwilso)
  2012-12-06  0:12     ` Alan Modra
  1 sibling, 1 reply; 7+ messages in thread
From: Jim Wilson (jimwilso) @ 2012-12-04 19:32 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

> I can try this on a full router image build here to see what happens.  This will
> probably take a day.

I rebuilt a mips router image.  The original unpatched binutils generated a ~13.5KB .rel.dyn section.  The new one has no .rel.dyn section as I expect, and otherwise looks OK.

Jim

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: mips64-elf .rel.dyn sections
  2012-12-04 19:32   ` Jim Wilson (jimwilso)
@ 2012-12-06  0:12     ` Alan Modra
  2012-12-06  1:11       ` Jim Wilson (jimwilso)
  2012-12-07  5:43       ` Alan Modra
  0 siblings, 2 replies; 7+ messages in thread
From: Alan Modra @ 2012-12-06  0:12 UTC (permalink / raw)
  To: Jim Wilson (jimwilso); +Cc: binutils

On Tue, Dec 04, 2012 at 07:32:11PM +0000, Jim Wilson (jimwilso) wrote:
> > I can try this on a full router image build here to see what happens.  This will
> > probably take a day.
> 
> I rebuilt a mips router image.  The original unpatched binutils generated a ~13.5KB .rel.dyn section.  The new one has no .rel.dyn section as I expect, and otherwise looks OK.

Committed.

bfd/
	* elfxx-mips.c (allocate_dynrelocs): Correct test for symbol
	defined in a regular file to include common symbols.
ld/testsuite/
	* ld-elf/comm-data4.d, ld-elf/comm-data4.s: New test.
	* ld-elf/comm-data5.d, ld-elf/comm-data5.s: New test.
	* ld-elf/comm-data.exp: Run them.

Index: bfd/elfxx-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-mips.c,v
retrieving revision 1.319
diff -u -p -r1.319 elfxx-mips.c
--- bfd/elfxx-mips.c	3 Dec 2012 16:37:51 -0000	1.319
+++ bfd/elfxx-mips.c	5 Dec 2012 07:20:47 -0000
@@ -8568,7 +8568,7 @@ allocate_dynrelocs (struct elf_link_hash
   if (! info->relocatable
       && hmips->possibly_dynamic_relocs != 0
       && (h->root.type == bfd_link_hash_defweak
-	  || !h->def_regular
+	  || (!h->def_regular && !ELF_COMMON_DEF_P (h))
 	  || info->shared))
     {
       bfd_boolean do_copy = TRUE;
Index: ld/testsuite/ld-elf/comm-data.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elf/comm-data.exp,v
retrieving revision 1.5
diff -u -p -r1.5 comm-data.exp
--- ld/testsuite/ld-elf/comm-data.exp	21 Nov 2012 19:31:24 -0000	1.5
+++ ld/testsuite/ld-elf/comm-data.exp	5 Dec 2012 07:20:50 -0000
@@ -98,3 +98,6 @@ run_ld_link_tests [list \
 	"comm-data3b" \
     ] \
 ]
+
+run_dump_test comm-data4
+run_dump_test comm-data5
Index: ld/testsuite/ld-elf/comm-data4.d
===================================================================
RCS file: ld/testsuite/ld-elf/comm-data4.d
diff -N ld/testsuite/ld-elf/comm-data4.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/comm-data4.d	5 Dec 2012 23:59:53 -0000
@@ -0,0 +1,6 @@
+#source: comm-data4.s
+#ld: 
+#readelf: -r
+#notarget: hppa64*-*-hpux*
+
+There are no relocations in this file.
Index: ld/testsuite/ld-elf/comm-data4.s
===================================================================
RCS file: ld/testsuite/ld-elf/comm-data4.s
diff -N ld/testsuite/ld-elf/comm-data4.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/comm-data4.s	5 Dec 2012 23:59:53 -0000
@@ -0,0 +1,15 @@
+ .comm i,4,4
+
+ .data
+ .dc.a i
+
+ .globl main
+ .globl start
+ .globl _start
+ .globl __start
+ .text
+main:
+start:
+_start:
+__start:
+ .dc.a 0
Index: ld/testsuite/ld-elf/comm-data5.d
===================================================================
RCS file: ld/testsuite/ld-elf/comm-data5.d
diff -N ld/testsuite/ld-elf/comm-data5.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/comm-data5.d	5 Dec 2012 23:59:53 -0000
@@ -0,0 +1,6 @@
+#source: comm-data5.s
+#ld: 
+#readelf: -r
+#notarget: hppa64*-*-hpux*
+
+There are no relocations in this file.
Index: ld/testsuite/ld-elf/comm-data5.s
===================================================================
RCS file: ld/testsuite/ld-elf/comm-data5.s
diff -N ld/testsuite/ld-elf/comm-data5.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/comm-data5.s	5 Dec 2012 23:59:53 -0000
@@ -0,0 +1,15 @@
+ .comm i,4,4
+
+ .section .rodata,"a",%progbits
+ .dc.a i
+
+ .globl main
+ .globl start
+ .globl _start
+ .globl __start
+ .text
+main:
+start:
+_start:
+__start:
+ .dc.a 0

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: mips64-elf .rel.dyn sections
  2012-12-06  0:12     ` Alan Modra
@ 2012-12-06  1:11       ` Jim Wilson (jimwilso)
  2012-12-07  5:43       ` Alan Modra
  1 sibling, 0 replies; 7+ messages in thread
From: Jim Wilson (jimwilso) @ 2012-12-06  1:11 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

Thanks.

Jim

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: mips64-elf .rel.dyn sections
  2012-12-06  0:12     ` Alan Modra
  2012-12-06  1:11       ` Jim Wilson (jimwilso)
@ 2012-12-07  5:43       ` Alan Modra
  1 sibling, 0 replies; 7+ messages in thread
From: Alan Modra @ 2012-12-07  5:43 UTC (permalink / raw)
  To: binutils

ld-elf/elf.exp runs all dump tests, so my addition to comm-data.exp made
the new tests run twice.

	* ld-elf/comm-data.exp: Revert last change.
	* ld-elf/comm-data5.d: xfail frv-linux.

Index: ld/testsuite/ld-elf/comm-data.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elf/comm-data.exp,v
retrieving revision 1.6
diff -u -p -r1.6 comm-data.exp
--- ld/testsuite/ld-elf/comm-data.exp	6 Dec 2012 00:10:41 -0000	1.6
+++ ld/testsuite/ld-elf/comm-data.exp	7 Dec 2012 05:40:09 -0000
@@ -98,6 +98,3 @@ run_ld_link_tests [list \
 	"comm-data3b" \
     ] \
 ]
-
-run_dump_test comm-data4
-run_dump_test comm-data5
Index: ld/testsuite/ld-elf/comm-data5.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elf/comm-data5.d,v
retrieving revision 1.1
diff -u -p -r1.1 comm-data5.d
--- ld/testsuite/ld-elf/comm-data5.d	6 Dec 2012 00:10:41 -0000	1.1
+++ ld/testsuite/ld-elf/comm-data5.d	7 Dec 2012 05:40:09 -0000
@@ -2,5 +2,6 @@
 #ld: 
 #readelf: -r
 #notarget: hppa64*-*-hpux*
+#xfail: frv-*-*linux*
 
 There are no relocations in this file.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-12-07  5:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-30 23:41 mips64-elf .rel.dyn sections Jim Wilson (jimwilso)
2012-12-03  4:22 ` Alan Modra
2012-12-04  0:40   ` Jim Wilson (jimwilso)
2012-12-04 19:32   ` Jim Wilson (jimwilso)
2012-12-06  0:12     ` Alan Modra
2012-12-06  1:11       ` Jim Wilson (jimwilso)
2012-12-07  5:43       ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).