[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 11:07:25 PDT 2018
rupprecht updated this revision to Diff 171539.
rupprecht added a comment.
- Update test
Repository:
rL LLVM
https://reviews.llvm.org/D53733
Files:
test/tools/llvm-objcopy/globalize-undefined-sym.test
tools/llvm-objcopy/llvm-objcopy.cpp
Index: tools/llvm-objcopy/llvm-objcopy.cpp
===================================================================
--- tools/llvm-objcopy/llvm-objcopy.cpp
+++ tools/llvm-objcopy/llvm-objcopy.cpp
@@ -273,11 +273,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/globalize-undefined-sym.test
===================================================================
--- /dev/null
+++ test/tools/llvm-objcopy/globalize-undefined-sym.test
@@ -0,0 +1,62 @@
+# RUN: yaml2obj %s > %t.o
+# RUN: cp %t.o %t-copy.o
+
+# This test ensures that --globalize-symbol and --keep-global-symbol are noops
+# for undefined symbols.
+
+# RUN: llvm-objcopy --globalize-symbol Weak --globalize-symbol Global %t.o %t.2.o
+# RUN: llvm-readobj -symbols %t.2.o | FileCheck %s
+# RUN: cmp %t.o %t-copy.o
+
+# Use --keep-global-symbol on a non-existant symbol, which causes other symbols
+# to be demoted to local symbols.
+# RUN: llvm-objcopy --keep-global-symbol DoesNotExist %t.o %t.3.o
+# RUN: llvm-readobj -symbols %t.3.o | FileCheck %s
+# RUN: cmp %t.o %t-copy.o
+
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+Symbols:
+ Weak:
+ - Name: Weak
+ Global:
+ - Name: Global
+
+# CHECK: Symbols [
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name:
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Local (0x0)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: Global
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: Weak
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Weak (0x2)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53733.171539.patch
Type: text/x-patch
Size: 2896 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181029/49f8b844/attachment.bin>
More information about the llvm-commits
mailing list