This is an archive of the discontinued LLVM Phabricator instance.

Add some basic linker module symbols
ClosedPublic

Authored by zturner on Jul 7 2017, 2:58 PM.

Details

Summary

To get this more correct we need to plumb a few additional values through, such as the argv0 and the command line. I need to get that done before I commit this, but throwing this up for early comments.

Diff Detail

Repository
rL LLVM

Event Timeline

zturner created this revision.Jul 7 2017, 2:58 PM
ruiu added inline comments.Jul 10 2017, 10:54 AM
lld/COFF/PDB.cpp
411 ↗(On Diff #105706)

Is this value the same on x86-64?

zturner added inline comments.Jul 10 2017, 10:59 AM
lld/COFF/PDB.cpp
411 ↗(On Diff #105706)

That's a good question, I should check.

zturner updated this revision to Diff 105903.Jul 10 2017, 12:50 PM

Update the test to properly check for x64, and finish up the remaining missing pieces. In particular, we need the value of argv[0] in order to portably get the executable name, and we need the values of argv[1] - argv[argc-1] in order to write them to the S_ENVBLOCK symbol. To address this, I deleted the global Argv0 variable that LLD currently used, and instead stored the entire argv array in the global configuration object.

I also added a test. Unfortunately checking for paths is pretty obnoxious in tests, requiring some magic sed incantation, so I've just regex'ed them all out in this test. Perhaps someone else can do better here.

smeenai added inline comments.
lld/COFF/PDB.cpp
411 ↗(On Diff #105706)

Probably dumb question: what about ARM (and AArch64 in the future)?

ruiu accepted this revision.Jul 10 2017, 1:08 PM

LGTM

lld/COFF/Config.h
95 ↗(On Diff #105903)

This can be ArrayRef.

This revision is now accepted and ready to land.Jul 10 2017, 1:08 PM
zturner added inline comments.Jul 10 2017, 1:14 PM
lld/COFF/Config.h
95 ↗(On Diff #105903)

In order to make it ArrayRef I have to make it ArrayRef<const char *>. This is what I had in an earlier version of the patch, but I had problems on the call to llvm::join() (because you can't use operator+ on two const char*. So if I want to be able to use StringRef, it has to be std::vector

lld/COFF/PDB.cpp
411 ↗(On Diff #105706)

Whoever's interested in adding PDB support for ARM and AArch64` can update this code :) The CPUType enumeration has a bunch of ARM values in the enumeration:

ARM3 = 0x60,
ARM4 = 0x61,
ARM4T = 0x62,
ARM5 = 0x63,
ARM5T = 0x64,
ARM6 = 0x65,
ARM_XMAC = 0x66,
ARM_WMMX = 0x67,
ARM7 = 0x68,
ARMNT = 0xf4,

the differences between which are not obvious to me :) But the support is there (in theory) for whoever wants this.

zturner added inline comments.Jul 10 2017, 1:16 PM
lld/COFF/PDB.cpp
411 ↗(On Diff #105706)

Actually ARM64 is probably ARM8, which does not seem to be represented in this enumeration. So there will be some head scratching involved to figure out what to do there

ruiu added inline comments.Jul 10 2017, 1:16 PM
lld/COFF/Config.h
95 ↗(On Diff #105903)

Makes sense.

lld/COFF/PDB.cpp
411 ↗(On Diff #105706)

Agreed. We can change this later when someone wants PDB support for ARM/ARM64.

ruiu added inline comments.Jul 10 2017, 1:21 PM
lld/COFF/Error.h
21 ↗(On Diff #105903)

Sorry for the last-minute comment, but can you keep this variable and just change it stype from llvm::StringRef to std::vector<llvm::StringRef> to make it consistent with ELF? I don't want to make them being diverged too much.

zturner added inline comments.Jul 10 2017, 1:22 PM
lld/COFF/Error.h
21 ↗(On Diff #105903)

Is it ok to have a global std::vector? This might invoke an undesirable global constructor.

ruiu added inline comments.Jul 10 2017, 1:24 PM
lld/COFF/Error.h
21 ↗(On Diff #105903)

Well, it might not be desirable, but we already have a few global std::vectors.

Should I still leave the variable in Error.h? It seems a little illogical to have the variable in Error.h given that it's now being used outside of Error related code. Config.h seems like the logical place for it. Maybe the best thing to do is add the vector in Configuration of ELF linker too?

ruiu added a comment.Jul 10 2017, 1:30 PM

Updating the ELF side should work, too.

zturner updated this revision to Diff 105917.Jul 10 2017, 1:38 PM

Updated the ELF side.

ruiu accepted this revision.Jul 10 2017, 1:50 PM

LGTM

lld/COFF/Driver.cpp
59 ↗(On Diff #105917)

I honestly didn't know that std::vector has assign member function. Does

Config->Argv = {Args.begin(), Args.end()};

work too? If so, I prefer this way.

lld/ELF/Config.h
107 ↗(On Diff #105917)

Move this before AuxiliaryList.

zturner added inline comments.Jul 10 2017, 2:01 PM
lld/COFF/Driver.cpp
59 ↗(On Diff #105917)

Yes, that works. In general assign is more efficient because it uses already reserved storage. In this case it doesn't matter since we're actually just initializing it. But say for example you have a vector with 1000 items in it, in that case assign() would be better since it wouldn't free the internal buffer. In any case, I've made the change you suggested and will submit like that.

This revision was automatically updated to reflect the committed changes.