[PATCH] Orphan sections and NOLOAD output section

Eric Botcazou botcazou@adacore.com
Thu Apr 21 15:31:58 GMT 2022


Hi,

we recently got a report about a counter-intuitive behavior of the GNU linker
for orphan sections matched by a NOLOAD output section, which turned out to be
an exact duplicate of:
  https://stackoverflow.com/questions/48764136/gcc-noload-directive-cause-wrong-memory-mapping

What happens is that the effect of the command:

  .foo (NOLOAD) : {}

is not equivalent to that of:

  .foo (NOLOAD) : { *(.foo) }

when there is more than 1 object file containing a .foo section: the former
will output two .foo sections, the first with PROGBITS and the second with
NOBITS, where the latter will output only one with NOBITS.

I think that the commands are essentially equivalent so the linker ought to yield
the same outcome, namely the single output section with NOBITS.

Tested on x86-64/Linux, OK for the mainline?


2022-04-21  Eric Botcazou  <ebotcazou@adacore.com>

ld/
	* ldelf.c (ldelf_place_orphan): Match only by name for a NOLOAD
	output section present in the script.
	* testsuite/ld-elf/orphan-13.d: New file.
	* testsuite/ld-elf/orphan-13.ld: Likewise.
	* testsuite/ld-elf/orphan-13a.s: Likewise.
	* testsuite/ld-elf/orphan-13b.s: Likewise.
	* testsuite/ld-elf/orphan-13c.s: Likewise.

-- 
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p.diff
Type: text/x-patch
Size: 2787 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20220421/ffe75c7f/attachment.bin>


More information about the Binutils mailing list