This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Linkerscript: implement SIZEOF_HEADERS.
ClosedPublic

Authored by grimar on Aug 4 2016, 8:29 AM.

Details

Summary

SIZEOF_HEADERS - Return the size in bytes of the output file’s headers.

It is is a feature used in FreeBsd script, for example.
There is a discussion on PR28688 page about it.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 66809.Aug 4 2016, 8:29 AM
grimar retitled this revision from to [ELF, Drawt] - Linkerscript: implement SIZEOF_HEADERS .
grimar updated this object.
grimar added reviewers: ruiu, rafael, davide.
grimar added subscribers: llvm-commits, grimar, evgeny777.
grimar retitled this revision from [ELF, Drawt] - Linkerscript: implement SIZEOF_HEADERS to [ELF, Draft] - Linkerscript: implement SIZEOF_HEADERS .Aug 4 2016, 8:29 AM
grimar updated this revision to Diff 66917.Aug 5 2016, 2:16 AM
grimar retitled this revision from [ELF, Draft] - Linkerscript: implement SIZEOF_HEADERS to [ELF] - Linkerscript: implement SIZEOF_HEADERS..
grimar updated this object.
  • Added testcase.
ruiu added inline comments.Aug 5 2016, 2:43 PM
ELF/LinkerScript.cpp
241 ↗(On Diff #66917)

I do see why you are doing this, but this is pretty obscure. Do we really have to do this?

grimar added inline comments.Aug 8 2016, 3:20 AM
ELF/LinkerScript.cpp
241 ↗(On Diff #66917)

When SIZE_OF_HEADERS is not used it is convenient behavior to have location counted be shifted automatically. Otherwise users will have to leave space for headers manually which probably not the best experience we can offer.

Or do you mean we should always shift dot here on size of headers ? That means that if script contains SIZE_OF_HEADES there will be some waste of VA space. That does not allow script to control everything also, what I guess can be expected for those who want to set up everything manually.

ruiu added inline comments.Aug 8 2016, 3:05 PM
ELF/LinkerScript.cpp
241 ↗(On Diff #66917)

I think we don't have to do this. If the first linker script line is

. = SIZEOF_HEADERS;

and if . is the same as SIZEOF_HEADERS (it is), the first line is a nop. So it should just work.

grimar updated this revision to Diff 67297.Aug 9 2016, 1:35 AM
  • Addressed review comments.
grimar added inline comments.Aug 9 2016, 1:38 AM
ELF/LinkerScript.cpp
241 ↗(On Diff #67297)

I hope there will not be scripts with first linke like:

. += SIZEOF_HEADERS;
ruiu accepted this revision.Aug 9 2016, 10:49 AM
ruiu edited edge metadata.

LGTM

ELF/LinkerScript.cpp
241 ↗(On Diff #67297)

Let's see how it works! If it works, it's definitely better.

923 ↗(On Diff #67297)

This technique is getting ugly as we have more and more functions to interact with the template class. At some point we probably should use a different technique. But for now it is fine (and probably still preferable.)

This revision is now accepted and ready to land.Aug 9 2016, 10:49 AM
grimar added inline comments.Aug 10 2016, 12:23 AM
ELF/LinkerScript.cpp
923 ↗(On Diff #67297)

May be something like I used in first iteration here:
https://reviews.llvm.org/D22759?id=65352 ?

grimar updated this object.Aug 10 2016, 1:00 AM
grimar edited edge metadata.
This revision was automatically updated to reflect the committed changes.