From: Fangrui Song <i@maskray.me>
To: Eric Botcazou <botcazou@adacore.com>
Cc: binutils@sourceware.org
Subject: Re: [PATCH] Orphan sections and NOLOAD output section
Date: Sat, 23 Apr 2022 14:30:16 -0700 [thread overview]
Message-ID: <20220423213016.zorvmjv5cspqbkry@gmail.com> (raw)
In-Reply-To: <2111887.irdbgypaU6@fomalhaut>
On 2022-04-21, Eric Botcazou via Binutils wrote:
>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
For other folks' convenience, the patch effect is changing
% ld.bfd orphan-13[abc].o -T orphan-13.ld && readelf -S a.out | grep foo
[ 1] .foo PROGBITS 0000000000000078 00000078
[ 2] .foo NOBITS 0000000000000098 00000098
to
% ~/Dev/binutils-gdb/out/release/ld/ld-new orphan-13[abc].o -T orphan-13.ld && readelf -S a.out | grep foo
[ 1] .foo NOBITS 0000000000000078 00000078
I think this is a good move.
I have checked `.foo (TYPE=SHT_NOBITS) : {}` which already uses just one output section.
I think in the future it makes sense to report a warning when NOBITS changes the section type from SHT_PROGBITS to SHT_NOBITS.
This kind of section type change is likely not what the user expects.
prev parent reply other threads:[~2022-04-23 21:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-21 15:31 Eric Botcazou
2022-04-21 15:53 ` Jan Beulich
2022-04-21 17:54 ` Eric Botcazou
2022-04-22 2:04 ` Alan Modra
2022-04-23 21:30 ` Fangrui Song [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220423213016.zorvmjv5cspqbkry@gmail.com \
--to=i@maskray.me \
--cc=binutils@sourceware.org \
--cc=botcazou@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).