This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Check that section alignment is a power of 2.
ClosedPublic

Authored by grimar on Oct 6 2016, 7:21 AM.

Details

Summary

I found that this check still may be useful in some cases.
At fact since we use uint32_t alignment, then maximum value
that is valid for us is 0x80000000. But some broken files,
for example file from testcase may have greater value.
Because of that offset calculation overflow and crash happens.

Diff Detail

Event Timeline

grimar updated this revision to Diff 73793.Oct 6 2016, 7:21 AM
grimar retitled this revision from to [ELF] - Check that section alignment is a power of 2..
grimar updated this object.
grimar added reviewers: ruiu, rafael, davide.
grimar added subscribers: llvm-commits, grimar, evgeny777.
ruiu added inline comments.Oct 6 2016, 11:16 AM
ELF/InputSection.cpp
59

Technically, an alignment greater than 2^32 is not invalid, so this error message is wrong. Please separate the two conditions and print out different messages

sh_addralign too large
sh_addralign is not a power of 2
ruiu added inline comments.Oct 6 2016, 11:25 AM
ELF/InputSection.cpp
57

Also, please leave a comment here to say that we reject object files having insanely large alignment requirements and may want to relax this limitation in the future.

binutils-ish tools have incredible long lifetime -- GNU ld has been used for decades now for example. We want to leave a hint why we are doing this, so that people who look at this code 10 years later won't have to wonder why we reject 4GB-aligned sections when they are creating 10 terabyte executable.

grimar updated this revision to Diff 73913.Oct 7 2016, 4:39 AM
  • Addressed review comments.
ELF/InputSection.cpp
57

Done.

59

Done.

rafael accepted this revision.Oct 7 2016, 5:22 AM
rafael edited edge metadata.

LGTM

This revision is now accepted and ready to land.Oct 7 2016, 5:22 AM
grimar closed this revision.Oct 7 2016, 5:43 AM

r283544