[PATCH] D53733: [llvm-objcopy] Fix --keep-global-symbol/--globalize-symbol for undefined symbols.
Jordan Rupprecht via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 29 15:47:43 PDT 2018
rupprecht updated this revision to Diff 171601.
rupprecht added a comment.
- typo
Repository:
rL LLVM
https://reviews.llvm.org/D53733
Files:
test/tools/llvm-objcopy/globalize.test
test/tools/llvm-objcopy/keep-global-symbols.test
tools/llvm-objcopy/ELF/ELFObjcopy.cpp
Index: tools/llvm-objcopy/ELF/ELFObjcopy.cpp
===================================================================
--- tools/llvm-objcopy/ELF/ELFObjcopy.cpp
+++ tools/llvm-objcopy/ELF/ELFObjcopy.cpp
@@ -230,11 +230,13 @@
// --keep-global-symbol. Because of that, make sure to check
// --globalize-symbol second.
if (!Config.SymbolsToKeepGlobal.empty() &&
- !is_contained(Config.SymbolsToKeepGlobal, Sym.Name))
+ !is_contained(Config.SymbolsToKeepGlobal, Sym.Name) &&
+ Sym.getShndx() != SHN_UNDEF)
Sym.Binding = STB_LOCAL;
if (!Config.SymbolsToGlobalize.empty() &&
- is_contained(Config.SymbolsToGlobalize, Sym.Name))
+ is_contained(Config.SymbolsToGlobalize, Sym.Name) &&
+ Sym.getShndx() != SHN_UNDEF)
Sym.Binding = STB_GLOBAL;
if (!Config.SymbolsToWeaken.empty() &&
Index: test/tools/llvm-objcopy/keep-global-symbols.test
===================================================================
--- test/tools/llvm-objcopy/keep-global-symbols.test
+++ test/tools/llvm-objcopy/keep-global-symbols.test
@@ -18,6 +18,8 @@
# "Global5 Global6": Global, because it appears in %t-globals2.txt, but we only
# trim leading and trailing whitespace. We don't just take the first chunk
# that looks like a symbol.
+# Global7: Global, because even though it doesn't appear as any -G flags, does
+# not get demoted since it's undefined.
# RUN: echo Global2 > %t-globals1.txt
# RUN: echo " Global3 " > %t-globals2.txt
@@ -77,8 +79,9 @@
Section: .text
- Name: "Global5 Global6"
Section: .text
+ - Name: Global7
-# CHECK: Symbol table '.symtab' contains 13 entries:
+# CHECK: Symbol table '.symtab' contains 14 entries:
# CHECK-NEXT: Num: Value Size Type Bind Vis Ndx Name
# CHECK-NEXT: 0: {{.*}} LOCAL {{.*}}
# CHECK-NEXT: 1: {{.*}} LOCAL {{.*}} Local1
@@ -91,5 +94,6 @@
# CHECK-NEXT: 8: {{.*}} GLOBAL {{.*}} Global3
# CHECK-NEXT: 9: {{.*}} GLOBAL {{.*}} Global4
# CHECK-NEXT: 10: {{.*}} GLOBAL {{.*}} Global5 Global6
-# CHECK-NEXT: 11: {{.*}} WEAK {{.*}} Weak1
-# CHECK-NEXT: 12: {{.*}} GLOBAL {{.*}} Weak2
+# CHECK-NEXT: 11: {{.*}} GLOBAL {{.*}} UND Global7
+# CHECK-NEXT: 12: {{.*}} WEAK {{.*}} Weak1
+# CHECK-NEXT: 13: {{.*}} GLOBAL {{.*}} Weak2
Index: test/tools/llvm-objcopy/globalize.test
===================================================================
--- test/tools/llvm-objcopy/globalize.test
+++ test/tools/llvm-objcopy/globalize.test
@@ -1,5 +1,8 @@
# RUN: yaml2obj %s > %t
-# RUN: llvm-objcopy --globalize-symbol Global --globalize-symbol Local --globalize-symbol Weak %t %t2
+# RUN: llvm-objcopy --globalize-symbol Global \
+# RUN: --globalize-symbol Local \
+# RUN: --globalize-symbol Weak \
+# RUN: --globalize-symbol WeakUndef %t %t2
# RUN: llvm-readobj -symbols %t2 | FileCheck %s
!ELF
@@ -28,6 +31,7 @@
Size: 8
Section: .text
Value: 0x1008
+ - Name: WeakUndef
Global:
- Name: Global
Type: STT_FUNC
@@ -72,4 +76,13 @@
#CHECK-NEXT: Other: 0
#CHECK-NEXT: Section: .text
#CHECK-NEXT: }
+#CHECK-NEXT: Symbol {
+#CHECK-NEXT: Name: WeakUndef
+#CHECK-NEXT: Value: 0x0
+#CHECK-NEXT: Size: 0
+#CHECK-NEXT: Binding: Weak
+#CHECK-NEXT: Type: None
+#CHECK-NEXT: Other: 0
+#CHECK-NEXT: Section: Undefined
+#CHECK-NEXT: }
#CHECK-NEXT:]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53733.171601.patch
Type: text/x-patch
Size: 3485 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181029/bc857bc5/attachment.bin>
More information about the llvm-commits
mailing list