This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Do not segfault if linkerscript tries to access Target too early.
ClosedPublic

Authored by grimar on Aug 1 2017, 4:56 AM.

Details

Summary

Following possible scripts triggered accessing to Target when it was not yet
initialized (was nullptr).

MEMORY { name : ORIGIN = DATA_SEGMENT_RELRO_END; }

MEMORY { name : ORIGIN = CONSTANT(COMMONPAGESIZE); }

Patch errors out instead.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Aug 1 2017, 4:56 AM
ruiu edited edge metadata.Aug 1 2017, 5:49 AM

Please define a helper function getPageSize() to avoid repeating the same error checking twice.

grimar updated this revision to Diff 109103.Aug 1 2017, 7:01 AM
  • Addressed review comment.
ruiu added inline comments.Aug 1 2017, 7:24 AM
ELF/ScriptParser.cpp
796 ↗(On Diff #109103)

Make this a member function.

800–801 ↗(On Diff #109103)

This is better.

return 4096;  // return a dummy value
804 ↗(On Diff #109103)

Make this a member function of LinkerScript so that you don't need to pass Location.

grimar updated this revision to Diff 109297.Aug 2 2017, 1:52 AM
  • Addressed review comments.
ruiu added inline comments.Aug 2 2017, 8:37 PM
ELF/ScriptParser.cpp
798 ↗(On Diff #109297)

Rename getPageSize.

800 ↗(On Diff #109297)

return [=] -> uint64_t { to remove casts.

808 ↗(On Diff #109297)

Rename readConstant.

grimar updated this revision to Diff 109514.Aug 3 2017, 4:21 AM
  • Addressed review comments.
ruiu accepted this revision.Aug 3 2017, 4:36 AM

LGTM

ELF/ScriptParser.cpp
813 ↗(On Diff #109514)

This doesn't capture anything so remove =

This revision is now accepted and ready to land.Aug 3 2017, 4:36 AM
This revision was automatically updated to reflect the committed changes.