This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Implement -ObjC
ClosedPublic

Authored by int3 on Aug 18 2020, 5:31 PM.

Details

Reviewers
compnerd
smeenai
Group Reviewers
Restricted Project
Commits
rGcf918c809bb0: [lld-macho] Implement -ObjC
Summary

It's roughly like -force_load with some filtering.

Diff Detail

Event Timeline

int3 created this revision.Aug 18 2020, 5:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 18 2020, 5:31 PM
int3 requested review of this revision.Aug 18 2020, 5:31 PM
compnerd accepted this revision.Aug 20 2020, 10:20 AM
compnerd added a subscriber: compnerd.
compnerd added inline comments.
lld/MachO/ObjC.cpp
28

Would you mind replacing 16 with sizeof(llvm::MachO::section::sectname) and sizeof(llvm::MachO::section::segname) respectively?

This revision is now accepted and ready to land.Aug 20 2020, 10:20 AM
int3 updated this revision to Diff 286864.Aug 20 2020, 11:10 AM
int3 marked an inline comment as done.

use sizeof

smeenai accepted this revision.Aug 26 2020, 1:41 PM
smeenai added a subscriber: smeenai.

LGTM

lld/MachO/Driver.cpp
254

I don't think this'll cause any issues with actual usage, but I'll just note that this isn't strictly equivalent to forcing a load of the archive member with that symbol. For example, if you already had a symbol with the same name (e.g. from an object file that's already been processed), this implementation won't load the archive member containing that symbol, whereas I believe ld64 would (and give you a multiply defined symbol error).

266

So we'd be adding ObjC-containing members twice, once as an ObjFile above and once as part of this archive? I don't think it'll cause any issues in practice, but it feels a little ugly conceptually. I think this is fine for now, but long-term it'd be nice to have something like LazyObjFile (like COFF and ELF do) to add each member only once (as either an ObjFile or a LazyObjFile). That would also address the TODO above and my previous comment.

lld/test/MachO/objc.s
2

Can you add an input archive with multiple members and show that only the member containing the Obj-C symbols/sections gets pulled in? Right now I think all the tests would pass if you replaced -ObjC with -all_load; I want a test which shows the difference between the two.

int3 updated this revision to Diff 288127.Aug 26 2020, 3:57 PM
int3 marked 2 inline comments as done.

address comments

lld/MachO/Driver.cpp
266

yeah, that's true. I'll expand the TODO comment above to mention this.

This revision was landed with ongoing or failed builds.Aug 26 2020, 7:27 PM
This revision was automatically updated to reflect the committed changes.