[llvm] 30718f3 - [llvm-objcopy] --weaken-symbol/--weaken: weaken STB_GNU_UNIQUE symbols
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 16 09:48:25 PDT 2022
Author: Fangrui Song
Date: 2022-03-16T09:48:19-07:00
New Revision: 30718f3aa62b81c2814564d2ca08888435202655
URL: https://github.com/llvm/llvm-project/commit/30718f3aa62b81c2814564d2ca08888435202655
DIFF: https://github.com/llvm/llvm-project/commit/30718f3aa62b81c2814564d2ca08888435202655.diff
LOG: [llvm-objcopy] --weaken-symbol/--weaken: weaken STB_GNU_UNIQUE symbols
STB_GNU_UNIQUE is like STB_GLOBAL with extra semantics:
* gold and ld.lld: changed to STB_GLOBAL if --no-gnu-unique is specified
* glibc: unique even with dlopen `RTLD_LOCAL`, implies DF_1_NODELETE
Therefore, I think it makes sense for --weaken-symbol/--weaken-symbols/--weaken
to change STB_GNU_UNIQUE symbols.
binutils 2.39 will have the same behavior: https://sourceware.org/bugzilla/show_bug.cgi?id=28926
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D120638
Added:
Modified:
llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
llvm/test/tools/llvm-objcopy/ELF/weaken-all.test
llvm/test/tools/llvm-objcopy/ELF/weaken.test
Removed:
################################################################################
diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
index bbbbd9f990073..f759fac5ac111 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
@@ -302,10 +302,11 @@ static Error updateAndRemoveSymbols(const CommonConfig &Config,
Sym.getShndx() != SHN_UNDEF)
Sym.Binding = STB_GLOBAL;
- if (Config.SymbolsToWeaken.matches(Sym.Name) && Sym.Binding == STB_GLOBAL)
+ // SymbolsToWeaken applies to both STB_GLOBAL and STB_GNU_UNIQUE.
+ if (Config.SymbolsToWeaken.matches(Sym.Name) && Sym.Binding != STB_LOCAL)
Sym.Binding = STB_WEAK;
- if (Config.Weaken && Sym.Binding == STB_GLOBAL &&
+ if (Config.Weaken && Sym.Binding != STB_LOCAL &&
Sym.getShndx() != SHN_UNDEF)
Sym.Binding = STB_WEAK;
diff --git a/llvm/test/tools/llvm-objcopy/ELF/weaken-all.test b/llvm/test/tools/llvm-objcopy/ELF/weaken-all.test
index 6fd8b64715f91..69f4ebc6f0a46 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/weaken-all.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/weaken-all.test
@@ -44,6 +44,10 @@ Symbols:
Section: .text
Value: 0x1010
Binding: STB_WEAK
+ - Name: GnuUnique
+ Section: .text
+ Value: 0x1010
+ Binding: STB_GNU_UNIQUE
#CHECK: Symbols [
#CHECK-NEXT: Symbol {
@@ -91,4 +95,13 @@ Symbols:
#CHECK-NEXT: Other: 0
#CHECK-NEXT: Section: .text
#CHECK-NEXT: }
+#CHECK-NEXT: Symbol {
+#CHECK-NEXT: Name: GnuUnique
+#CHECK-NEXT: Value: 0x1010
+#CHECK-NEXT: Size: 0
+#CHECK-NEXT: Binding: Weak
+#CHECK-NEXT: Type: None
+#CHECK-NEXT: Other: 0
+#CHECK-NEXT: Section: .text
+#CHECK-NEXT: }
#CHECK-NEXT:]
diff --git a/llvm/test/tools/llvm-objcopy/ELF/weaken.test b/llvm/test/tools/llvm-objcopy/ELF/weaken.test
index a23a4fc0fbc81..107c5a03521ef 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/weaken.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/weaken.test
@@ -1,17 +1,19 @@
# RUN: yaml2obj %s -o %t
-# RUN: llvm-objcopy --weaken-symbol Global -W Local -W Weak -W Missing %t %t2
+# RUN: llvm-objcopy --weaken-symbol Global -W Local -W Weak -W GnuUnique -W Missing %t %t2
# RUN: llvm-readobj --symbols %t2 | FileCheck %s
# RUN: llvm-objcopy --regex --weaken-symbol='[LGW].*' %t %t3
# RUN: cmp %t2 %t3
# RUN: echo " Global # comment" > %t-list.txt
# RUN: echo "Local" >> %t-list.txt
# RUN: echo "Weak" >> %t-list.txt
+# RUN: echo "GnuUnique" >> %t-list.txt
# RUN: echo "Missing" >> %t-list.txt
# RUN: echo " # comment" >> %t-list.txt
# RUN: llvm-objcopy --weaken-symbols %t-list.txt %t %t4
# RUN: cmp %t2 %t4
# RUN: echo ".*al # Global + Local == .*al" > %t-list2.txt
# RUN: echo "Weak # weak" >> %t-list2.txt
+# RUN: echo " Gnu.*" >> %t-list2.txt
# RUN: llvm-objcopy --regex --weaken-symbols %t-list2.txt %t %t5
# RUN: cmp %t2 %t5
@@ -46,6 +48,9 @@ Symbols:
Section: .text
Value: 0x1008
Binding: STB_WEAK
+ - Name: GnuUnique
+ Section: .text
+ Binding: STB_GNU_UNIQUE
- Name: Unspecified
Section: .text
Binding: STB_GLOBAL
@@ -88,6 +93,15 @@ Symbols:
#CHECK-NEXT: Section: .text
#CHECK-NEXT: }
#CHECK-NEXT: Symbol {
+#CHECK-NEXT: Name: GnuUnique
+#CHECK-NEXT: Value: 0x0
+#CHECK-NEXT: Size: 0
+#CHECK-NEXT: Binding: Weak
+#CHECK-NEXT: Type: None
+#CHECK-NEXT: Other: 0
+#CHECK-NEXT: Section: .text
+#CHECK-NEXT: }
+#CHECK-NEXT: Symbol {
#CHECK-NEXT: Name: Unspecified
#CHECK-NEXT: Value: 0x0
#CHECK-NEXT: Size: 0
More information about the llvm-commits
mailing list