[PATCH] D55902: [ELF] SymbolTable::addShared: don't set IsNeeded unless IsUsedInRegularObj

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 20 12:37:43 PST 2018


ruiu added inline comments.


================
Comment at: ELF/SymbolTable.cpp:512-514
+    if (!S->isWeak() && S->IsUsedInRegularObj && !Config->GcSections &&
+        WasUndefined)
       File.IsNeeded = true;
----------------
MaskRay wrote:
> ruiu wrote:
> > Thinking about this code, I'm no longer sure if this code makes sense. If IsNeeded is set correctly for --gc-sections, we can just remove this `if` and let the later pass to set an appropriate bit to IsNeeded, maybe?
> This `if` handles the `--no-gc-sections` case. No later passes set the `IsNeeded` bit.
> For the `--gc-sections` case, a later pass (`MarkLive.cpp:resolveReloc`) sets the `IsNeeded` bit.
I still want to make this simpler... At least I don't think this is correct per se, as you need to address the case in which a shared symbol is added first and then an undefined symbol is added later. In that case you need to set IsNeeded too.

I wonder if a DSO is needed if and only if there is a shared symbol for the DSO whose isWeak() and IsUsedRegularObj are both true. If that's the case, we can remove the code from here, and add another loop after the symbol resolution to visit all symbols to set IsNeeded bit for DSOs.


Repository:
  rLLD LLVM Linker

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55902/new/

https://reviews.llvm.org/D55902





More information about the llvm-commits mailing list