[PATCH] D61563: [ELF] Error on relocations to local undefined symbols

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 20 04:16:24 PDT 2019


MaskRay updated this revision to Diff 200246.
MaskRay added a comment.

R_ARM_V4BX uses symbol index 0. Clarify why we check SymIndex != 0 instead of Type != Target->NoneRel


Repository:
  rLLD LLVM Linker

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

https://reviews.llvm.org/D61563

Files:
  ELF/Relocations.cpp
  test/ELF/local-undefined-symbol.s


Index: test/ELF/local-undefined-symbol.s
===================================================================
--- test/ELF/local-undefined-symbol.s
+++ test/ELF/local-undefined-symbol.s
@@ -1,10 +1,8 @@
 # REQUIRES: x86
-# 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
+# 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
 
-# CHECK:     Symbols [
-# CHECK-NOT:  Name: foo
+# CHECK: error: undefined symbol: foo
 
 .global _start
 _start:
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -675,7 +675,7 @@
 // Returns true if this function printed out an error message.
 static bool maybeReportUndefined(Symbol &Sym, InputSectionBase &Sec,
                                  uint64_t Offset) {
-  if (Sym.isLocal() || !Sym.isUndefined() || Sym.isWeak())
+  if (!Sym.isUndefined() || Sym.isWeak())
     return false;
 
   bool CanBeExternal =
@@ -1012,7 +1012,8 @@
 static void scanReloc(InputSectionBase &Sec, OffsetGetter &GetOffset, RelTy *&I,
                       RelTy *End) {
   const RelTy &Rel = *I;
-  Symbol &Sym = Sec.getFile<ELFT>()->getRelocTargetSym(Rel);
+  uint32_t SymIndex = Rel.getSymbol(Config->IsMips64EL);
+  Symbol &Sym = Sec.getFile<ELFT>()->getSymbol(SymIndex);
   RelType Type;
 
   // Deal with MIPS oddity.
@@ -1028,8 +1029,10 @@
   if (Offset == uint64_t(-1))
     return;
 
-  // Skip if the target symbol is an erroneous undefined symbol.
-  if (maybeReportUndefined(Sym, Sec, Rel.r_offset))
+  // Skip if the target symbol is an erroneous undefined symbol. SymIndex 0 may
+  // be used by marker relocations, e.g. R_*_NONE, R_ARM_V4BX. Don't error on
+  // them.
+  if (SymIndex != 0 && maybeReportUndefined(Sym, Sec, Rel.r_offset))
     return;
 
   const uint8_t *RelocatedAddr = Sec.data().begin() + Rel.r_offset;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61563.200246.patch
Type: text/x-patch
Size: 2005 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190520/e9f0f762/attachment.bin>


More information about the llvm-commits mailing list