[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
Thu Oct 25 14:47:48 PDT 2018
rupprecht created this revision.
rupprecht added reviewers: jhenderson, alexshap, jakehehrlich.
Herald added a subscriber: llvm-commits.
--keep-global-symbol and --globalize-symbol don't make sense for undefined symbols, so it should be ignored for those symbols. This matches GNU objcopy behavior.
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,60 @@
+# 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
+
+# RUN: llvm-objcopy --keep-global-symbol Foo %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.171201.patch
Type: text/x-patch
Size: 2771 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181025/6214ea1a/attachment-0001.bin>
More information about the llvm-commits
mailing list