This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Fix an assertion failure when -u specifies an undefined section$start symbol
ClosedPublic

Authored by MaskRay on Nov 3 2021, 2:41 PM.

Details

Summary

This matches ld64. Also improve the test for -dead_strip.

Diff Detail

Event Timeline

MaskRay created this revision.Nov 3 2021, 2:41 PM
Herald added a project: Restricted Project. · View Herald Transcript
MaskRay requested review of this revision.Nov 3 2021, 2:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 3 2021, 2:41 PM
int3 added a subscriber: int3.Nov 3 2021, 9:47 PM

I don't understand this... shouldn't -u symbols also be marked live? MarkLive.cpp does traverse explicitUndefineds after all. Also I patched this diff, added back the assert, and ran the start-end.s test, and the assert wasn't triggered

MaskRay updated this revision to Diff 384666.Nov 3 2021, 10:37 PM

fix test: now it does crash without the patch

int3 added a comment.Nov 4 2021, 11:13 AM

Gotcha, thanks for fixing the test. I still think the assert is correct... as long as we fix MarkLive to mark all explicitUndefineds:

--- a/lld/MachO/MarkLive.cpp
+++ b/lld/MachO/MarkLive.cpp
@@ -96,8 +96,7 @@ void markLive() {
   }
   // -u symbols
   for (Symbol *sym : config->explicitUndefineds)
-    if (auto *defined = dyn_cast<Defined>(sym))
-      addSym(defined);
+    addSym(sym);
   // local symbols explicitly marked .no_dead_strip
   for (const InputFile *file : inputFiles)
     if (auto *objFile = dyn_cast<ObjFile>(file))
MaskRay updated this revision to Diff 384826.Nov 4 2021, 11:29 AM

properly fix the issue as Jez suggested

MaskRay updated this revision to Diff 384828.Nov 4 2021, 11:31 AM

add missing RUN line

int3 accepted this revision.Nov 4 2021, 12:03 PM

Thanks!

This revision is now accepted and ready to land.Nov 4 2021, 12:03 PM
thakis added a comment.Nov 5 2021, 1:01 PM

LGTM too. Thanks for the patch, and thanks to int3 for the excellent review :)