[llvm] r350926 - [llvm-objcopy] [COFF] Fix writing object files without symbols/string table
Martin Storsjo via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 11 05:47:37 PST 2019
Author: mstorsjo
Date: Fri Jan 11 05:47:37 2019
New Revision: 350926
URL: http://llvm.org/viewvc/llvm-project?rev=350926&view=rev
Log:
[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
Added:
llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/no-symbols.yaml
Modified:
llvm/trunk/test/tools/llvm-objcopy/COFF/basic-copy.test
llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp
Added: llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/no-symbols.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/no-symbols.yaml?rev=350926&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/no-symbols.yaml (added)
+++ llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/no-symbols.yaml Fri Jan 11 05:47:37 2019
@@ -0,0 +1,11 @@
+--- !COFF
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: [ ]
+sections:
+ - Name: .text
+ Characteristics: [ ]
+ Alignment: 4
+ SectionData: E800000000C3C3C3
+symbols:
+...
Modified: llvm/trunk/test/tools/llvm-objcopy/COFF/basic-copy.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/COFF/basic-copy.test?rev=350926&r1=350925&r2=350926&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/COFF/basic-copy.test (original)
+++ llvm/trunk/test/tools/llvm-objcopy/COFF/basic-copy.test Fri Jan 11 05:47:37 2019
@@ -40,3 +40,9 @@ RUN: llvm-objcopy %t.x86_64.exe %t.x86_6
RUN: obj2yaml %t.x86_64.exe > %t.x86_64.exe.yaml
RUN: obj2yaml %t.x86_64-copy.exe > %t.x86_64-copy.exe.yaml
RUN: cmp %t.x86_64.exe.yaml %t.x86_64-copy.exe.yaml
+
+RUN: yaml2obj %p/Inputs/no-symbols.yaml > %t.no-symbols.o
+RUN: llvm-objcopy %t.no-symbols.o %t.no-symbols-copy.o
+RUN: obj2yaml %t.no-symbols.o > %t.no-symbols.o.yaml
+RUN: obj2yaml %t.no-symbols-copy.o > %t.no-symbols-copy.o.yaml
+RUN: cmp %t.no-symbols.o.yaml %t.no-symbols-copy.o.yaml
Modified: llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp?rev=350926&r1=350925&r2=350926&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp Fri Jan 11 05:47:37 2019
@@ -154,12 +154,11 @@ Error COFFWriter::finalize(bool IsBigObj
size_t PointerToSymbolTable = FileSize;
// StrTabSize <= 4 is the size of an empty string table, only consisting
// of the length field.
- if (SymTabSize == 0 && StrTabSize <= 4) {
- // Don't point to the symbol table if empty.
+ if (SymTabSize == 0 && StrTabSize <= 4 && Obj.IsPE) {
+ // For executables, don't point to the symbol table and skip writing
+ // the length field, if both the symbol and string tables are empty.
PointerToSymbolTable = 0;
- // For executables, skip the length field of an empty string table.
- if (Obj.IsPE)
- StrTabSize = 0;
+ StrTabSize = 0;
}
size_t NumRawSymbols = SymTabSize / SymbolSize;
More information about the llvm-commits
mailing list