llvm.org GIT mirror llvm / 7c395d1
[llvm-objcopy] [COFF] Remove unreferenced undefined externals with --strip-unneeded. Differential Revision: https://reviews.llvm.org/D56660 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351099 91177308-0d34-0410-b5e6-96231b3b80d8 Martin Storsjo 7 months ago
4 changed file(s) with 21 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
55 - Name: .text
66 Characteristics: [ ]
77 Alignment: 4
8 SectionData: E800000000C3C3C3
8 SectionData: E800000000E800000000C3C3C3
99 Relocations:
1010 - VirtualAddress: 1
1111 SymbolName: local_referenced
12 Type: IMAGE_REL_AMD64_REL32
13 - VirtualAddress: 5
14 SymbolName: external_undefined
1215 Type: IMAGE_REL_AMD64_REL32
1316 symbols:
1417 - Name: external
1821 ComplexType: IMAGE_SYM_DTYPE_NULL
1922 StorageClass: IMAGE_SYM_CLASS_EXTERNAL
2023 - Name: external_undefined
24 Value: 0
25 SectionNumber: 0
26 SimpleType: IMAGE_SYM_TYPE_NULL
27 ComplexType: IMAGE_SYM_DTYPE_NULL
28 StorageClass: IMAGE_SYM_CLASS_EXTERNAL
29 - Name: external_undefined_unreferenced
2130 Value: 0
2231 SectionNumber: 0
2332 SimpleType: IMAGE_SYM_TYPE_NULL
1818 SYMBOLS: SYMBOL TABLE:
1919 SYMBOLS-NEXT: external
2020 SYMBOLS-NEXT: external_undefined
21 SYMBOLS-NEXT: external_undefined_unreferenced
2122 SYMBOLS-PRE-NEXT: local_unreferenced
2223 SYMBOLS-NEXT: local_referenced
2324 SYMBOLS-NEXT: local_undefined_unreferenced
77 SYMBOLS: SYMBOL TABLE:
88 SYMBOLS-NEXT: external
99 SYMBOLS-NEXT: external_undefined
10 SYMBOLS-PRE-NEXT: external_undefined_unreferenced
1011 SYMBOLS-PRE-NEXT: local_unreferenced
1112 SYMBOLS-NEXT: local_referenced
1213 SYMBOLS-PRE-NEXT: local_undefined_unreferenced
4646 return true;
4747 }
4848
49 if (!Sym.Referenced && Sym.Sym.StorageClass == IMAGE_SYM_CLASS_STATIC) {
50 if (Config.StripUnneeded)
49 if (!Sym.Referenced) {
50 // With --strip-unneeded, GNU objcopy removes all unreferenced local
51 // symbols, and any unreferenced undefined external.
52 if (Config.StripUnneeded &&
53 (Sym.Sym.StorageClass == IMAGE_SYM_CLASS_STATIC ||
54 Sym.Sym.SectionNumber == 0))
5155 return true;
56
5257 // GNU objcopy keeps referenced local symbols and external symbols
5358 // if --discard-all is set, similar to what --strip-unneeded does,
5459 // but undefined local symbols are kept when --discard-all is set.
55 if (Config.DiscardAll && Sym.Sym.SectionNumber != 0)
60 if (Config.DiscardAll && Sym.Sym.StorageClass == IMAGE_SYM_CLASS_STATIC &&
61 Sym.Sym.SectionNumber != 0)
5662 return true;
5763 }
5864