[lld] ab11ed5 - [ELF] Reset verdefIndex for Defined preempting SharedSymbol

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 29 21:27:02 PDT 2022


Author: Fangrui Song
Date: 2022-09-29T21:26:53-07:00
New Revision: ab11ed5249401e9ff12f034e49942693ea035594

URL: https://github.com/llvm/llvm-project/commit/ab11ed5249401e9ff12f034e49942693ea035594
DIFF: https://github.com/llvm/llvm-project/commit/ab11ed5249401e9ff12f034e49942693ea035594.diff

LOG: [ELF] Reset verdefIndex for Defined preempting SharedSymbol

to avoid spurious "attempt to reassign symbol '...'" warning after
7a58dd1046a8052619d173b769f32f2df3aafbe8

Added: 
    

Modified: 
    lld/ELF/Relocations.cpp
    lld/ELF/Symbols.h
    lld/test/ELF/verdef-defaultver.s

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index e2e7a5ee79eb8..696e172419acb 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -301,6 +301,7 @@ static void replaceWithDefined(Symbol &sym, SectionBase &sec, uint64_t value,
           size, &sec)
       .overwrite(sym);
 
+  sym.verdefIndex = old.verdefIndex;
   sym.exportDynamic = true;
   sym.isUsedInRegularObj = true;
   // A copy relocated alias may need a GOT entry.

diff  --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index 5ef08a6fa6808..2d1b1d4a47e79 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -344,6 +344,7 @@ class Defined : public Symbol {
   }
   void overwrite(Symbol &sym) const {
     Symbol::overwrite(sym, DefinedKind);
+    sym.verdefIndex = -1;
     auto &s = static_cast<Defined &>(sym);
     s.value = value;
     s.size = size;

diff  --git a/lld/test/ELF/verdef-defaultver.s b/lld/test/ELF/verdef-defaultver.s
index 36913ad8b74a7..7becdcf96422b 100644
--- a/lld/test/ELF/verdef-defaultver.s
+++ b/lld/test/ELF/verdef-defaultver.s
@@ -1,5 +1,6 @@
 # REQUIRES: x86
 
+# RUN: rm -rf %t && split-file %s %t && cd %t
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/verdef-defaultver.s -o %t1
 # RUN: echo "V1 { global: a; b; local: *; };" > %t.script
 # RUN: echo "V2 { global: b; c; } V1;" >> %t.script
@@ -107,9 +108,9 @@
 # DSO-NEXT:  ]
 
 ## Check that we can link against DSO produced.
-# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2
-# RUN: ld.lld --hash-style=sysv %t2 %t.so -o %t3
-# RUN: llvm-readobj -V --dyn-syms %t3 | FileCheck --check-prefix=EXE %s
+# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
+# RUN: ld.lld --hash-style=sysv a.o %t.so -o a
+# RUN: llvm-readobj -V --dyn-syms a | FileCheck --check-prefix=EXE %s
 
 # EXE:      DynamicSymbols [
 # EXE-NEXT:    Symbol {
@@ -193,8 +194,23 @@
 # EXE-NEXT:    }
 # EXE-NEXT:  ]
 
+# RUN: llvm-mc -filetype=obj -triple=x86_64 b.s -o b.o
+# RUN: ld.lld -shared --version-script=%t.script --fatal-warnings %t.so b.o -o b.so
+# RUN: llvm-readelf --dyn-syms b.so | FileCheck %s --check-prefix=PREEMPT
+# RUN: ld.lld -shared --version-script=%t.script --fatal-warnings b.o %t.so -o b.so
+# RUN: llvm-readelf --dyn-syms b.so | FileCheck %s --check-prefix=PREEMPT
+
+# PREEMPT-DAG: a@@V1
+# PREEMPT-DAG: c@@V2
+
+#--- a.s
 .globl _start
 _start:
   .long a - .
   .long b - .
   .long c - .
+
+#--- b.s
+.globl a, c
+a:
+c:


        


More information about the llvm-commits mailing list