[llvm] r351099 - [llvm-objcopy] [COFF] Remove unreferenced undefined externals with --strip-unneeded.
Martin Storsjo via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 14 10:56:48 PST 2019
Author: mstorsjo
Date: Mon Jan 14 10:56:47 2019
New Revision: 351099
URL: http://llvm.org/viewvc/llvm-project?rev=351099&view=rev
Log:
[llvm-objcopy] [COFF] Remove unreferenced undefined externals with --strip-unneeded.
Differential Revision: https://reviews.llvm.org/D56660
Modified:
llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/discard-locals.yaml
llvm/trunk/test/tools/llvm-objcopy/COFF/discard-all.test
llvm/trunk/test/tools/llvm-objcopy/COFF/strip-unneeded.test
llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
Modified: llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/discard-locals.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/discard-locals.yaml?rev=351099&r1=351098&r2=351099&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/discard-locals.yaml (original)
+++ llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/discard-locals.yaml Mon Jan 14 10:56:47 2019
@@ -6,11 +6,14 @@ sections:
- Name: .text
Characteristics: [ ]
Alignment: 4
- SectionData: E800000000C3C3C3
+ SectionData: E800000000E800000000C3C3C3
Relocations:
- VirtualAddress: 1
SymbolName: local_referenced
Type: IMAGE_REL_AMD64_REL32
+ - VirtualAddress: 5
+ SymbolName: external_undefined
+ Type: IMAGE_REL_AMD64_REL32
symbols:
- Name: external
Value: 0
@@ -22,6 +25,12 @@ symbols:
Value: 0
SectionNumber: 0
SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: external_undefined_unreferenced
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
- Name: local_unreferenced
Modified: llvm/trunk/test/tools/llvm-objcopy/COFF/discard-all.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/COFF/discard-all.test?rev=351099&r1=351098&r2=351099&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/COFF/discard-all.test (original)
+++ llvm/trunk/test/tools/llvm-objcopy/COFF/discard-all.test Mon Jan 14 10:56:47 2019
@@ -19,6 +19,7 @@ RUN: cmp %t.out.o %t.strip-discard-all.o
SYMBOLS: SYMBOL TABLE:
SYMBOLS-NEXT: external
SYMBOLS-NEXT: external_undefined
+SYMBOLS-NEXT: external_undefined_unreferenced
SYMBOLS-PRE-NEXT: local_unreferenced
SYMBOLS-NEXT: local_referenced
SYMBOLS-NEXT: local_undefined_unreferenced
Modified: llvm/trunk/test/tools/llvm-objcopy/COFF/strip-unneeded.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/COFF/strip-unneeded.test?rev=351099&r1=351098&r2=351099&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/COFF/strip-unneeded.test (original)
+++ llvm/trunk/test/tools/llvm-objcopy/COFF/strip-unneeded.test Mon Jan 14 10:56:47 2019
@@ -8,6 +8,7 @@ RUN: llvm-objdump -t %t.out.o | FileChec
SYMBOLS: SYMBOL TABLE:
SYMBOLS-NEXT: external
SYMBOLS-NEXT: external_undefined
+SYMBOLS-PRE-NEXT: external_undefined_unreferenced
SYMBOLS-PRE-NEXT: local_unreferenced
SYMBOLS-NEXT: local_referenced
SYMBOLS-PRE-NEXT: local_undefined_unreferenced
Modified: llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp?rev=351099&r1=351098&r2=351099&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp Mon Jan 14 10:56:47 2019
@@ -47,13 +47,19 @@ static Error handleArgs(const CopyConfig
return true;
}
- if (!Sym.Referenced && Sym.Sym.StorageClass == IMAGE_SYM_CLASS_STATIC) {
- if (Config.StripUnneeded)
+ if (!Sym.Referenced) {
+ // With --strip-unneeded, GNU objcopy removes all unreferenced local
+ // symbols, and any unreferenced undefined external.
+ if (Config.StripUnneeded &&
+ (Sym.Sym.StorageClass == IMAGE_SYM_CLASS_STATIC ||
+ Sym.Sym.SectionNumber == 0))
return true;
+
// GNU objcopy keeps referenced local symbols and external symbols
// if --discard-all is set, similar to what --strip-unneeded does,
// but undefined local symbols are kept when --discard-all is set.
- if (Config.DiscardAll && Sym.Sym.SectionNumber != 0)
+ if (Config.DiscardAll && Sym.Sym.StorageClass == IMAGE_SYM_CLASS_STATIC &&
+ Sym.Sym.SectionNumber != 0)
return true;
}
More information about the llvm-commits
mailing list