[PATCH] D56660: [llvm-objcopy] [COFF] Remove unreferenced undefined externals with --strip-unneeded.
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 14 05:03:31 PST 2019
mstorsjo created this revision.
mstorsjo added reviewers: jhenderson, alexshap, rupprecht, jakehehrlich, rnk.
Unreferenced undefined external symbols are removed by --strip-unneeded, but not by --discard-all.
Repository:
rL LLVM
https://reviews.llvm.org/D56660
Files:
test/tools/llvm-objcopy/COFF/Inputs/discard-locals.yaml
test/tools/llvm-objcopy/COFF/discard-all.test
test/tools/llvm-objcopy/COFF/strip-unneeded.test
tools/llvm-objcopy/COFF/COFFObjcopy.cpp
Index: tools/llvm-objcopy/COFF/COFFObjcopy.cpp
===================================================================
--- tools/llvm-objcopy/COFF/COFFObjcopy.cpp
+++ tools/llvm-objcopy/COFF/COFFObjcopy.cpp
@@ -47,13 +47,19 @@
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;
}
Index: test/tools/llvm-objcopy/COFF/strip-unneeded.test
===================================================================
--- test/tools/llvm-objcopy/COFF/strip-unneeded.test
+++ test/tools/llvm-objcopy/COFF/strip-unneeded.test
@@ -8,6 +8,7 @@
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
Index: test/tools/llvm-objcopy/COFF/discard-all.test
===================================================================
--- test/tools/llvm-objcopy/COFF/discard-all.test
+++ test/tools/llvm-objcopy/COFF/discard-all.test
@@ -19,6 +19,7 @@
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
Index: test/tools/llvm-objcopy/COFF/Inputs/discard-locals.yaml
===================================================================
--- test/tools/llvm-objcopy/COFF/Inputs/discard-locals.yaml
+++ test/tools/llvm-objcopy/COFF/Inputs/discard-locals.yaml
@@ -6,11 +6,14 @@
- 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
@@ -24,6 +27,12 @@
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
Value: 6
SectionNumber: 1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56660.181537.patch
Type: text/x-patch
Size: 3349 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190114/982da146/attachment.bin>
More information about the llvm-commits
mailing list