llvm.org GIT mirror llvm / fecfc2b
[llvm-objcopy] [COFF] Fix writing object files without symbols/string table Previously, this was broken - by setting PointerToSymbolTable to zero but still actually writing the string table length, the object file header was corrupted. Differential Revision: https://reviews.llvm.org/D56584 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350926 91177308-0d34-0410-b5e6-96231b3b80d8 Martin Storsjo 7 months ago
3 changed file(s) with 21 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
0 --- !COFF
1 header:
2 Machine: IMAGE_FILE_MACHINE_AMD64
3 Characteristics: [ ]
4 sections:
5 - Name: .text
6 Characteristics: [ ]
7 Alignment: 4
8 SectionData: E800000000C3C3C3
9 symbols:
10 ...
3939 RUN: obj2yaml %t.x86_64.exe > %t.x86_64.exe.yaml
4040 RUN: obj2yaml %t.x86_64-copy.exe > %t.x86_64-copy.exe.yaml
4141 RUN: cmp %t.x86_64.exe.yaml %t.x86_64-copy.exe.yaml
42
43 RUN: yaml2obj %p/Inputs/no-symbols.yaml > %t.no-symbols.o
44 RUN: llvm-objcopy %t.no-symbols.o %t.no-symbols-copy.o
45 RUN: obj2yaml %t.no-symbols.o > %t.no-symbols.o.yaml
46 RUN: obj2yaml %t.no-symbols-copy.o > %t.no-symbols-copy.o.yaml
47 RUN: cmp %t.no-symbols.o.yaml %t.no-symbols-copy.o.yaml
153153 size_t PointerToSymbolTable = FileSize;
154154 // StrTabSize <= 4 is the size of an empty string table, only consisting
155155 // of the length field.
156 if (SymTabSize == 0 && StrTabSize <= 4) {
157 // Don't point to the symbol table if empty.
156 if (SymTabSize == 0 && StrTabSize <= 4 && Obj.IsPE) {
157 // For executables, don't point to the symbol table and skip writing
158 // the length field, if both the symbol and string tables are empty.
158159 PointerToSymbolTable = 0;
159 // For executables, skip the length field of an empty string table.
160 if (Obj.IsPE)
161 StrTabSize = 0;
160 StrTabSize = 0;
162161 }
163162
164163 size_t NumRawSymbols = SymTabSize / SymbolSize;