public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: KONRAD Frederic <frederic.konrad@adacore.com>
Cc: binutils@sourceware.org
Subject: Re: ld: output section alignment and empty section.
Date: Tue, 10 Mar 2020 17:12:25 +1030	[thread overview]
Message-ID: <20200310064225.GT5384@bubble.grove.modra.org> (raw)
In-Reply-To: <f8f1491e-5693-0db5-5397-e87fe0a6f44e@adacore.com>

On Thu, Mar 05, 2020 at 02:55:44PM +0100, KONRAD Frederic wrote:
> Hi,
> 
> I just figured out that the following linker script hunk:
> 
>   . = ALIGN(0x4);
>   .rodata :
>   {
>     . = ALIGN(0x4);
>   }
> 
> is creating an empty .rodata output section while I was expecting it not to be
> emited.
> 
> This is because we flag ". = ALIGN(xxx)" as SEC_KEEP in exp_fold_tree_1.
> 
> Dropping that for ". = ALIGN(constant)" seems to fix the behavior:

Yes it would, but you could also write the align inside .rodata using

  . = ALIGN(. != 0 ? 4 : 1);

That is one of the few forms of assigning to dot that ld recognises as
*not* resulting in "keep this section".  This is documented under node
"Output Section Discarding" in ld.info.

I don't think there is a good reason to change this behaviour as there
may even be scripts that rely on a simpler ALIGN to keep the section.

> Is that because strip_excluded_output_sections happens before the relaxation?
> Could that be a problem in the case of a constant alignment?

Yes and yes.  It is possible to create a script that assigns an
address (before the colon in an output section statement) or alignment
(after the colon) to a section less than the constant alignment in
some ". = ALIGN();" statement in that section, and the addresses of
prior sections conspire to make the alignment do nothing before
relaxation but to add padding when prior sections change.  The patches
that were reverted with e0a3af227e ran into something like that when I
tried to make the single operand ALIGN behave like the two operand
form.

> What do you think?

Fix your script.  :-)

-- 
Alan Modra
Australia Development Lab, IBM

  reply	other threads:[~2020-03-10  6:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-05 13:55 KONRAD Frederic
2020-03-10  6:42 ` Alan Modra [this message]
2020-03-11 14:14   ` KONRAD Frederic
2020-03-12  2:55   ` Fangrui Song

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=20200310064225.GT5384@bubble.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=frederic.konrad@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).