llvm.org GIT mirror llvm / 33c1aca
[llvm-objcopy] [COFF] Implement --strip-all[-gnu] for symbols Differential Revision: https://reviews.llvm.org/D56481 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351174 91177308-0d34-0410-b5e6-96231b3b80d8 Martin Storsjo 7 months ago
3 changed file(s) with 68 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
0 # RUN: yaml2obj %s > %t.in.o
1
2 # RUN: llvm-objdump -t %t.in.o | FileCheck %s --check-prefixes=SYMBOLS,SYMBOLS-PRE
3
4 # RUN: llvm-objcopy --strip-all %t.in.o %t.out.o
5 # RUN: llvm-objdump -t %t.out.o | FileCheck %s --check-prefix=SYMBOLS
6 # RUN: llvm-readobj -relocs %t.out.o | FileCheck %s --check-prefix=RELOCS
7
8 # Test that -S, llvm-strip without arguments and --strip-all-gnu produces
9 # output identical to --strip-all above.
10 # RUN: llvm-objcopy -S %t.in.o %t.out-short.o
11 # RUN: cmp %t.out.o %t.out-short.o
12
13 # RUN: cp %t.in.o %t.out-strip.o
14 # RUN: llvm-strip %t.out-strip.o
15 # RUN: cmp %t.out.o %t.out-strip.o
16
17 # RUN: llvm-objcopy --strip-all-gnu %t.in.o %t.out-gnu.o
18 # RUN: cmp %t.out.o %t.out-gnu.o
19
20 # SYMBOLS: SYMBOL TABLE:
21 # SYMBOLS-PRE-NEXT: external
22 # SYMBOLS-PRE-NEXT: external_undefined
23 # SYMBOLS-EMPTY:
24
25 # RELOCS: Relocations [
26 # RELOCS-NEXT: ]
27
28 --- !COFF
29 header:
30 Machine: IMAGE_FILE_MACHINE_AMD64
31 Characteristics: [ ]
32 sections:
33 - Name: .text
34 Characteristics: [ ]
35 Alignment: 4
36 SectionData: 488B0500000000C3
37 Relocations:
38 - VirtualAddress: 3
39 SymbolName: external_undefined
40 Type: IMAGE_REL_AMD64_REL32
41 symbols:
42 - Name: external
43 Value: 0
44 SectionNumber: 1
45 SimpleType: IMAGE_SYM_TYPE_NULL
46 ComplexType: IMAGE_SYM_DTYPE_NULL
47 StorageClass: IMAGE_SYM_CLASS_EXTERNAL
48 - Name: external_undefined
49 Value: 0
50 SectionNumber: 0
51 SimpleType: IMAGE_SYM_TYPE_NULL
52 ComplexType: IMAGE_SYM_DTYPE_NULL
53 StorageClass: IMAGE_SYM_CLASS_EXTERNAL
54 ...
2727 using namespace COFF;
2828
2929 static Error handleArgs(const CopyConfig &Config, Object &Obj) {
30 // StripAll removes all symbols and thus also removes all relocations.
31 if (Config.StripAll || Config.StripAllGNU)
32 for (Section &Sec : Obj.Sections)
33 Sec.Relocs.clear();
34
3035 // If we need to do per-symbol removals, initialize the Referenced field.
3136 if (Config.StripUnneeded || Config.DiscardAll ||
3237 !Config.SymbolsToRemove.empty())
3540
3641 // Actually do removals of symbols.
3742 Obj.removeSymbols([&](const Symbol &Sym) {
43 // For StripAll, all relocations have been stripped and we remove all
44 // symbols.
45 if (Config.StripAll || Config.StripAllGNU)
46 return true;
47
3848 if (is_contained(Config.SymbolsToRemove, Sym.Name)) {
3949 // Explicitly removing a referenced symbol is an error.
4050 if (Sym.Referenced)
4545 S.Header.PointerToRawData = FileSize;
4646 FileSize += S.Header.SizeOfRawData; // For executables, this is already
4747 // aligned to FileAlignment.
48 if (S.Header.NumberOfRelocations > 0)
49 S.Header.PointerToRelocations = FileSize;
48 S.Header.NumberOfRelocations = S.Relocs.size();
49 S.Header.PointerToRelocations =
50 S.Header.NumberOfRelocations > 0 ? FileSize : 0;
5051 FileSize += S.Relocs.size() * sizeof(coff_relocation);
5152 FileSize = alignTo(FileSize, FileAlignment);
5253