[PATCH][gold] Use attributes of existing sections when placing orphan sections.

Igor Kudrin ikudrin@accesssoftek.com
Mon Oct 24 13:25:00 GMT 2016


Hi Ian,

The main reason I made this patch is that, in our case, gold places
orphan sections differently than GNU ld does. I tried not to affect
the current behaviour in other cases. At least, all the existing tests pass.

Here is the comparison of results of GNU ld, gold and the patched gold:
$ cat > test.s << EOF
.section CODE, "ax"
nop
.section DATA2, "aw"
.word 0
.section CODE2, "ax"
nop
.section DATA, "aw"
.word 0
EOF
$ cat > test.t << EOF
SECTIONS
{
    DATA : { *(DATA) }
    CODE : { *(CODE) }
}
EOF
$ as test.s -o test.o
$ ./ld test.o -T test.t -o test.ld.out
$ ./gold test.o -T test.t -o test.gold.out
$ ./gold-patched test.o -T test.t -o test.gold-patched.out
$ readelf -SW test.ld.out
...
  [ 1] DATA              PROGBITS        0000000000000000 200000 000002 00  WA  0   0  1
  [ 2] DATA2             PROGBITS        0000000000000002 200002 000002 00  WA  0   0  1
  [ 3] CODE              PROGBITS        0000000000000004 200004 000001 00  AX  0   0  1
  [ 4] CODE2             PROGBITS        0000000000000005 200005 000001 00  AX  0   0  1
...
$ readelf -SW test.gold.out
...
  [ 1] DATA              PROGBITS        0000000000000000 001000 000002 00  WA  0   0  1
  [ 2] .text             PROGBITS        0000000000000002 001002 000000 00  AX  0   0  1
  [ 3] CODE2             PROGBITS        0000000000000002 001002 000001 00  AX  0   0  1
  [ 4] .data             PROGBITS        0000000000000003 001003 000000 00  WA  0   0  1
  [ 5] DATA2             PROGBITS        0000000000000003 001003 000002 00  WA  0   0  1
  [ 6] .bss              NOBITS          0000000000000005 001005 000000 00  WA  0   0  1
  [ 7] CODE              PROGBITS        0000000000000024 001024 000001 00  AX  0   0  1
...
$ readelf -SW test.gold-patched.out
...
  [ 1] DATA              PROGBITS        0000000000000000 001000 000002 00  WA  0   0  1
  [ 2] .data             PROGBITS        0000000000000002 001002 000000 00  WA  0   0  1
  [ 3] DATA2             PROGBITS        0000000000000002 001002 000002 00  WA  0   0  1
  [ 4] .bss              NOBITS          0000000000000004 001004 000000 00  WA  0   0  1
  [ 5] CODE              PROGBITS        0000000000000020 001020 000001 00  AX  0   0  1
  [ 6] .text             PROGBITS        0000000000000021 001021 000000 00  AX  0   0  1
  [ 7] CODE2             PROGBITS        0000000000000021 001021 000001 00  AX  0   0  1
...

Best regards,
Igor

________________________________________
From: Ian Lance Taylor <iant@google.com>
Sent: Friday, October 21, 2016 7:12 PM
To: Igor Kudrin
Cc: binutils@sourceware.org; Cary Coutant
Subject: Re: [PATCH][gold] Use attributes of existing sections when placing orphan sections.

On Fri, Oct 21, 2016 at 4:24 AM, Igor Kudrin <ikudrin@accesssoftek.com> wrote:
>
> The current version of gold uses names of described output sections
> to find places where to put orphan sections. If the sections in the
> linker script have different names, gold fails to find the right place
> for orphans. This patch addresses the issue by analyzing attributes
> of existing section if they have unfamiliar names.

One of the goals of gold's orphan section placement is to be
approximately the same as GNU ld's orphan section placement.  How does
GNU ld behave in the scenarios you are looking at?

Ian



More information about the Binutils mailing list