This is an archive of the discontinued LLVM Phabricator instance.

[ELF2] -z now option implemented
ClosedPublic

Authored by grimar on Oct 6 2015, 5:59 AM.

Details

Summary

When generating an executable or shared library, mark it to tell the dynamic linker to resolve all symbols when the program is started, or when the shared library is linked to using dlopen, instead of deferring function call resolution to the point when the function is first called.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 36613.Oct 6 2015, 5:59 AM
grimar retitled this revision from to [ELF2] -z now option implemented.
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added a project: lld.
grimar added subscribers: llvm-commits, grimar.
emaste added a subscriber: emaste.Oct 6 2015, 6:05 AM
emaste added inline comments.Oct 6 2015, 6:34 AM
ELF/Options.td
76 ↗(On Diff #36613)

Should this be JoinedOrSeparate?

While trying the FreeBSD base system build with LLD I see that -znodelete is passed to the linker.

grimar added inline comments.Oct 6 2015, 6:46 AM
ELF/Options.td
76 ↗(On Diff #36613)

Looks like ld/gold accepts both variants. -help indicates to separate syntax thought.

ruiu added inline comments.Oct 6 2015, 9:12 AM
ELF/Config.h
37 ↗(On Diff #36613)

Name this ZNow so that -z foo would get different name than -foo.

ELF/Driver.cpp
142–144 ↗(On Diff #36613)

If doesn't have {} and else has? Please make this consistent.

143 ↗(On Diff #36613)

Let's not warn on unknown options for now. They were silently ignored before this patch.

ELF/OutputSections.cpp
319–324 ↗(On Diff #36613)
if (Config->Now)
  WriteVal(DT_FLAGS_1, DF_1_NOW);
grimar added inline comments.Oct 6 2015, 10:20 AM
ELF/Driver.cpp
143 ↗(On Diff #36613)

Yes, I know they were. But this is equals to ld behavior now. It shows warnings on unknown -z options. But if you wish I will remove.

ELF/OutputSections.cpp
319–324 ↗(On Diff #36613)

There are many possible -z options. And Flag is requred to combine them when at least one more will be added.

ruiu added inline comments.Oct 6 2015, 10:59 AM
ELF/Driver.cpp
143 ↗(On Diff #36613)

Ultimately we will want to warn on unknown options, but for now we ignore lots of options for ease of development, and I think -z is not an exception.

ELF/OutputSections.cpp
319–324 ↗(On Diff #36613)

I'd want you to update the code to use a variable when you need the variable. Currently it can be written without that.

grimar updated this revision to Diff 36710.Oct 7 2015, 12:47 AM

All review comments addressed.

ELF/Options.td
76 ↗(On Diff #36613)

Changed to JoinedOrSeparate.

grimar added inline comments.Oct 7 2015, 2:40 AM
ELF/Driver.cpp
143–145 ↗(On Diff #36710)

Fixed.

144 ↗(On Diff #36710)

Ok.

ELF/OutputSections.cpp
346–351 ↗(On Diff #36710)

Ok.

ruiu accepted this revision.Oct 7 2015, 6:18 AM
ruiu edited edge metadata.

LGTM with a nit.

ELF/Driver.cpp
139–143 ↗(On Diff #36710)

This can be

for (auto *Arg : Args.filtered(OPT_z))
  if (Arg->getValue() == "now")
    Config->ZNow = true;
This revision is now accepted and ready to land.Oct 7 2015, 6:18 AM
grimar added inline comments.Oct 7 2015, 6:40 AM
ELF/Driver.cpp
139–143 ↗(On Diff #36710)

Unfortunately no because getValue() returns char*.

I'll rewrite to:

if (Arg->getValue() == StringRef("now"))
  Config->ZNow = true;
This revision was automatically updated to reflect the committed changes.