This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Basic support of linkerscript commands: DATA_SEGMENT_ALIGN, DATA_SEGMENT_END, CONSTANT
ClosedPublic

Authored by grimar on Apr 28 2016, 8:17 AM.

Details

Summary

It is called basic because:

  1. CONSTANT expression can refer to COMMONPAGESIZE and MAXPAGESIZE.

This sizes are usually different and used for possible optimization of
memory consumption.
More details are here: https://sourceware.org/ml/binutils/2002-02/msg00265.html
We currently do not support this optimization, so both CONSTANT(MAXPAGESIZE)
and CONSTANT(COMMONPAGESIZE) just return Target->PageSize value.

  1. DATA_SEGMENT_ALIGN and DATA_SEGMENT_END are used as a part of opt.

The latter one is just ignored now.
According to documentation DATA_SEGMENT_ALIGN has 2 possible
calculation, but since we do not support mentioned opt - it
is always calculated now as (ALIGN(MAXPAGESIZE) + (. & (MAXPAGESIZE - 1))).

In general this should work for now until we deside to support this opt.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 55420.Apr 28 2016, 8:17 AM
grimar retitled this revision from to [ELF] - Basic support of linkerscript commands: DATA_SEGMENT_ALIGN, DATA_SEGMENT_END, CONSTANT.
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
ruiu edited edge metadata.Apr 28 2016, 1:33 PM

This comment is not particularly to this patch, but it seems that you are working on the linker script and starting it from easy part. This patch is, for example, easy to implement. We can add small features such as this later after we complete the main part. There is also a chance that we would end up have to refactor the current code so we would have to rewrite everything -- so adding small features first is a bit risky. Therefore, can you focus on design instead of coding? We need a plan with which we are sure we'll be able to implement all the (well, probably not all, but all sane) linker script features.

davide added a subscriber: davide.Apr 28 2016, 7:19 PM

It would be particularly nice to have designs on how to handle features like 'SECTION', which not only seem to be larger but also used by more complicated linker scripts like, e.g., the ones used by kernels.

In D19663#415938, @ruiu wrote:

This comment is not particularly to this patch, but it seems that you are working on the linker script and starting it from easy part. This patch is, for example, easy to implement. We can add small features such as this later after we complete the main part. There is also a chance that we would end up have to refactor the current code so we would have to rewrite everything -- so adding small features first is a bit risky. Therefore, can you focus on design instead of coding? We need a plan with which we are sure we'll be able to implement all the (well, probably not all, but all sane) linker script features.

Ok.
About this little patch: if was fast to do and I assumed that expression evaluation and linker script itself are more or less independent components. And even if we will rewrite everything, such patches introduces new testcases, that are potentially usefull.

grimar updated this revision to Diff 64912.Jul 21 2016, 9:34 AM
grimar edited edge metadata.
grimar added a subscriber: evgeny777.
  • Rebased.

So I guess after all that LS commits we now are ready to support this.
It opens a way for linker script constants as well.

evgeny777 added inline comments.Jul 21 2016, 9:41 AM
ELF/LinkerScript.cpp
158 ↗(On Diff #64912)

Looks like you can write

expect("(.)")
grimar added inline comments.Jul 21 2016, 9:50 AM
ELF/LinkerScript.cpp
158 ↗(On Diff #64912)

This is 3 different tokens, this will not work.

evgeny777 added inline comments.Jul 21 2016, 9:52 AM
ELF/LinkerScript.cpp
158 ↗(On Diff #64912)

Yeah, you're right, sorry.

ruiu accepted this revision.Jul 21 2016, 12:44 PM
ruiu edited edge metadata.

LGTM

ELF/LinkerScript.cpp
104 ↗(On Diff #64912)

static?

105–109 ↗(On Diff #64912)

Are you describing the same thing in two places in the same commit? Maybe you want to leave one of them and remove the other?

137 ↗(On Diff #64912)

Can you consistently use V as a return value in this function just like other if clauses do?

This revision is now accepted and ready to land.Jul 21 2016, 12:44 PM
This revision was automatically updated to reflect the committed changes.
grimar added inline comments.Jul 21 2016, 12:55 PM
ELF/LinkerScript.cpp
104 ↗(On Diff #64912)

Done.

105–109 ↗(On Diff #64912)

Removed.

137 ↗(On Diff #64912)

Sure, sorry.