This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Linkerscript: implemented ALIGN modificatior of output sections.
ClosedPublic

Authored by grimar on Jul 22 2016, 5:51 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 65062.Jul 22 2016, 5:51 AM
grimar retitled this revision from to [ELF] - Linkerscript: implemented ALIGN modificatior of output sections..
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar, evgeny777.
emaste added a subscriber: emaste.Jul 22 2016, 6:20 AM
davide added a subscriber: davide.Jul 22 2016, 11:51 AM

FWIW, this is very important because both FreeBSD and Linux rely on it (kernel).

davide accepted this revision.Jul 22 2016, 11:54 AM
davide added a reviewer: davide.

I think this one is OK. Please wait for Rui for final sign-off.

This revision is now accepted and ready to land.Jul 22 2016, 11:54 AM
ruiu edited edge metadata.Jul 23 2016, 4:29 AM

ALIGN shouldn't be implemented as a special feature that is allowed only after ":" in SECTIONS subcommands. It is a generic function as described in https://sourceware.org/binutils/docs/ld/Builtin-Functions.html#Builtin-Functions.

If you support an expression after ":" in the context and the ALIGN built-in function, this feature is going to naturally be supported.

In D22674#493846, @ruiu wrote:

ALIGN shouldn't be implemented as a special feature that is allowed only after ":" in SECTIONS subcommands. It is a generic function as described in https://sourceware.org/binutils/docs/ld/Builtin-Functions.html#Builtin-Functions.

If you support an expression after ":" in the context and the ALIGN built-in function, this feature is going to naturally be supported.

I think we have different typese of ALIGN here. One is a output section description modificator.
3.6.1 Output Section Description explicitly says that ALIGN is a part of description.
(https://sourceware.org/binutils/docs/ld/Output-Section-Description.html#Output-Section-Description).
That is what this patch implements.

The other ALIGN is a generic function, as you mentioned.

I think location counter value in output secrion description is "global", but
in expressions inside declaration is "local" (relative to OutSec start address).
So ALIGN in declarations allows to use global location counter and layout the section
properly.

Because of above I think patch implements it in a correct way.

grimar added a comment.EditedJul 25 2016, 1:00 AM

So, the full description of an output section looks like this:
(https://sourceware.org/binutils/docs/ld/Output-Section-Description.html#Output-Section-Description)

section [address] [(type)] :
  [AT(lma)]
  [ALIGN(section_align) | ALIGN_WITH_INPUT]
  [SUBALIGN(subsection_align)]
  [constraint]
  {
    output-section-command
    output-section-command
    ...
  } [>region] [AT>lma_region] [:phdr :phdr ...] [=fillexp] [,]

There are just a few things that can be between ":" and "{". One of them is ALIGN.
ALIGN also can be meet as regular command after "{", but it will have different meaning,
it will work with localcounter that is not absolete address, but offset from start of the section.
This way I think it is unnatural to treat everything between ":" and "{" as possible expression,
as the only possible expression is ALIGN. But that is not expression, but output section modificator.
So I believe logic of the patch is fine, I just plan to rebase it after recent changes soon.

grimar updated this revision to Diff 65312.Jul 25 2016, 1:26 AM
grimar edited edge metadata.
  • Rebased.
ruiu added a comment.Jul 25 2016, 2:15 PM

Instead of adding new code to the function, can you create a new function that processes only ALIGN option?

ELF/LinkerScript.cpp
664–665 ↗(On Diff #65312)
if (skip("ALIGN"))
  readAlign(Cmd);
grimar updated this revision to Diff 65503.Jul 26 2016, 5:58 AM
  • Rebased, addressed review comments.
In D22674#495326, @ruiu wrote:

Instead of adding new code to the function, can you create a new function that processes only ALIGN option?

I moved the handling to a assignAddresses() method, IMO more appropriate for that, and so handling is just 2 lines now.
I am not sure if moving to new function worth that now, when it is just 2 lines ? I guess no.
And the reason I moved it to assignAddresses() is that I found that location counter can be used in
ALIGN, like:
.aaa : ALIGN(4096 + . * 100) { ... }
Though I never saw this in real linkerscripts, it still looks as a more correct place, since we know the value
of location counter only in that place. What do you think ?

ELF/LinkerScript.cpp
664–665 ↗(On Diff #65312)

Done.

ruiu accepted this revision.Jul 26 2016, 10:48 AM
ruiu edited edge metadata.

LGTM

This revision was automatically updated to reflect the committed changes.

Does llvm ld support the ALIGN_WITH_INPUT option?

Herald added a project: Restricted Project. · View Herald Transcript

Does llvm ld support the ALIGN_WITH_INPUT option?

@Octav It doesn't. You can verify that the token "ALIGN_WITH_INPUT" is not mentioned in lld/ELF. What would be helpful is to give your minimized linker script which uses ALIGN_WITH_INPUT.