[llvm] 7c65e88 - [llvm-objcopy] Match GNU behaviour regarding file symbols
Yi Kong via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 20 20:30:18 PDT 2020
Author: Yi Kong
Date: 2020-04-21T11:30:04+08:00
New Revision: 7c65e88d0bc85ff2732a4e23c397ff842b97b828
URL: https://github.com/llvm/llvm-project/commit/7c65e88d0bc85ff2732a4e23c397ff842b97b828
DIFF: https://github.com/llvm/llvm-project/commit/7c65e88d0bc85ff2732a4e23c397ff842b97b828.diff
LOG: [llvm-objcopy] Match GNU behaviour regarding file symbols
GNU objcopy removes STT_FILE symbols for strip-debug operations, and
keeps them for --discard-all operation. Match their behaviour for
llvm-objcopy.
Bug: https://github.com/android/ndk/issues/1212
Differential Revision: https://reviews.llvm.org/D76675
Added:
Modified:
llvm/test/tools/llvm-objcopy/ELF/keep-file-symbols.test
llvm/test/tools/llvm-objcopy/ELF/strip-debug.test
llvm/tools/llvm-objcopy/CopyConfig.cpp
llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-objcopy/ELF/keep-file-symbols.test b/llvm/test/tools/llvm-objcopy/ELF/keep-file-symbols.test
index 30e4aae225c4..8471c1831ae8 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/keep-file-symbols.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/keep-file-symbols.test
@@ -9,6 +9,16 @@
# RUN: llvm-strip --keep-file-symbols --strip-symbol foo %t -o %t4
# RUN: llvm-readobj --symbols %t4 | FileCheck %s --check-prefix=STRIP
+# RUN: llvm-objcopy --keep-file-symbols --strip-debug %t %t5
+# RUN: llvm-readobj --symbols %t5 | FileCheck %s --check-prefix=STRIPDEBUG
+# RUN: llvm-objcopy --keep-file-symbols --strip-unneeded %t %t6
+# RUN: llvm-readobj --symbols %t6 | FileCheck %s --check-prefix=STRIPDEBUG
+
+# RUN: llvm-strip --keep-file-symbols --strip-debug %t -o %t7
+# RUN: llvm-readobj --symbols %t7 | FileCheck %s --check-prefix=STRIPDEBUG
+# RUN: llvm-strip --keep-file-symbols --strip-unneeded %t -o %t8
+# RUN: llvm-readobj --symbols %t8 | FileCheck %s --check-prefix=STRIPDEBUG
+
!ELF
FileHeader:
Class: ELFCLASS64
@@ -16,6 +26,9 @@ FileHeader:
Type: ET_REL
Machine: EM_X86_64
Sections:
+ - Name: .debugfoo
+ Type: SHT_PROGBITS
+ Content: "00000000"
- Name: .text
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
@@ -30,6 +43,9 @@ Symbols:
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
+ - Name: debugfoo
+ Section: .debugfoo
+ Binding: STB_GLOBAL
#STRIPALL: Symbols [
#STRIPALL-NEXT: Symbol {
@@ -80,4 +96,43 @@ Symbols:
#STRIP-NEXT: Other: 0
#STRIP-NEXT: Section: .text
#STRIP-NEXT: }
+#STRIP-NEXT: Symbol {
+#STRIP-NEXT: Name: debugfoo
+#STRIP-NEXT: Value: 0x0
+#STRIP-NEXT: Size: 0
+#STRIP-NEXT: Binding: Global
+#STRIP-NEXT: Type: None
+#STRIP-NEXT: Other: 0
+#STRIP-NEXT: Section: .debugfoo
+#STRIP-NEXT: }
#STRIP-NEXT:]
+
+#STRIPDEBUG: Symbols [
+#STRIPDEBUG-NEXT: Symbol {
+#STRIPDEBUG-NEXT: Name:
+#STRIPDEBUG-NEXT: Value: 0x0
+#STRIPDEBUG-NEXT: Size: 0
+#STRIPDEBUG-NEXT: Binding: Local
+#STRIPDEBUG-NEXT: Type: None
+#STRIPDEBUG-NEXT: Other: 0
+#STRIPDEBUG-NEXT: Section: Undefined
+#STRIPDEBUG-NEXT: }
+#STRIPDEBUG-NEXT: Symbol {
+#STRIPDEBUG-NEXT: Name: foo
+#STRIPDEBUG-NEXT: Value: 0x0
+#STRIPDEBUG-NEXT: Size: 0
+#STRIPDEBUG-NEXT: Binding: Local
+#STRIPDEBUG-NEXT: Type: File
+#STRIPDEBUG-NEXT: Other: 0
+#STRIPDEBUG-NEXT: Section: .text
+#STRIPDEBUG-NEXT: }
+#STRIPDEBUG-NEXT: Symbol {
+#STRIPDEBUG-NEXT: Name: bar
+#STRIPDEBUG-NEXT: Value: 0x0
+#STRIPDEBUG-NEXT: Size: 0
+#STRIPDEBUG-NEXT: Binding: Global
+#STRIPDEBUG-NEXT: Type: Function
+#STRIPDEBUG-NEXT: Other: 0
+#STRIPDEBUG-NEXT: Section: .text
+#STRIPDEBUG-NEXT: }
+#STRIPDEBUG-NEXT:]
\ No newline at end of file
diff --git a/llvm/test/tools/llvm-objcopy/ELF/strip-debug.test b/llvm/test/tools/llvm-objcopy/ELF/strip-debug.test
index 711f9d3b6d89..4d7cb173c341 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/strip-debug.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/strip-debug.test
@@ -116,6 +116,8 @@ Symbols:
- Name: debugfoo
Section: .debugfoo
Binding: STB_GLOBAL
+ - Name: filesymbol
+ Type: STT_FILE
# CHECK: SectionHeaderCount: 5
@@ -124,7 +126,7 @@ Symbols:
# CHECK: Name: .strtab
# CHECK: Name: .shstrtab
-# Check that *only* foo is copied and not debugfoo
+# Check that *only* foo is copied and not debugfoo or filesymbol.
# CHECK: Symbols [
# CHECK-NEXT: Symbol {
# CHECK-NEXT: Name:
diff --git a/llvm/tools/llvm-objcopy/CopyConfig.cpp b/llvm/tools/llvm-objcopy/CopyConfig.cpp
index df2fbbb05a8d..ff12e4bd89f3 100644
--- a/llvm/tools/llvm-objcopy/CopyConfig.cpp
+++ b/llvm/tools/llvm-objcopy/CopyConfig.cpp
@@ -667,8 +667,10 @@ parseObjcopyOptions(ArrayRef<const char *> ArgsArr,
Config.KeepFileSymbols = InputArgs.hasArg(OBJCOPY_keep_file_symbols);
Config.DecompressDebugSections =
InputArgs.hasArg(OBJCOPY_decompress_debug_sections);
- if (Config.DiscardMode == DiscardType::All)
+ if (Config.DiscardMode == DiscardType::All) {
Config.StripDebug = true;
+ Config.KeepFileSymbols = true;
+ }
for (auto Arg : InputArgs.filtered(OBJCOPY_localize_symbol))
if (Error E = Config.SymbolsToLocalize.addMatcher(NameOrPattern::create(
Arg->getValue(), SymbolMatchStyle, ErrorCallback)))
@@ -938,8 +940,10 @@ parseStripOptions(ArrayRef<const char *> ArgsArr,
!Config.StripAllGNU && Config.SymbolsToRemove.empty())
Config.StripAll = true;
- if (Config.DiscardMode == DiscardType::All)
+ if (Config.DiscardMode == DiscardType::All) {
Config.StripDebug = true;
+ Config.KeepFileSymbols = true;
+ }
Config.DeterministicArchives =
InputArgs.hasFlag(STRIP_enable_deterministic_archives,
diff --git a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
index d12eff718f5b..c1d8c1fa979c 100644
--- a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
+++ b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
@@ -420,6 +420,9 @@ static Error updateAndRemoveSymbols(const CopyConfig &Config, Object &Obj) {
if (Config.StripAll || Config.StripAllGNU)
return true;
+ if (Config.StripDebug && Sym.Type == STT_FILE)
+ return true;
+
if (Config.SymbolsToRemove.matches(Sym.Name))
return true;
More information about the llvm-commits
mailing list