This is an archive of the discontinued LLVM Phabricator instance.

Implement --{push,pop}-state.
ClosedPublic

Authored by ruiu on May 30 2018, 10:01 AM.

Details

Summary

--push-state implemented in this patch saves the states of --as-needed,
--whole-archive and --static. It saves less number of flags than GNU linkers.
Since even GNU linkers save different flags, no one seems to care about the
details. In this patch, I tried to save the minimal number of flags to not
complicate the implementation and the siutation.

I'm not personally happy to add the --{push,pop}-state flags though.
That options seem too hacky to me. However, gcc started using the options
since GCC 8 when GNU ld is available at the build time. Thererfore, lld
is no longer a drop-in replacmenet for GNU linker for that machine
without supporting the flags.

Diff Detail

Repository
rL LLVM

Event Timeline

ruiu created this revision.May 30 2018, 10:01 AM
grimar accepted this revision.May 31 2018, 2:27 AM

This is LGTM as is, but also added a suggestion about possible simplification.
I have no strong preference here though. I assume no much people will use this option anyways.

lld/ELF/Driver.cpp
944 ↗(On Diff #149150)

One idea based on the difference of bfd and gold implementations.
As far I know, gold implements the true stack, but bfd - don't (https://sourceware.org/bugzilla/show_bug.cgi?id=18989#c2).
And letting users use the full power of nesting in invocations looks like a road to hell..

So should we just do it Optional<std::tuple<bool, bool, bool>> Stack?
Also, I would rename to State then.
(Or States if you decide to go with the true stack). It is consistent with the option name.

1032 ↗(On Diff #149150)

Then it can be probably a bit simpler:

if (!Stack))
  error("--pop-state used without --push-state");
std::tie(Config->AsNeeded, Config->Static, InWholeArchive) =
  Stack.getValueOr(std::tuple<bool, bool, bool>());
break;
This revision is now accepted and ready to land.May 31 2018, 2:27 AM
ruiu added inline comments.May 31 2018, 5:33 AM
lld/ELF/Driver.cpp
944 ↗(On Diff #149150)

Looks like bfd linker at least can count the nesting depth. Are you sure that bfd cannot keep the stack of states?

$ ld.bfd --push-state --push-state --pop-state --pop-state
ld.bfd: no input files

$ ld.bfd --push-state --push-state --pop-state --pop-state --pop-state
ld.bfd: no state pushed before popping
grimar added inline comments.May 31 2018, 5:54 AM
lld/ELF/Driver.cpp
944 ↗(On Diff #149150)

It just what that comment in their bugzilla seems was saying. But I did not check that.

ruiu added a comment.May 31 2018, 5:56 AM

I don't know how it was implemented at the time when the bugzilla comment was posted, but it seems bfd linker's --push-state is a real stack now.

I don't know how it was implemented at the time when the bugzilla comment was posted, but it seems bfd linker's --push-state is a real stack now.

Ok. Perhaps we should just follow then.

This revision was automatically updated to reflect the committed changes.