[lld] r301897 - ELF: Set symbol binding to STB_GLOBAL when undefining symbols during LTO.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Mon May 1 22:07:42 PDT 2017


Author: pcc
Date: Tue May  2 00:07:41 2017
New Revision: 301897

URL: http://llvm.org/viewvc/llvm-project?rev=301897&view=rev
Log:
ELF: Set symbol binding to STB_GLOBAL when undefining symbols during LTO.

If there is a bug in the LTO implementation that causes it to fail to provide
an expected symbol definition, the linker should report an undefined symbol
error. Unfortunately, we were failing to do so if the symbol definition
was weak, as the undefine() function was turning the definition into a weak
undefined symbol, which resolves to zero if the symbol remains undefined. This
patch causes us to set the binding to STB_GLOBAL when we undefine a symbol.

I can't see a good way to test this. The behaviour should only be observable
if there is a bug in the LTO implementation.

Differential Revision: https://reviews.llvm.org/D32731

Modified:
    lld/trunk/ELF/LTO.cpp

Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=301897&r1=301896&r2=301897&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Tue May  2 00:07:41 2017
@@ -105,6 +105,11 @@ BitcodeCompiler::~BitcodeCompiler() = de
 static void undefine(Symbol *S) {
   replaceBody<Undefined>(S, S->body()->getName(), /*IsLocal=*/false,
                          STV_DEFAULT, S->body()->Type, nullptr);
+  // It shouldn't normally matter what the binding is, but if a bug in the LTO
+  // implementation causes it to fail to provide a definition for a symbol,
+  // setting the binding to STB_GLOBAL will cause the linker to report an
+  // undefined symbol error, even if the definition was weak.
+  S->Binding = STB_GLOBAL;
 }
 
 void BitcodeCompiler::add(BitcodeFile &F) {




More information about the llvm-commits mailing list