public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Fangrui Song <i@maskray.me>
To: Alan Modra <amodra@gmail.com>
Cc: binutils <binutils@sourceware.org>
Subject: Re: [ld] section address : ALIGN(align) and the maximum of input section alignments
Date: Wed, 04 Mar 2020 00:03:00 -0000	[thread overview]
Message-ID: <BY5PR07MB7316EFFEE876DEA501ED5614CBE50@BY5PR07MB7316.namprd07.prod.outlook.com> (raw)
In-Reply-To: <20200303223901.GO5384@bubble.grove.modra.org>

On Tue, Mar 3, 2020 at 2:39 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Tue, Feb 25, 2020 at 10:30:03PM -0800, Fangrui Song wrote:
> > > Why doesn't `.bss . : ALIGN(16)` respect the maximum of input section alignments (32)?
> > >
> > > (I have verified that .bss being SHT_NOBITS is unrelated.)
> > >
> > > The rule of sh_addr computation appears to be:
> > >
> > > * ADDR is unset, ALIGN is unset => max_input_alignment
> > > * ADDR is unset, ALIGN is set => max(ALIGN, max_input_alignment)
> > > * ADDR is set, ALIGN is unset => max_input_alignment
> > > * ADDR is set, ALIGN is set => ALIGN
> >
> > When ADDR is set, ALIGN is used while max_input_alignment is ignored.
> >
> > ld/ldlang.c:5582
> >
> >                 if (os->addr_tree == NULL) {
> >                     ...
> >                   newdot = os->region->current;
> >                     // maximum of ALIGN and input section alignments
> >                   section_alignment = os->bfd_section->alignment_power;
> >                 }
> >               else
> >                   // ALIGN
> >                 section_alignment = exp_get_power (os->section_alignment, "section alignment");
> >
> > Alan, is the `else` branch supposed to use `section_alignment = os->bfd_section->alignment_power;` as well?
>
> No.  When you specify the address of an output section that is the
> address it should have.  Except that specifying both an address and
> alignment aligns the address given.  Specifying both is somewhat
> contradictory and it would probably have been better if we didn't
> support ALIGN here.

Thanks. For the example below, do you agree with the comments in a.x below?

% cat a.s
.globl _start; _start: ret
.section .data.rel.ro,"aw"; .balign 8; .byte 0
.data; .byte 0
.section .data2,"aw"; .balign 8; .byte 0
.section .data3,"aw"; .balign 32; .byte 0
.bss; .balign 32; .byte 0
% as a.s -o a.o

% cat a.x
SECTIONS {
  .text 0x10000 : { *(.text) }
  /* sh_addr is 0x10010. Specifying both address and ALIGN should be
disallowed. */
  .data.rel.ro . : ALIGN(16) { *(.data.rel.ro) }

  .data 0x20000 : { *(.data) }
  /* sh_addr is 0x20001. Should there be a warning that sh_addralign
is 8? Even --warn-section-align does not warn. */
  .data2 . : { *(.data2) }
  /* sh_addr is 0x20020. The input section alignment wins. */
  .data3 : ALIGN(16) { *(.data3) }
  /* sh_addr is 0x20030. Specifying both address and ALIGN should be
disallowed. */
  .bss . : ALIGN(16) { *(.bss) }
}

% ld.bfd -T a.x a.s -o a

If specifying both Output Section Address and ALIGN is disallowed,
there should be no "changing start of section" warning when
--warn-section-align is not specified. Is my understanding correct?

BTW, I filed a bug about duplicate "changing start of section"
warnings https://sourceware.org/bugzilla/show_bug.cgi?id=25570

  reply	other threads:[~2020-03-04  0:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-26  5:23 Fangrui Song
2020-02-26  6:31 ` Fangrui Song
2020-03-03  5:46   ` Fangrui Song
2020-03-03 22:39   ` Alan Modra
2020-03-04  0:03     ` Fangrui Song [this message]
     [not found]     ` <BY5PR07MB7316674DD98011D2AD812A63CBE40@BY5PR07MB7316.namprd07.prod.outlook.com>
2020-03-04  5:56       ` Alan Modra
2020-03-04  6:40         ` Fangrui Song
2020-03-04  8:04           ` Alan Modra
2020-03-05  6:41             ` Fangrui Song
2020-03-05 11:21               ` Alan Modra
2020-03-10 19:00                 ` 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=BY5PR07MB7316EFFEE876DEA501ED5614CBE50@BY5PR07MB7316.namprd07.prod.outlook.com \
    --to=i@maskray.me \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /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).