Revert "[ELF] Error on relocations to local undefined symbols"
authorDmitri Gribenko <gribozavr@gmail.com>
Mon, 20 May 2019 15:04:08 +0000 (15:04 +0000)
committerDmitri Gribenko <gribozavr@gmail.com>
Mon, 20 May 2019 15:04:08 +0000 (15:04 +0000)
This reverts commit r361144.  It causes a use-of-uninitialized-value in
maybeReportUndefined at llvm/tools/lld/ELF/Relocations.cpp:682, as
detected by MemorySanitizer when local-undefined-symbol.s test is run.

llvm-svn: 361162

lld/ELF/Relocations.cpp
lld/test/ELF/local-undefined-symbol.s

index fbdeb4f346b761a50544e58b5374cc8507b5c42e..74b46174dbf4d1f60f2d34fea0e588a26efb27c1 100644 (file)
@@ -675,7 +675,7 @@ static int64_t computeAddend(const RelTy &Rel, const RelTy *End,
 // Returns true if this function printed out an error message.
 static bool maybeReportUndefined(Symbol &Sym, InputSectionBase &Sec,
                                  uint64_t Offset) {
-  if (!Sym.isUndefined() || Sym.isWeak())
+  if (Sym.isLocal() || !Sym.isUndefined() || Sym.isWeak())
     return false;
 
   bool CanBeExternal =
@@ -1012,8 +1012,7 @@ template <class ELFT, class RelTy>
 static void scanReloc(InputSectionBase &Sec, OffsetGetter &GetOffset, RelTy *&I,
                       RelTy *End) {
   const RelTy &Rel = *I;
-  uint32_t SymIndex = Rel.getSymbol(Config->IsMips64EL);
-  Symbol &Sym = Sec.getFile<ELFT>()->getSymbol(SymIndex);
+  Symbol &Sym = Sec.getFile<ELFT>()->getRelocTargetSym(Rel);
   RelType Type;
 
   // Deal with MIPS oddity.
@@ -1029,9 +1028,8 @@ static void scanReloc(InputSectionBase &Sec, OffsetGetter &GetOffset, RelTy *&I,
   if (Offset == uint64_t(-1))
     return;
 
-  // Error if the target symbol is undefined. Symbol index 0 may be used by
-  // marker relocations, e.g. R_*_NONE and R_ARM_V4BX. Don't error on them.
-  if (SymIndex != 0 && maybeReportUndefined(Sym, Sec, Rel.r_offset))
+  // Skip if the target symbol is an erroneous undefined symbol.
+  if (maybeReportUndefined(Sym, Sec, Rel.r_offset))
     return;
 
   const uint8_t *RelocatedAddr = Sec.data().begin() + Rel.r_offset;
index c2ab207359bf662af7f228d370dd27dfc88033c6..bff8c8bc1dc381f9a559c7e04884b87ad0308a9e 100644 (file)
@@ -1,8 +1,10 @@
 # REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
-# RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: ld.lld %t -o %t1
+# RUN: llvm-readobj --symbols %t1 | FileCheck %s
 
-# CHECK: error: undefined symbol: foo
+# CHECK:     Symbols [
+# CHECK-NOT:  Name: foo
 
 .global _start
 _start: