<div dir="ltr"><div dir="ltr">Hi, <div><br></div><div>ubsan seems to be unhappy with this change, please fix ASAP </div><div><br></div><div><a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/27463/steps/check-llvm%20ubsan/logs/stdio">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/27463/steps/check-llvm%20ubsan/logs/stdio</a><br></div><div><pre style="font-family:"Courier New",courier,monotype,monospace;color:rgb(0,0,0);font-size:medium"><span class="gmail-stdout">b/sanitizer-x86_64-linux-fast/build/llvm/tools/llvm-objcopy/COFF/Writer.cpp:228:17: runtime error: null pointer passed as argument 2, which is declared to never be null
/usr/include/string.h:43:28: note: nonnull attribute specified here
#0 0x436e89 in llvm::objcopy::coff::COFFWriter::writeSections() /b/sanitizer-x86_64-linux-fast/build/llvm/tools/llvm-objcopy/COFF/Writer.cpp:228:5
#1 0x436f2a in llvm::objcopy::coff::COFFWriter::write(bool) /b/sanitizer-x86_64-linux-fast/build/llvm/tools/llvm-objcopy/COFF/Writer.cpp:255:3
#2 0x432664 in llvm::objcopy::coff::executeObjcopyOnBinary(llvm::objcopy::CopyConfig const&, llvm::object::COFFObjectFile&, llvm::objcopy::Buffer&) /b/sanitizer-x86_64-linux-fast/build/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp:35:10
#3 0x42ef45 in executeObjcopy /b/sanitizer-x86_64-linux-fast/build/llvm/tools/llvm-objcopy/llvm-objcopy.cpp:211:7
#4 0x42ef45 in main /b/sanitizer-x86_64-linux-fast/build/llvm/tools/llvm-objcopy/llvm-objcopy.cpp:231
#5 0x7f702c5862e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
#6 0x409c09 in _start (/b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/bin/llvm-objcopy+0x409c09)
--</span></pre></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Dec 18, 2018 at 11:27 PM Martin Storsjo via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: mstorsjo<br>
Date: Tue Dec 18 23:24:38 2018<br>
New Revision: 349605<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=349605&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=349605&view=rev</a><br>
Log:<br>
[llvm-objcopy] Initial COFF support<br>
<br>
This is an initial implementation of no-op passthrough copying of COFF<br>
with objcopy.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D54939" rel="noreferrer" target="_blank">https://reviews.llvm.org/D54939</a><br>
<br>
Added:<br>
llvm/trunk/test/tools/llvm-objcopy/COFF/<br>
llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/<br>
llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/i386-exe.yaml<br>
llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/i386-obj.yaml<br>
llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/x86_64-exe.yaml<br>
llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/x86_64-obj.yaml<br>
llvm/trunk/test/tools/llvm-objcopy/COFF/basic-copy.test<br>
llvm/trunk/tools/llvm-objcopy/COFF/<br>
llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp<br>
llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.h<br>
llvm/trunk/tools/llvm-objcopy/COFF/Object.h<br>
llvm/trunk/tools/llvm-objcopy/COFF/Reader.cpp<br>
llvm/trunk/tools/llvm-objcopy/COFF/Reader.h<br>
llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp<br>
llvm/trunk/tools/llvm-objcopy/COFF/Writer.h<br>
Modified:<br>
llvm/trunk/include/llvm/Object/COFF.h<br>
llvm/trunk/lib/Object/COFFObjectFile.cpp<br>
llvm/trunk/tools/llvm-objcopy/CMakeLists.txt<br>
llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/Object/COFF.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=349605&r1=349604&r2=349605&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=349605&r1=349604&r2=349605&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Object/COFF.h (original)<br>
+++ llvm/trunk/include/llvm/Object/COFF.h Tue Dec 18 23:24:38 2018<br>
@@ -971,6 +971,9 @@ public:<br>
return nullptr;<br>
return reinterpret_cast<const dos_header *>(base());<br>
}<br>
+ std::error_code getCOFFHeader(const coff_file_header *&Res) const;<br>
+ std::error_code<br>
+ getCOFFBigObjHeader(const coff_bigobj_file_header *&Res) const;<br>
std::error_code getPE32Header(const pe32_header *&Res) const;<br>
std::error_code getPE32PlusHeader(const pe32plus_header *&Res) const;<br>
std::error_code getDataDirectory(uint32_t index,<br>
<br>
Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=349605&r1=349604&r2=349605&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=349605&r1=349604&r2=349605&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)<br>
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Tue Dec 18 23:24:38 2018<br>
@@ -938,6 +938,18 @@ iterator_range<base_reloc_iterator> COFF<br>
return make_range(base_reloc_begin(), base_reloc_end());<br>
}<br>
<br>
+std::error_code<br>
+COFFObjectFile::getCOFFHeader(const coff_file_header *&Res) const {<br>
+ Res = COFFHeader;<br>
+ return std::error_code();<br>
+}<br>
+<br>
+std::error_code<br>
+COFFObjectFile::getCOFFBigObjHeader(const coff_bigobj_file_header *&Res) const {<br>
+ Res = COFFBigObjHeader;<br>
+ return std::error_code();<br>
+}<br>
+<br>
std::error_code COFFObjectFile::getPE32Header(const pe32_header *&Res) const {<br>
Res = PE32Header;<br>
return std::error_code();<br>
<br>
Added: llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/i386-exe.yaml<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/i386-exe.yaml?rev=349605&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/i386-exe.yaml?rev=349605&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/i386-exe.yaml (added)<br>
+++ llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/i386-exe.yaml Tue Dec 18 23:24:38 2018<br>
@@ -0,0 +1,84 @@<br>
+--- !COFF<br>
+OptionalHeader: <br>
+ AddressOfEntryPoint: 4144<br>
+ ImageBase: 4194304<br>
+ SectionAlignment: 4096<br>
+ FileAlignment: 512<br>
+ MajorOperatingSystemVersion: 6<br>
+ MinorOperatingSystemVersion: 0<br>
+ MajorImageVersion: 0<br>
+ MinorImageVersion: 0<br>
+ MajorSubsystemVersion: 6<br>
+ MinorSubsystemVersion: 0<br>
+ Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI<br>
+ DLLCharacteristics: [ IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE, IMAGE_DLL_CHARACTERISTICS_NX_COMPAT, IMAGE_DLL_CHARACTERISTICS_NO_SEH, IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE ]<br>
+ SizeOfStackReserve: 1048576<br>
+ SizeOfStackCommit: 4096<br>
+ SizeOfHeapReserve: 1048576<br>
+ SizeOfHeapCommit: 4096<br>
+ ExportTable: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ ImportTable: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ ResourceTable: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ ExceptionTable: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ CertificateTable: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ BaseRelocationTable: <br>
+ RelativeVirtualAddress: 12288<br>
+ Size: 12<br>
+ Debug: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ Architecture: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ GlobalPtr: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ TlsTable: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ LoadConfigTable: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ BoundImport: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ IAT: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ DelayImportDescriptor: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ ClrRuntimeHeader: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+header: <br>
+ Machine: IMAGE_FILE_MACHINE_I386<br>
+ Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_32BIT_MACHINE ]<br>
+sections: <br>
+ - Name: .text<br>
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]<br>
+ VirtualAddress: 4096<br>
+ VirtualSize: 83<br>
+ SectionData: 5589E5508B45088B0D00204000034D088945FC89C883C4045DC3660F1F4400005589E55DC3662E0F1F840000000000905589E583EC08E8E5FFFFFFC745FC00000000C7042402000000E8B2FFFFFF83C4085DC3<br>
+ - Name: .data<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]<br>
+ VirtualAddress: 8192<br>
+ VirtualSize: 4<br>
+ SectionData: '01000000'<br>
+ - Name: .reloc<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]<br>
+ VirtualAddress: 12288<br>
+ VirtualSize: 12<br>
+ SectionData: 001000000C00000009300000<br>
+symbols: []<br>
+...<br>
<br>
Added: llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/i386-obj.yaml<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/i386-obj.yaml?rev=349605&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/i386-obj.yaml?rev=349605&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/i386-obj.yaml (added)<br>
+++ llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/i386-obj.yaml Tue Dec 18 23:24:38 2018<br>
@@ -0,0 +1,244 @@<br>
+--- !COFF<br>
+header: <br>
+ Machine: IMAGE_FILE_MACHINE_I386<br>
+ Characteristics: [ ]<br>
+sections: <br>
+ - Name: .text<br>
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]<br>
+ Alignment: 16<br>
+ SectionData: 5589E5508B45088B0D00000000034D088945FC89C883C4045DC3660F1F4400005589E55DC3662E0F1F840000000000905589E583EC08E800000000C745FC00000000C7042402000000E80000000083C4085DC3<br>
+ Relocations: <br>
+ - VirtualAddress: 9<br>
+ SymbolName: _x<br>
+ Type: IMAGE_REL_I386_DIR32<br>
+ - VirtualAddress: 55<br>
+ SymbolName: ___main<br>
+ Type: IMAGE_REL_I386_REL32<br>
+ - VirtualAddress: 74<br>
+ SymbolName: _f<br>
+ Type: IMAGE_REL_I386_REL32<br>
+ - Name: .data<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]<br>
+ Alignment: 4<br>
+ SectionData: '01000000'<br>
+ - Name: .bss<br>
+ Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]<br>
+ Alignment: 4<br>
+ SectionData: ''<br>
+ - Name: .debug_str<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]<br>
+ Alignment: 1<br>
+ SectionData: 636C616E672076657273696F6E20382E302E3020287472756E6B203334363337382920286C6C766D2F7472756E6B203334363339302900736F757263652E63002F686F6D652F6D617274696E2F636F64652F6C6C766D2F6275696C642F6F626A636F70792D696E707574007800696E740066005F5F6D61696E006D61696E007900<br>
+ - Name: .debug_abbrev<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]<br>
+ Alignment: 1<br>
+ SectionData: 011101250E1305030E10171B0E110112060000023400030E49133A0B3B0B02180000032400030E3E0B0B0B0000042E01110112064018030E3A0B3B0B271949133F1900000505000218030E3A0B3B0B49130000062E00110112064018030E3A0B3B0B27193F190000072E00110112064018030E3A0B3B0B49133F19000000<br>
+ - Name: .debug_info<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]<br>
+ Alignment: 1<br>
+ SectionData: 850000000400000000000401000000000C003700000000000000400000000000000053000000026B000000370000000101050300000000036D000000050404000000001A000000015571000000010337000000050291087F00000001033700000000062000000005000000015573000000010707300000002300000001557A00000001093700000000<br>
+ Relocations: <br>
+ - VirtualAddress: 6<br>
+ SymbolName: .debug_abbrev<br>
+ Type: IMAGE_REL_I386_SECREL<br>
+ - VirtualAddress: 12<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_I386_SECREL<br>
+ - VirtualAddress: 18<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_I386_SECREL<br>
+ - VirtualAddress: 22<br>
+ SymbolName: .debug_line<br>
+ Type: IMAGE_REL_I386_SECREL<br>
+ - VirtualAddress: 26<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_I386_SECREL<br>
+ - VirtualAddress: 30<br>
+ SymbolName: .text<br>
+ Type: IMAGE_REL_I386_DIR32<br>
+ - VirtualAddress: 39<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_I386_SECREL<br>
+ - VirtualAddress: 51<br>
+ SymbolName: _x<br>
+ Type: IMAGE_REL_I386_DIR32<br>
+ - VirtualAddress: 56<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_I386_SECREL<br>
+ - VirtualAddress: 63<br>
+ SymbolName: .text<br>
+ Type: IMAGE_REL_I386_DIR32<br>
+ - VirtualAddress: 73<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_I386_SECREL<br>
+ - VirtualAddress: 87<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_I386_SECREL<br>
+ - VirtualAddress: 99<br>
+ SymbolName: .text<br>
+ Type: IMAGE_REL_I386_DIR32<br>
+ - VirtualAddress: 109<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_I386_SECREL<br>
+ - VirtualAddress: 116<br>
+ SymbolName: .text<br>
+ Type: IMAGE_REL_I386_DIR32<br>
+ - VirtualAddress: 126<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_I386_SECREL<br>
+ - Name: .debug_macinfo<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]<br>
+ Alignment: 1<br>
+ SectionData: '00'<br>
+ - Name: .debug_line<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]<br>
+ Alignment: 1<br>
+ SectionData: 52000000040020000000010101FB0E0D00010101010000000100000100736F757263652E6300000000000005020000000014050A0A75050C0666050366050006CB05010A3D0500C9050A0A0821050306BA0205000101<br>
+ Relocations: <br>
+ - VirtualAddress: 45<br>
+ SymbolName: .text<br>
+ Type: IMAGE_REL_I386_DIR32<br>
+ - Name: .llvm_addrsig<br>
+ Characteristics: [ IMAGE_SCN_LNK_REMOVE ]<br>
+ Alignment: 1<br>
+ SectionData: '1314'<br>
+symbols: <br>
+ - Name: .text<br>
+ Value: 0<br>
+ SectionNumber: 1<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 83<br>
+ NumberOfRelocations: 3<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 4183332250<br>
+ Number: 1<br>
+ - Name: .data<br>
+ Value: 0<br>
+ SectionNumber: 2<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 4<br>
+ NumberOfRelocations: 0<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 3099354981<br>
+ Number: 2<br>
+ - Name: .bss<br>
+ Value: 0<br>
+ SectionNumber: 3<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 0<br>
+ NumberOfRelocations: 0<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 0<br>
+ Number: 3<br>
+ - Name: .debug_str<br>
+ Value: 0<br>
+ SectionNumber: 4<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 129<br>
+ NumberOfRelocations: 0<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 2876129505<br>
+ Number: 4<br>
+ - Name: .debug_abbrev<br>
+ Value: 0<br>
+ SectionNumber: 5<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 126<br>
+ NumberOfRelocations: 0<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 2218663305<br>
+ Number: 5<br>
+ - Name: .debug_info<br>
+ Value: 0<br>
+ SectionNumber: 6<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 137<br>
+ NumberOfRelocations: 16<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 2577207131<br>
+ Number: 6<br>
+ - Name: .debug_macinfo<br>
+ Value: 0<br>
+ SectionNumber: 7<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 1<br>
+ NumberOfRelocations: 0<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 0<br>
+ Number: 7<br>
+ - Name: .debug_line<br>
+ Value: 0<br>
+ SectionNumber: 8<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 86<br>
+ NumberOfRelocations: 1<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 2357396799<br>
+ Number: 8<br>
+ - Name: .llvm_addrsig<br>
+ Value: 0<br>
+ SectionNumber: 9<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 2<br>
+ NumberOfRelocations: 0<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 2067109359<br>
+ Number: 9<br>
+ - Name: '@feat.00'<br>
+ Value: 1<br>
+ SectionNumber: -1<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ - Name: _f<br>
+ Value: 0<br>
+ SectionNumber: 1<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION<br>
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL<br>
+ - Name: _x<br>
+ Value: 0<br>
+ SectionNumber: 2<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ - Name: ___main<br>
+ Value: 32<br>
+ SectionNumber: 1<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION<br>
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL<br>
+ - Name: _main<br>
+ Value: 48<br>
+ SectionNumber: 1<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION<br>
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL<br>
+...<br>
<br>
Added: llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/x86_64-exe.yaml<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/x86_64-exe.yaml?rev=349605&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/x86_64-exe.yaml?rev=349605&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/x86_64-exe.yaml (added)<br>
+++ llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/x86_64-exe.yaml Tue Dec 18 23:24:38 2018<br>
@@ -0,0 +1,89 @@<br>
+--- !COFF<br>
+OptionalHeader: <br>
+ AddressOfEntryPoint: 4144<br>
+ ImageBase: 1073741824<br>
+ SectionAlignment: 4096<br>
+ FileAlignment: 512<br>
+ MajorOperatingSystemVersion: 6<br>
+ MinorOperatingSystemVersion: 0<br>
+ MajorImageVersion: 0<br>
+ MinorImageVersion: 0<br>
+ MajorSubsystemVersion: 6<br>
+ MinorSubsystemVersion: 0<br>
+ Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI<br>
+ DLLCharacteristics: [ IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA, IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE, IMAGE_DLL_CHARACTERISTICS_NX_COMPAT, IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE ]<br>
+ SizeOfStackReserve: 1048576<br>
+ SizeOfStackCommit: 4096<br>
+ SizeOfHeapReserve: 1048576<br>
+ SizeOfHeapCommit: 4096<br>
+ ExportTable: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ ImportTable: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ ResourceTable: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ ExceptionTable: <br>
+ RelativeVirtualAddress: 16384<br>
+ Size: 24<br>
+ CertificateTable: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ BaseRelocationTable: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ Debug: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ Architecture: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ GlobalPtr: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ TlsTable: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ LoadConfigTable: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ BoundImport: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ IAT: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ DelayImportDescriptor: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+ ClrRuntimeHeader: <br>
+ RelativeVirtualAddress: 0<br>
+ Size: 0<br>
+header: <br>
+ Machine: IMAGE_FILE_MACHINE_AMD64<br>
+ Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE ]<br>
+sections: <br>
+ - Name: .text<br>
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]<br>
+ VirtualAddress: 4096<br>
+ VirtualSize: 87<br>
+ SectionData: 50894C24048B0DF51F0000034C240489C859C3662E0F1F8400000000000F1F00C3662E0F1F8400000000000F1F440000554883EC30488D6C2430E8E1FFFFFFC745FC00000000B902000000E8B0FFFFFF904883C4305DC3<br>
+ - Name: .rdata<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]<br>
+ VirtualAddress: 8192<br>
+ VirtualSize: 20<br>
+ SectionData: 0101010001020000010A03350A03055201500000<br>
+ - Name: .data<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]<br>
+ VirtualAddress: 12288<br>
+ VirtualSize: 4<br>
+ SectionData: '01000000'<br>
+ - Name: .pdata<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]<br>
+ VirtualAddress: 16384<br>
+ VirtualSize: 24<br>
+ SectionData: '001000001310000000200000301000005710000008200000'<br>
+symbols: []<br>
+...<br>
<br>
Added: llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/x86_64-obj.yaml<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/x86_64-obj.yaml?rev=349605&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/x86_64-obj.yaml?rev=349605&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/x86_64-obj.yaml (added)<br>
+++ llvm/trunk/test/tools/llvm-objcopy/COFF/Inputs/x86_64-obj.yaml Tue Dec 18 23:24:38 2018<br>
@@ -0,0 +1,295 @@<br>
+--- !COFF<br>
+header: <br>
+ Machine: IMAGE_FILE_MACHINE_AMD64<br>
+ Characteristics: [ ]<br>
+sections: <br>
+ - Name: .text<br>
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]<br>
+ Alignment: 16<br>
+ SectionData: 50894C24048B0D00000000034C240489C859C3662E0F1F8400000000000F1F00C3662E0F1F8400000000000F1F440000554883EC30488D6C2430E800000000C745FC00000000B902000000E800000000904883C4305DC3<br>
+ Relocations: <br>
+ - VirtualAddress: 7<br>
+ SymbolName: x<br>
+ Type: IMAGE_REL_AMD64_REL32<br>
+ - VirtualAddress: 59<br>
+ SymbolName: __main<br>
+ Type: IMAGE_REL_AMD64_REL32<br>
+ - VirtualAddress: 76<br>
+ SymbolName: f<br>
+ Type: IMAGE_REL_AMD64_REL32<br>
+ - Name: .data<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]<br>
+ Alignment: 4<br>
+ SectionData: '01000000'<br>
+ - Name: .bss<br>
+ Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]<br>
+ Alignment: 4<br>
+ SectionData: ''<br>
+ - Name: .xdata<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]<br>
+ Alignment: 4<br>
+ SectionData: 0101010001020000010A03350A03055201500000<br>
+ - Name: .debug_str<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]<br>
+ Alignment: 1<br>
+ SectionData: 636C616E672076657273696F6E20382E302E3020287472756E6B203334363337382920286C6C766D2F7472756E6B203334363339302900736F757263652E63002F686F6D652F6D617274696E2F636F64652F6C6C766D2F6275696C642F6F626A636F70792D696E707574007800696E740066005F5F6D61696E006D61696E007900<br>
+ - Name: .debug_abbrev<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]<br>
+ Alignment: 1<br>
+ SectionData: 011101250E1305030E10171B0E110112060000023400030E49133A0B3B0B02180000032400030E3E0B0B0B0000042E01110112064018030E3A0B3B0B271949133F1900000505000218030E3A0B3B0B49130000062E00110112064018030E3A0B3B0B27193F190000072E00110112064018030E3A0B3B0B49133F19000000<br>
+ - Name: .debug_info<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]<br>
+ Alignment: 1<br>
+ SectionData: 990000000400000000000801000000000C00370000000000000040000000000000000000000057000000026B0000003F000000010109030000000000000000036D00000005040400000000000000001300000001577100000001033F000000050291047F00000001033F000000000620000000000000000100000001577300000001070730000000000000002700000001567A00000001093F00000000<br>
+ Relocations: <br>
+ - VirtualAddress: 6<br>
+ SymbolName: .debug_abbrev<br>
+ Type: IMAGE_REL_AMD64_SECREL<br>
+ - VirtualAddress: 12<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_AMD64_SECREL<br>
+ - VirtualAddress: 18<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_AMD64_SECREL<br>
+ - VirtualAddress: 22<br>
+ SymbolName: .debug_line<br>
+ Type: IMAGE_REL_AMD64_SECREL<br>
+ - VirtualAddress: 26<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_AMD64_SECREL<br>
+ - VirtualAddress: 30<br>
+ SymbolName: .text<br>
+ Type: IMAGE_REL_AMD64_ADDR64<br>
+ - VirtualAddress: 43<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_AMD64_SECREL<br>
+ - VirtualAddress: 55<br>
+ SymbolName: x<br>
+ Type: IMAGE_REL_AMD64_ADDR64<br>
+ - VirtualAddress: 64<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_AMD64_SECREL<br>
+ - VirtualAddress: 71<br>
+ SymbolName: .text<br>
+ Type: IMAGE_REL_AMD64_ADDR64<br>
+ - VirtualAddress: 85<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_AMD64_SECREL<br>
+ - VirtualAddress: 99<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_AMD64_SECREL<br>
+ - VirtualAddress: 111<br>
+ SymbolName: .text<br>
+ Type: IMAGE_REL_AMD64_ADDR64<br>
+ - VirtualAddress: 125<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_AMD64_SECREL<br>
+ - VirtualAddress: 132<br>
+ SymbolName: .text<br>
+ Type: IMAGE_REL_AMD64_ADDR64<br>
+ - VirtualAddress: 146<br>
+ SymbolName: .debug_str<br>
+ Type: IMAGE_REL_AMD64_SECREL<br>
+ - Name: .debug_macinfo<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]<br>
+ Alignment: 1<br>
+ SectionData: '00'<br>
+ - Name: .pdata<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]<br>
+ Alignment: 4<br>
+ SectionData: '000000001300000000000000000000002700000008000000'<br>
+ Relocations: <br>
+ - VirtualAddress: 0<br>
+ SymbolName: f<br>
+ Type: IMAGE_REL_AMD64_ADDR32NB<br>
+ - VirtualAddress: 4<br>
+ SymbolName: f<br>
+ Type: IMAGE_REL_AMD64_ADDR32NB<br>
+ - VirtualAddress: 8<br>
+ SymbolName: .xdata<br>
+ Type: IMAGE_REL_AMD64_ADDR32NB<br>
+ - VirtualAddress: 12<br>
+ SymbolName: main<br>
+ Type: IMAGE_REL_AMD64_ADDR32NB<br>
+ - VirtualAddress: 16<br>
+ SymbolName: main<br>
+ Type: IMAGE_REL_AMD64_ADDR32NB<br>
+ - VirtualAddress: 20<br>
+ SymbolName: .xdata<br>
+ Type: IMAGE_REL_AMD64_ADDR32NB<br>
+ - Name: .debug_line<br>
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]<br>
+ Alignment: 1<br>
+ SectionData: 57000000040020000000010101FB0E0D00010101010000000100000100736F757263652E630000000000000902000000000000000014050A0A59050C066605034A050006081505010A130500F3050A0A08590503069E0207000101<br>
+ Relocations: <br>
+ - VirtualAddress: 45<br>
+ SymbolName: .text<br>
+ Type: IMAGE_REL_AMD64_ADDR64<br>
+ - Name: .llvm_addrsig<br>
+ Characteristics: [ IMAGE_SCN_LNK_REMOVE ]<br>
+ Alignment: 1<br>
+ SectionData: '1718'<br>
+symbols: <br>
+ - Name: .text<br>
+ Value: 0<br>
+ SectionNumber: 1<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 87<br>
+ NumberOfRelocations: 3<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 4237828689<br>
+ Number: 1<br>
+ - Name: .data<br>
+ Value: 0<br>
+ SectionNumber: 2<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 4<br>
+ NumberOfRelocations: 0<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 3099354981<br>
+ Number: 2<br>
+ - Name: .bss<br>
+ Value: 0<br>
+ SectionNumber: 3<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 0<br>
+ NumberOfRelocations: 0<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 0<br>
+ Number: 3<br>
+ - Name: .xdata<br>
+ Value: 0<br>
+ SectionNumber: 4<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 20<br>
+ NumberOfRelocations: 0<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 3415491858<br>
+ Number: 4<br>
+ - Name: .debug_str<br>
+ Value: 0<br>
+ SectionNumber: 5<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 129<br>
+ NumberOfRelocations: 0<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 2876129505<br>
+ Number: 5<br>
+ - Name: .debug_abbrev<br>
+ Value: 0<br>
+ SectionNumber: 6<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 126<br>
+ NumberOfRelocations: 0<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 2218663305<br>
+ Number: 6<br>
+ - Name: .debug_info<br>
+ Value: 0<br>
+ SectionNumber: 7<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 157<br>
+ NumberOfRelocations: 16<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 603506744<br>
+ Number: 7<br>
+ - Name: .debug_macinfo<br>
+ Value: 0<br>
+ SectionNumber: 8<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 1<br>
+ NumberOfRelocations: 0<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 0<br>
+ Number: 8<br>
+ - Name: .pdata<br>
+ Value: 0<br>
+ SectionNumber: 9<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 24<br>
+ NumberOfRelocations: 6<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 2036901199<br>
+ Number: 9<br>
+ - Name: .debug_line<br>
+ Value: 0<br>
+ SectionNumber: 10<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 91<br>
+ NumberOfRelocations: 1<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 633454091<br>
+ Number: 10<br>
+ - Name: .llvm_addrsig<br>
+ Value: 0<br>
+ SectionNumber: 11<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ SectionDefinition: <br>
+ Length: 2<br>
+ NumberOfRelocations: 0<br>
+ NumberOfLinenumbers: 0<br>
+ CheckSum: 384769216<br>
+ Number: 11<br>
+ - Name: '@feat.00'<br>
+ Value: 0<br>
+ SectionNumber: -1<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ - Name: f<br>
+ Value: 0<br>
+ SectionNumber: 1<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION<br>
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL<br>
+ - Name: x<br>
+ Value: 0<br>
+ SectionNumber: 2<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_NULL<br>
+ StorageClass: IMAGE_SYM_CLASS_STATIC<br>
+ - Name: __main<br>
+ Value: 32<br>
+ SectionNumber: 1<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION<br>
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL<br>
+ - Name: main<br>
+ Value: 48<br>
+ SectionNumber: 1<br>
+ SimpleType: IMAGE_SYM_TYPE_NULL<br>
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION<br>
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL<br>
+...<br>
<br>
Added: llvm/trunk/test/tools/llvm-objcopy/COFF/basic-copy.test<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/COFF/basic-copy.test?rev=349605&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/COFF/basic-copy.test?rev=349605&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-objcopy/COFF/basic-copy.test (added)<br>
+++ llvm/trunk/test/tools/llvm-objcopy/COFF/basic-copy.test Tue Dec 18 23:24:38 2018<br>
@@ -0,0 +1,42 @@<br>
+Test plain passthrough copying with llvm-objcopy, by checking that obj2yaml<br>
+produces identical output for both input and output object files/executables.<br>
+(Intentionally not comparing to the original input yaml, in case there are<br>
+superficial differences like line endings.) In order to have a check of the<br>
+whole file and not just individual fields with FileCheck, checking with<br>
+obj2yaml+cmp instead of llvm-readobj+cmp, as llvm-readobj also prints file<br>
+details that can differ between otherwise equal files (such as file offsets).<br>
+<br>
+Actual copied object files/executables can differ in, among others, the<br>
+following aspects:<br>
+- The padding of executable sections (lld uses 0xcc, which is int3 on x86)<br>
+- The actual layout of the string table (it can be filled linearly,<br>
+ strings can be dedupliated, the table can be optimized by sharing tails<br>
+ of longer strings; different parts in llvm do each of these three options)<br>
+- The size indication for an empty/missing string table can either be 4<br>
+ or left out altogether<br>
+- Alignment of section data<br>
+- Checksums<br>
+<br>
+RUN: yaml2obj %p/Inputs/i386-obj.yaml > %t.i386.o<br>
+RUN: llvm-objcopy %t.i386.o %t.i386-copy.o<br>
+RUN: obj2yaml %t.i386.o > %t.i386.o.yaml<br>
+RUN: obj2yaml %t.i386-copy.o > %t.i386-copy.o.yaml<br>
+RUN: cmp %t.i386.o.yaml %t.i386-copy.o.yaml<br>
+<br>
+RUN: yaml2obj %p/Inputs/x86_64-obj.yaml > %t.x86_64.o<br>
+RUN: llvm-objcopy %t.x86_64.o %t.x86_64-copy.o<br>
+RUN: obj2yaml %t.x86_64.o > %t.x86_64.o.yaml<br>
+RUN: obj2yaml %t.x86_64-copy.o > %t.x86_64-copy.o.yaml<br>
+RUN: cmp %t.x86_64.o.yaml %t.x86_64-copy.o.yaml<br>
+<br>
+RUN: yaml2obj %p/Inputs/i386-exe.yaml > %t.i386.exe<br>
+RUN: llvm-objcopy %t.i386.exe %t.i386-copy.exe<br>
+RUN: obj2yaml %t.i386.exe > %t.i386.exe.yaml<br>
+RUN: obj2yaml %t.i386-copy.exe > %t.i386-copy.exe.yaml<br>
+RUN: cmp %t.i386.exe.yaml %t.i386-copy.exe.yaml<br>
+<br>
+RUN: yaml2obj %p/Inputs/x86_64-exe.yaml > %t.x86_64.exe<br>
+RUN: llvm-objcopy %t.x86_64.exe %t.x86_64-copy.exe<br>
+RUN: obj2yaml %t.x86_64.exe > %t.x86_64.exe.yaml<br>
+RUN: obj2yaml %t.x86_64-copy.exe > %t.x86_64-copy.exe.yaml<br>
+RUN: cmp %t.x86_64.exe.yaml %t.x86_64-copy.exe.yaml<br>
<br>
Modified: llvm/trunk/tools/llvm-objcopy/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/CMakeLists.txt?rev=349605&r1=349604&r2=349605&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/CMakeLists.txt?rev=349605&r1=349604&r2=349605&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-objcopy/CMakeLists.txt (original)<br>
+++ llvm/trunk/tools/llvm-objcopy/CMakeLists.txt Tue Dec 18 23:24:38 2018<br>
@@ -17,6 +17,9 @@ add_llvm_tool(llvm-objcopy<br>
Buffer.cpp<br>
CopyConfig.cpp<br>
llvm-objcopy.cpp<br>
+ COFF/COFFObjcopy.cpp<br>
+ COFF/Reader.cpp<br>
+ COFF/Writer.cpp<br>
ELF/ELFObjcopy.cpp<br>
ELF/Object.cpp<br>
DEPENDS<br>
<br>
Added: llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp?rev=349605&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp?rev=349605&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp (added)<br>
+++ llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp Tue Dec 18 23:24:38 2018<br>
@@ -0,0 +1,40 @@<br>
+//===- COFFObjcopy.cpp ----------------------------------------------------===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "COFFObjcopy.h"<br>
+#include "Buffer.h"<br>
+#include "CopyConfig.h"<br>
+#include "Object.h"<br>
+#include "Reader.h"<br>
+#include "Writer.h"<br>
+#include "llvm-objcopy.h"<br>
+<br>
+#include "llvm/Object/Binary.h"<br>
+#include "llvm/Object/COFF.h"<br>
+#include <cassert><br>
+<br>
+namespace llvm {<br>
+namespace objcopy {<br>
+namespace coff {<br>
+<br>
+using namespace object;<br>
+using namespace COFF;<br>
+<br>
+void executeObjcopyOnBinary(const CopyConfig &Config,<br>
+ object::COFFObjectFile &In, Buffer &Out) {<br>
+ COFFReader Reader(In);<br>
+ std::unique_ptr<Object> Obj = Reader.create();<br>
+ assert(Obj && "Unable to deserialize COFF object");<br>
+ COFFWriter Writer(*Obj, Out);<br>
+ Writer.write();<br>
+}<br>
+<br>
+} // end namespace coff<br>
+} // end namespace objcopy<br>
+} // end namespace llvm<br>
<br>
Added: llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.h?rev=349605&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.h?rev=349605&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.h (added)<br>
+++ llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.h Tue Dec 18 23:24:38 2018<br>
@@ -0,0 +1,31 @@<br>
+//===- COFFObjcopy.h --------------------------------------------*- C++ -*-===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_TOOLS_OBJCOPY_COFFOBJCOPY_H<br>
+#define LLVM_TOOLS_OBJCOPY_COFFOBJCOPY_H<br>
+<br>
+namespace llvm {<br>
+<br>
+namespace object {<br>
+class COFFObjectFile;<br>
+} // end namespace object<br>
+<br>
+namespace objcopy {<br>
+struct CopyConfig;<br>
+class Buffer;<br>
+<br>
+namespace coff {<br>
+void executeObjcopyOnBinary(const CopyConfig &Config,<br>
+ object::COFFObjectFile &In, Buffer &Out);<br>
+<br>
+} // end namespace coff<br>
+} // end namespace objcopy<br>
+} // end namespace llvm<br>
+<br>
+#endif // LLVM_TOOLS_OBJCOPY_COFFOBJCOPY_H<br>
<br>
Added: llvm/trunk/tools/llvm-objcopy/COFF/Object.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/Object.h?rev=349605&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/Object.h?rev=349605&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-objcopy/COFF/Object.h (added)<br>
+++ llvm/trunk/tools/llvm-objcopy/COFF/Object.h Tue Dec 18 23:24:38 2018<br>
@@ -0,0 +1,110 @@<br>
+//===- Object.h -------------------------------------------------*- C++ -*-===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_TOOLS_OBJCOPY_COFF_OBJECT_H<br>
+#define LLVM_TOOLS_OBJCOPY_COFF_OBJECT_H<br>
+<br>
+#include "llvm/ADT/ArrayRef.h"<br>
+#include "llvm/ADT/StringRef.h"<br>
+#include "llvm/BinaryFormat/COFF.h"<br>
+#include "llvm/Object/COFF.h"<br>
+#include <cstddef><br>
+#include <cstdint><br>
+#include <vector><br>
+<br>
+namespace llvm {<br>
+namespace objcopy {<br>
+namespace coff {<br>
+<br>
+struct Section {<br>
+ object::coff_section Header;<br>
+ ArrayRef<uint8_t> Contents;<br>
+ std::vector<object::coff_relocation> Relocs;<br>
+ StringRef Name;<br>
+};<br>
+<br>
+struct Symbol {<br>
+ object::coff_symbol32 Sym;<br>
+ StringRef Name;<br>
+ ArrayRef<uint8_t> AuxData;<br>
+};<br>
+<br>
+struct Object {<br>
+ bool IsPE = false;<br>
+<br>
+ object::dos_header DosHeader;<br>
+ ArrayRef<uint8_t> DosStub;<br>
+<br>
+ object::coff_file_header CoffFileHeader;<br>
+<br>
+ bool Is64 = false;<br>
+ object::pe32plus_header PeHeader;<br>
+ uint32_t BaseOfData = 0; // pe32plus_header lacks this field.<br>
+<br>
+ std::vector<object::data_directory> DataDirectories;<br>
+ std::vector<Section> Sections;<br>
+ std::vector<Symbol> Symbols;<br>
+};<br>
+<br>
+// Copy between coff_symbol16 and coff_symbol32.<br>
+// The source and destination files can use either coff_symbol16 or<br>
+// coff_symbol32, while we always store them as coff_symbol32 in the<br>
+// intermediate data structure.<br>
+template <class Symbol1Ty, class Symbol2Ty><br>
+void copySymbol(Symbol1Ty &Dest, const Symbol2Ty &Src) {<br>
+ static_assert(sizeof(Dest.Name.ShortName) == sizeof(Src.Name.ShortName),<br>
+ "Mismatched name sizes");<br>
+ memcpy(Dest.Name.ShortName, Src.Name.ShortName, sizeof(Dest.Name.ShortName));<br>
+ Dest.Value = Src.Value;<br>
+ Dest.SectionNumber = Src.SectionNumber;<br>
+ Dest.Type = Src.Type;<br>
+ Dest.StorageClass = Src.StorageClass;<br>
+ Dest.NumberOfAuxSymbols = Src.NumberOfAuxSymbols;<br>
+}<br>
+<br>
+// Copy between pe32_header and pe32plus_header.<br>
+// We store the intermediate state in a pe32plus_header.<br>
+template <class PeHeader1Ty, class PeHeader2Ty><br>
+void copyPeHeader(PeHeader1Ty &Dest, const PeHeader2Ty &Src) {<br>
+ Dest.Magic = Src.Magic;<br>
+ Dest.MajorLinkerVersion = Src.MajorLinkerVersion;<br>
+ Dest.MinorLinkerVersion = Src.MinorLinkerVersion;<br>
+ Dest.SizeOfCode = Src.SizeOfCode;<br>
+ Dest.SizeOfInitializedData = Src.SizeOfInitializedData;<br>
+ Dest.SizeOfUninitializedData = Src.SizeOfUninitializedData;<br>
+ Dest.AddressOfEntryPoint = Src.AddressOfEntryPoint;<br>
+ Dest.BaseOfCode = Src.BaseOfCode;<br>
+ Dest.ImageBase = Src.ImageBase;<br>
+ Dest.SectionAlignment = Src.SectionAlignment;<br>
+ Dest.FileAlignment = Src.FileAlignment;<br>
+ Dest.MajorOperatingSystemVersion = Src.MajorOperatingSystemVersion;<br>
+ Dest.MinorOperatingSystemVersion = Src.MinorOperatingSystemVersion;<br>
+ Dest.MajorImageVersion = Src.MajorImageVersion;<br>
+ Dest.MinorImageVersion = Src.MinorImageVersion;<br>
+ Dest.MajorSubsystemVersion = Src.MajorSubsystemVersion;<br>
+ Dest.MinorSubsystemVersion = Src.MinorSubsystemVersion;<br>
+ Dest.Win32VersionValue = Src.Win32VersionValue;<br>
+ Dest.SizeOfImage = Src.SizeOfImage;<br>
+ Dest.SizeOfHeaders = Src.SizeOfHeaders;<br>
+ Dest.CheckSum = Src.CheckSum;<br>
+ Dest.Subsystem = Src.Subsystem;<br>
+ Dest.DLLCharacteristics = Src.DLLCharacteristics;<br>
+ Dest.SizeOfStackReserve = Src.SizeOfStackReserve;<br>
+ Dest.SizeOfStackCommit = Src.SizeOfStackCommit;<br>
+ Dest.SizeOfHeapReserve = Src.SizeOfHeapReserve;<br>
+ Dest.SizeOfHeapCommit = Src.SizeOfHeapCommit;<br>
+ Dest.LoaderFlags = Src.LoaderFlags;<br>
+ Dest.NumberOfRvaAndSize = Src.NumberOfRvaAndSize;<br>
+}<br>
+<br>
+} // end namespace coff<br>
+} // end namespace objcopy<br>
+} // end namespace llvm<br>
+<br>
+#endif // LLVM_TOOLS_OBJCOPY_COFF_OBJECT_H<br>
<br>
Added: llvm/trunk/tools/llvm-objcopy/COFF/Reader.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/Reader.cpp?rev=349605&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/Reader.cpp?rev=349605&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-objcopy/COFF/Reader.cpp (added)<br>
+++ llvm/trunk/tools/llvm-objcopy/COFF/Reader.cpp Tue Dec 18 23:24:38 2018<br>
@@ -0,0 +1,141 @@<br>
+//===- Reader.cpp ---------------------------------------------------------===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "Reader.h"<br>
+#include "Object.h"<br>
+#include "llvm-objcopy.h"<br>
+#include "llvm/ADT/ArrayRef.h"<br>
+#include "llvm/ADT/StringRef.h"<br>
+#include "llvm/Object/COFF.h"<br>
+#include "llvm/Support/ErrorHandling.h"<br>
+#include <cstddef><br>
+#include <cstdint><br>
+<br>
+namespace llvm {<br>
+namespace objcopy {<br>
+namespace coff {<br>
+<br>
+using namespace object;<br>
+<br>
+Reader::~Reader() {}<br>
+<br>
+void COFFReader::readExecutableHeaders(Object &Obj) const {<br>
+ const dos_header *DH = COFFObj.getDOSHeader();<br>
+ Obj.Is64 = COFFObj.is64();<br>
+ if (!DH)<br>
+ return;<br>
+<br>
+ Obj.IsPE = true;<br>
+ Obj.DosHeader = *DH;<br>
+ if (DH->AddressOfNewExeHeader > sizeof(*DH))<br>
+ Obj.DosStub = ArrayRef<uint8_t>(reinterpret_cast<const uint8_t *>(&DH[1]),<br>
+ DH->AddressOfNewExeHeader - sizeof(*DH));<br>
+<br>
+ if (COFFObj.is64()) {<br>
+ const pe32plus_header *PE32Plus = nullptr;<br>
+ if (auto EC = COFFObj.getPE32PlusHeader(PE32Plus))<br>
+ reportError(COFFObj.getFileName(), std::move(EC));<br>
+ Obj.PeHeader = *PE32Plus;<br>
+ } else {<br>
+ const pe32_header *PE32 = nullptr;<br>
+ if (auto EC = COFFObj.getPE32Header(PE32))<br>
+ reportError(COFFObj.getFileName(), std::move(EC));<br>
+ copyPeHeader(Obj.PeHeader, *PE32);<br>
+ // The pe32plus_header (stored in Object) lacks the BaseOfData field.<br>
+ Obj.BaseOfData = PE32->BaseOfData;<br>
+ }<br>
+<br>
+ for (size_t I = 0; I < Obj.PeHeader.NumberOfRvaAndSize; I++) {<br>
+ const data_directory *Dir;<br>
+ if (auto EC = COFFObj.getDataDirectory(I, Dir))<br>
+ reportError(COFFObj.getFileName(), std::move(EC));<br>
+ Obj.DataDirectories.emplace_back(*Dir);<br>
+ }<br>
+}<br>
+<br>
+void COFFReader::readSections(Object &Obj) const {<br>
+ // Section indexing starts from 1.<br>
+ for (size_t I = 1, E = COFFObj.getNumberOfSections(); I <= E; I++) {<br>
+ const coff_section *Sec;<br>
+ if (auto EC = COFFObj.getSection(I, Sec))<br>
+ reportError(COFFObj.getFileName(), std::move(EC));<br>
+ Obj.Sections.push_back(Section());<br>
+ Section &S = Obj.Sections.back();<br>
+ S.Header = *Sec;<br>
+ if (auto EC = COFFObj.getSectionContents(Sec, S.Contents))<br>
+ reportError(COFFObj.getFileName(), std::move(EC));<br>
+ ArrayRef<coff_relocation> Relocs = COFFObj.getRelocations(Sec);<br>
+ S.Relocs.insert(S.Relocs.end(), Relocs.begin(), Relocs.end());<br>
+ if (auto EC = COFFObj.getSectionName(Sec, S.Name))<br>
+ reportError(COFFObj.getFileName(), std::move(EC));<br>
+ if (Sec->hasExtendedRelocations())<br>
+ reportError(<br>
+ COFFObj.getFileName(),<br>
+ make_error<StringError>("Extended relocations not supported yet",<br>
+ object_error::parse_failed));<br>
+ }<br>
+}<br>
+<br>
+void COFFReader::readSymbols(Object &Obj, bool IsBigObj) const {<br>
+ for (uint32_t I = 0, E = COFFObj.getRawNumberOfSymbols(); I < E;) {<br>
+ Expected<COFFSymbolRef> SymOrErr = COFFObj.getSymbol(I);<br>
+ if (!SymOrErr)<br>
+ reportError(COFFObj.getFileName(), SymOrErr.takeError());<br>
+ COFFSymbolRef SymRef = *SymOrErr;<br>
+<br>
+ Obj.Symbols.push_back(Symbol());<br>
+ Symbol &Sym = Obj.Symbols.back();<br>
+ // Copy symbols from the original form into an intermediate coff_symbol32.<br>
+ if (IsBigObj)<br>
+ copySymbol(Sym.Sym,<br>
+ *reinterpret_cast<const coff_symbol32 *>(SymRef.getRawPtr()));<br>
+ else<br>
+ copySymbol(Sym.Sym,<br>
+ *reinterpret_cast<const coff_symbol16 *>(SymRef.getRawPtr()));<br>
+ if (auto EC = COFFObj.getSymbolName(SymRef, Sym.Name))<br>
+ reportError(COFFObj.getFileName(), std::move(EC));<br>
+ Sym.AuxData = COFFObj.getSymbolAuxData(SymRef);<br>
+ assert((Sym.AuxData.size() %<br>
+ (IsBigObj ? sizeof(coff_symbol32) : sizeof(coff_symbol16))) == 0);<br>
+ I += 1 + SymRef.getNumberOfAuxSymbols();<br>
+ }<br>
+}<br>
+<br>
+std::unique_ptr<Object> COFFReader::create() const {<br>
+ auto Obj = llvm::make_unique<Object>();<br>
+<br>
+ const coff_file_header *CFH = nullptr;<br>
+ const coff_bigobj_file_header *CBFH = nullptr;<br>
+ COFFObj.getCOFFHeader(CFH);<br>
+ COFFObj.getCOFFBigObjHeader(CBFH);<br>
+ bool IsBigObj = false;<br>
+ if (CFH) {<br>
+ Obj->CoffFileHeader = *CFH;<br>
+ } else {<br>
+ if (!CBFH)<br>
+ reportError(COFFObj.getFileName(),<br>
+ make_error<StringError>("No COFF file header returned",<br>
+ object_error::parse_failed));<br>
+ // Only copying the few fields from the bigobj header that we need<br>
+ // and won't recreate in the end.<br>
+ Obj->CoffFileHeader.Machine = CBFH->Machine;<br>
+ Obj->CoffFileHeader.TimeDateStamp = CBFH->TimeDateStamp;<br>
+ IsBigObj = true;<br>
+ }<br>
+<br>
+ readExecutableHeaders(*Obj);<br>
+ readSections(*Obj);<br>
+ readSymbols(*Obj, IsBigObj);<br>
+<br>
+ return Obj;<br>
+}<br>
+<br>
+} // end namespace coff<br>
+} // end namespace objcopy<br>
+} // end namespace llvm<br>
<br>
Added: llvm/trunk/tools/llvm-objcopy/COFF/Reader.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/Reader.h?rev=349605&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/Reader.h?rev=349605&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-objcopy/COFF/Reader.h (added)<br>
+++ llvm/trunk/tools/llvm-objcopy/COFF/Reader.h Tue Dec 18 23:24:38 2018<br>
@@ -0,0 +1,47 @@<br>
+//===- Reader.h -------------------------------------------------*- C++ -*-===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_TOOLS_OBJCOPY_COFF_READER_H<br>
+#define LLVM_TOOLS_OBJCOPY_COFF_READER_H<br>
+<br>
+#include "Buffer.h"<br>
+#include "llvm/BinaryFormat/COFF.h"<br>
+#include "llvm/Object/COFF.h"<br>
+<br>
+namespace llvm {<br>
+namespace objcopy {<br>
+namespace coff {<br>
+<br>
+class Object;<br>
+<br>
+using object::COFFObjectFile;<br>
+<br>
+class Reader {<br>
+public:<br>
+ virtual ~Reader();<br>
+ virtual std::unique_ptr<Object> create() const = 0;<br>
+};<br>
+<br>
+class COFFReader : public Reader {<br>
+ const COFFObjectFile &COFFObj;<br>
+<br>
+ void readExecutableHeaders(Object &Obj) const;<br>
+ void readSections(Object &Obj) const;<br>
+ void readSymbols(Object &Obj, bool IsBigObj) const;<br>
+<br>
+public:<br>
+ explicit COFFReader(const COFFObjectFile &O) : COFFObj(O) {}<br>
+ std::unique_ptr<Object> create() const override;<br>
+};<br>
+<br>
+} // end namespace coff<br>
+} // end namespace objcopy<br>
+} // end namespace llvm<br>
+<br>
+#endif // LLVM_TOOLS_OBJCOPY_COFF_READER_H<br>
<br>
Added: llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp?rev=349605&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp?rev=349605&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp (added)<br>
+++ llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp Tue Dec 18 23:24:38 2018<br>
@@ -0,0 +1,318 @@<br>
+//===- Writer.cpp ---------------------------------------------------------===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "Writer.h"<br>
+#include "Object.h"<br>
+#include "llvm-objcopy.h"<br>
+#include "llvm/ADT/ArrayRef.h"<br>
+#include "llvm/ADT/StringRef.h"<br>
+#include "llvm/BinaryFormat/COFF.h"<br>
+#include "llvm/Object/COFF.h"<br>
+#include "llvm/Support/ErrorHandling.h"<br>
+#include <cstddef><br>
+#include <cstdint><br>
+<br>
+namespace llvm {<br>
+namespace objcopy {<br>
+namespace coff {<br>
+<br>
+using namespace object;<br>
+using namespace COFF;<br>
+<br>
+Writer::~Writer() {}<br>
+<br>
+void COFFWriter::layoutSections() {<br>
+ for (auto &S : Obj.Sections) {<br>
+ if (S.Header.SizeOfRawData > 0)<br>
+ S.Header.PointerToRawData = FileSize;<br>
+ FileSize += S.Header.SizeOfRawData; // For executables, this is already<br>
+ // aligned to FileAlignment.<br>
+ if (S.Header.NumberOfRelocations > 0)<br>
+ S.Header.PointerToRelocations = FileSize;<br>
+ FileSize += S.Relocs.size() * sizeof(coff_relocation);<br>
+ FileSize = alignTo(FileSize, FileAlignment);<br>
+<br>
+ if (S.Header.Characteristics & IMAGE_SCN_CNT_INITIALIZED_DATA)<br>
+ SizeOfInitializedData += S.Header.SizeOfRawData;<br>
+ }<br>
+}<br>
+<br>
+size_t COFFWriter::finalizeStringTable() {<br>
+ for (auto &S : Obj.Sections)<br>
+ if (S.Name.size() > COFF::NameSize)<br>
+ StrTabBuilder.add(S.Name);<br>
+<br>
+ for (const auto &S : Obj.Symbols)<br>
+ if (S.Name.size() > COFF::NameSize)<br>
+ StrTabBuilder.add(S.Name);<br>
+<br>
+ StrTabBuilder.finalize();<br>
+<br>
+ for (auto &S : Obj.Sections) {<br>
+ if (S.Name.size() > COFF::NameSize) {<br>
+ snprintf(<a href="http://S.Header.Name" rel="noreferrer" target="_blank">S.Header.Name</a>, sizeof(<a href="http://S.Header.Name" rel="noreferrer" target="_blank">S.Header.Name</a>), "/%d",<br>
+ (int)StrTabBuilder.getOffset(S.Name));<br>
+ } else {<br>
+ strncpy(<a href="http://S.Header.Name" rel="noreferrer" target="_blank">S.Header.Name</a>, S.Name.data(), COFF::NameSize);<br>
+ }<br>
+ }<br>
+ for (auto &S : Obj.Symbols) {<br>
+ if (S.Name.size() > COFF::NameSize) {<br>
+ S.Sym.Name.Offset.Zeroes = 0;<br>
+ S.Sym.Name.Offset.Offset = StrTabBuilder.getOffset(S.Name);<br>
+ } else {<br>
+ strncpy(S.Sym.Name.ShortName, S.Name.data(), COFF::NameSize);<br>
+ }<br>
+ }<br>
+ return StrTabBuilder.getSize();<br>
+}<br>
+<br>
+template <class SymbolTy><br>
+std::pair<size_t, size_t> COFFWriter::finalizeSymbolTable() {<br>
+ size_t SymTabSize = Obj.Symbols.size() * sizeof(SymbolTy);<br>
+ for (const auto &S : Obj.Symbols)<br>
+ SymTabSize += S.AuxData.size();<br>
+ return std::make_pair(SymTabSize, sizeof(SymbolTy));<br>
+}<br>
+<br>
+void COFFWriter::finalize(bool IsBigObj) {<br>
+ size_t SizeOfHeaders = 0;<br>
+ FileAlignment = 1;<br>
+ size_t PeHeaderSize = 0;<br>
+ if (Obj.IsPE) {<br>
+ Obj.DosHeader.AddressOfNewExeHeader =<br>
+ sizeof(Obj.DosHeader) + Obj.DosStub.size();<br>
+ SizeOfHeaders += Obj.DosHeader.AddressOfNewExeHeader + sizeof(PEMagic);<br>
+<br>
+ FileAlignment = Obj.PeHeader.FileAlignment;<br>
+ Obj.PeHeader.NumberOfRvaAndSize = Obj.DataDirectories.size();<br>
+<br>
+ PeHeaderSize = Obj.Is64 ? sizeof(pe32plus_header) : sizeof(pe32_header);<br>
+ SizeOfHeaders +=<br>
+ PeHeaderSize + sizeof(data_directory) * Obj.DataDirectories.size();<br>
+ }<br>
+ Obj.CoffFileHeader.NumberOfSections = Obj.Sections.size();<br>
+ SizeOfHeaders +=<br>
+ IsBigObj ? sizeof(coff_bigobj_file_header) : sizeof(coff_file_header);<br>
+ SizeOfHeaders += sizeof(coff_section) * Obj.Sections.size();<br>
+ SizeOfHeaders = alignTo(SizeOfHeaders, FileAlignment);<br>
+<br>
+ Obj.CoffFileHeader.SizeOfOptionalHeader =<br>
+ PeHeaderSize + sizeof(data_directory) * Obj.DataDirectories.size();<br>
+<br>
+ FileSize = SizeOfHeaders;<br>
+ SizeOfInitializedData = 0;<br>
+<br>
+ layoutSections();<br>
+<br>
+ if (Obj.IsPE) {<br>
+ Obj.PeHeader.SizeOfHeaders = SizeOfHeaders;<br>
+ Obj.PeHeader.SizeOfInitializedData = SizeOfInitializedData;<br>
+<br>
+ if (!Obj.Sections.empty()) {<br>
+ const Section &S = Obj.Sections.back();<br>
+ Obj.PeHeader.SizeOfImage =<br>
+ alignTo(S.Header.VirtualAddress + S.Header.VirtualSize,<br>
+ Obj.PeHeader.SectionAlignment);<br>
+ }<br>
+<br>
+ // If the PE header had a checksum, clear it, since it isn't valid<br>
+ // any longer. (We don't calculate a new one.)<br>
+ Obj.PeHeader.CheckSum = 0;<br>
+ }<br>
+<br>
+ size_t StrTabSize = finalizeStringTable();<br>
+ size_t SymTabSize, SymbolSize;<br>
+ std::tie(SymTabSize, SymbolSize) = IsBigObj<br>
+ ? finalizeSymbolTable<coff_symbol32>()<br>
+ : finalizeSymbolTable<coff_symbol16>();<br>
+<br>
+ size_t PointerToSymbolTable = FileSize;<br>
+ // StrTabSize <= 4 is the size of an empty string table, only consisting<br>
+ // of the length field.<br>
+ if (SymTabSize == 0 && StrTabSize <= 4) {<br>
+ // Don't point to the symbol table if empty.<br>
+ PointerToSymbolTable = 0;<br>
+ // For executables, skip the length field of an empty string table.<br>
+ if (Obj.IsPE)<br>
+ StrTabSize = 0;<br>
+ }<br>
+<br>
+ size_t NumRawSymbols = SymTabSize / SymbolSize;<br>
+ Obj.CoffFileHeader.PointerToSymbolTable = PointerToSymbolTable;<br>
+ Obj.CoffFileHeader.NumberOfSymbols = NumRawSymbols;<br>
+ FileSize += SymTabSize + StrTabSize;<br>
+ FileSize = alignTo(FileSize, FileAlignment);<br>
+}<br>
+<br>
+void COFFWriter::writeHeaders(bool IsBigObj) {<br>
+ uint8_t *Ptr = Buf.getBufferStart();<br>
+ if (Obj.IsPE) {<br>
+ memcpy(Ptr, &Obj.DosHeader, sizeof(Obj.DosHeader));<br>
+ Ptr += sizeof(Obj.DosHeader);<br>
+ memcpy(Ptr, Obj.DosStub.data(), Obj.DosStub.size());<br>
+ Ptr += Obj.DosStub.size();<br>
+ memcpy(Ptr, PEMagic, sizeof(PEMagic));<br>
+ Ptr += sizeof(PEMagic);<br>
+ }<br>
+ if (!IsBigObj) {<br>
+ memcpy(Ptr, &Obj.CoffFileHeader, sizeof(Obj.CoffFileHeader));<br>
+ Ptr += sizeof(Obj.CoffFileHeader);<br>
+ } else {<br>
+ // Generate a coff_bigobj_file_header, filling it in with the values<br>
+ // from Obj.CoffFileHeader. All extra fields that don't exist in<br>
+ // coff_file_header can be set to hardcoded values.<br>
+ coff_bigobj_file_header BigObjHeader;<br>
+ BigObjHeader.Sig1 = IMAGE_FILE_MACHINE_UNKNOWN;<br>
+ BigObjHeader.Sig2 = 0xffff;<br>
+ BigObjHeader.Version = BigObjHeader::MinBigObjectVersion;<br>
+ BigObjHeader.Machine = Obj.CoffFileHeader.Machine;<br>
+ BigObjHeader.TimeDateStamp = Obj.CoffFileHeader.TimeDateStamp;<br>
+ memcpy(BigObjHeader.UUID, BigObjMagic, sizeof(BigObjMagic));<br>
+ BigObjHeader.unused1 = 0;<br>
+ BigObjHeader.unused2 = 0;<br>
+ BigObjHeader.unused3 = 0;<br>
+ BigObjHeader.unused4 = 0;<br>
+ // The value in Obj.CoffFileHeader.NumberOfSections is truncated, thus<br>
+ // get the original one instead.<br>
+ BigObjHeader.NumberOfSections = Obj.Sections.size();<br>
+ BigObjHeader.PointerToSymbolTable = Obj.CoffFileHeader.PointerToSymbolTable;<br>
+ BigObjHeader.NumberOfSymbols = Obj.CoffFileHeader.NumberOfSymbols;<br>
+<br>
+ memcpy(Ptr, &BigObjHeader, sizeof(BigObjHeader));<br>
+ Ptr += sizeof(BigObjHeader);<br>
+ }<br>
+ if (Obj.IsPE) {<br>
+ if (Obj.Is64) {<br>
+ memcpy(Ptr, &Obj.PeHeader, sizeof(Obj.PeHeader));<br>
+ Ptr += sizeof(Obj.PeHeader);<br>
+ } else {<br>
+ pe32_header PeHeader;<br>
+ copyPeHeader(PeHeader, Obj.PeHeader);<br>
+ // The pe32plus_header (stored in Object) lacks the BaseOfData field.<br>
+ PeHeader.BaseOfData = Obj.BaseOfData;<br>
+<br>
+ memcpy(Ptr, &PeHeader, sizeof(PeHeader));<br>
+ Ptr += sizeof(PeHeader);<br>
+ }<br>
+ for (const auto &DD : Obj.DataDirectories) {<br>
+ memcpy(Ptr, &DD, sizeof(DD));<br>
+ Ptr += sizeof(DD);<br>
+ }<br>
+ }<br>
+ for (const auto &S : Obj.Sections) {<br>
+ memcpy(Ptr, &S.Header, sizeof(S.Header));<br>
+ Ptr += sizeof(S.Header);<br>
+ }<br>
+}<br>
+<br>
+void COFFWriter::writeSections() {<br>
+ for (const auto &S : Obj.Sections) {<br>
+ uint8_t *Ptr = Buf.getBufferStart() + S.Header.PointerToRawData;<br>
+ memcpy(Ptr, S.Contents.data(), S.Contents.size());<br>
+<br>
+ // For executable sections, pad the remainder of the raw data size with<br>
+ // 0xcc, which is int3 on x86.<br>
+ if ((S.Header.Characteristics & IMAGE_SCN_CNT_CODE) &&<br>
+ S.Header.SizeOfRawData > S.Contents.size())<br>
+ memset(Ptr + S.Contents.size(), 0xcc,<br>
+ S.Header.SizeOfRawData - S.Contents.size());<br>
+<br>
+ Ptr += S.Header.SizeOfRawData;<br>
+ memcpy(Ptr, S.Relocs.data(), S.Relocs.size() * sizeof(coff_relocation));<br>
+ }<br>
+}<br>
+<br>
+template <class SymbolTy> void COFFWriter::writeSymbolStringTables() {<br>
+ uint8_t *Ptr = Buf.getBufferStart() + Obj.CoffFileHeader.PointerToSymbolTable;<br>
+ for (const auto &S : Obj.Symbols) {<br>
+ // Convert symbols back to the right size, from coff_symbol32.<br>
+ copySymbol<SymbolTy, coff_symbol32>(*reinterpret_cast<SymbolTy *>(Ptr),<br>
+ S.Sym);<br>
+ Ptr += sizeof(SymbolTy);<br>
+ memcpy(Ptr, S.AuxData.data(), S.AuxData.size());<br>
+ Ptr += S.AuxData.size();<br>
+ }<br>
+ if (StrTabBuilder.getSize() > 4 || !Obj.IsPE) {<br>
+ // Always write a string table in object files, even an empty one.<br>
+ StrTabBuilder.write(Ptr);<br>
+ Ptr += StrTabBuilder.getSize();<br>
+ }<br>
+}<br>
+<br>
+void COFFWriter::write(bool IsBigObj) {<br>
+ finalize(IsBigObj);<br>
+<br>
+ Buf.allocate(FileSize);<br>
+<br>
+ writeHeaders(IsBigObj);<br>
+ writeSections();<br>
+ if (IsBigObj)<br>
+ writeSymbolStringTables<coff_symbol32>();<br>
+ else<br>
+ writeSymbolStringTables<coff_symbol16>();<br>
+<br>
+ if (Obj.IsPE)<br>
+ patchDebugDirectory();<br>
+<br>
+ if (auto E = Buf.commit())<br>
+ reportError(Buf.getName(), errorToErrorCode(std::move(E)));<br>
+}<br>
+<br>
+// Locate which sections contain the debug directories, iterate over all<br>
+// the debug_directory structs in there, and set the PointerToRawData field<br>
+// in all of them, according to their new physical location in the file.<br>
+void COFFWriter::patchDebugDirectory() {<br>
+ if (Obj.DataDirectories.size() < DEBUG_DIRECTORY)<br>
+ return;<br>
+ const data_directory *Dir = &Obj.DataDirectories[DEBUG_DIRECTORY];<br>
+ if (Dir->Size <= 0)<br>
+ return;<br>
+ for (const auto &S : Obj.Sections) {<br>
+ if (Dir->RelativeVirtualAddress >= S.Header.VirtualAddress &&<br>
+ Dir->RelativeVirtualAddress <<br>
+ S.Header.VirtualAddress + S.Header.SizeOfRawData) {<br>
+ if (Dir->RelativeVirtualAddress + Dir->Size ><br>
+ S.Header.VirtualAddress + S.Header.SizeOfRawData)<br>
+ reportError(Buf.getName(),<br>
+ make_error<StringError>(<br>
+ "Debug directory extends past end of section",<br>
+ object_error::parse_failed));<br>
+<br>
+ size_t Offset = Dir->RelativeVirtualAddress - S.Header.VirtualAddress;<br>
+ uint8_t *Ptr = Buf.getBufferStart() + S.Header.PointerToRawData + Offset;<br>
+ uint8_t *End = Ptr + Dir->Size;<br>
+ while (Ptr < End) {<br>
+ debug_directory *Debug = reinterpret_cast<debug_directory *>(Ptr);<br>
+ Debug->PointerToRawData =<br>
+ S.Header.PointerToRawData + Offset + sizeof(debug_directory);<br>
+ Ptr += sizeof(debug_directory) + Debug->SizeOfData;<br>
+ Offset += sizeof(debug_directory) + Debug->SizeOfData;<br>
+ }<br>
+ // Debug directory found and patched, all done.<br>
+ return;<br>
+ }<br>
+ }<br>
+ reportError(Buf.getName(),<br>
+ make_error<StringError>("Debug directory not found",<br>
+ object_error::parse_failed));<br>
+}<br>
+<br>
+void COFFWriter::write() {<br>
+ bool IsBigObj = Obj.Sections.size() > MaxNumberOfSections16;<br>
+ if (IsBigObj && Obj.IsPE)<br>
+ reportError(Buf.getName(),<br>
+ make_error<StringError>("Too many sections for executable",<br>
+ object_error::parse_failed));<br>
+ write(IsBigObj);<br>
+}<br>
+<br>
+} // end namespace coff<br>
+} // end namespace objcopy<br>
+} // end namespace llvm<br>
<br>
Added: llvm/trunk/tools/llvm-objcopy/COFF/Writer.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/Writer.h?rev=349605&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/Writer.h?rev=349605&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-objcopy/COFF/Writer.h (added)<br>
+++ llvm/trunk/tools/llvm-objcopy/COFF/Writer.h Tue Dec 18 23:24:38 2018<br>
@@ -0,0 +1,68 @@<br>
+//===- Writer.h -------------------------------------------------*- C++ -*-===//<br>
+//<br>
+// The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_TOOLS_OBJCOPY_COFF_WRITER_H<br>
+#define LLVM_TOOLS_OBJCOPY_COFF_WRITER_H<br>
+<br>
+#include "Buffer.h"<br>
+#include "llvm/MC/StringTableBuilder.h"<br>
+#include <cstddef><br>
+#include <utility><br>
+<br>
+namespace llvm {<br>
+namespace objcopy {<br>
+namespace coff {<br>
+<br>
+class Object;<br>
+<br>
+class Writer {<br>
+protected:<br>
+ Object &Obj;<br>
+ Buffer &Buf;<br>
+<br>
+public:<br>
+ virtual ~Writer();<br>
+ virtual void write() = 0;<br>
+<br>
+ Writer(Object &O, Buffer &B) : Obj(O), Buf(B) {}<br>
+};<br>
+<br>
+class COFFWriter : public Writer {<br>
+ size_t FileSize;<br>
+ size_t FileAlignment;<br>
+ size_t SizeOfInitializedData;<br>
+ StringTableBuilder StrTabBuilder;<br>
+<br>
+ void layoutSections();<br>
+ size_t finalizeStringTable();<br>
+ template <class SymbolTy> std::pair<size_t, size_t> finalizeSymbolTable();<br>
+<br>
+ void finalize(bool IsBigObj);<br>
+<br>
+ void writeHeaders(bool IsBigObj);<br>
+ void writeSections();<br>
+ template <class SymbolTy> void writeSymbolStringTables();<br>
+<br>
+ void write(bool IsBigObj);<br>
+<br>
+ void patchDebugDirectory();<br>
+<br>
+public:<br>
+ virtual ~COFFWriter() {}<br>
+ void write() override;<br>
+<br>
+ COFFWriter(Object &Obj, Buffer &Buf)<br>
+ : Writer(Obj, Buf), StrTabBuilder(StringTableBuilder::WinCOFF) {}<br>
+};<br>
+<br>
+} // end namespace coff<br>
+} // end namespace objcopy<br>
+} // end namespace llvm<br>
+<br>
+#endif // LLVM_TOOLS_OBJCOPY_COFF_WRITER_H<br>
<br>
Modified: llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp?rev=349605&r1=349604&r2=349605&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp?rev=349605&r1=349604&r2=349605&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp (original)<br>
+++ llvm/trunk/tools/llvm-objcopy/llvm-objcopy.cpp Tue Dec 18 23:24:38 2018<br>
@@ -9,6 +9,7 @@<br>
<br>
#include "llvm-objcopy.h"<br>
#include "Buffer.h"<br>
+#include "COFF/COFFObjcopy.h"<br>
#include "CopyConfig.h"<br>
#include "ELF/ELFObjcopy.h"<br>
<br>
@@ -19,6 +20,7 @@<br>
#include "llvm/Object/Archive.h"<br>
#include "llvm/Object/ArchiveWriter.h"<br>
#include "llvm/Object/Binary.h"<br>
+#include "llvm/Object/COFF.h"<br>
#include "llvm/Object/ELFObjectFile.h"<br>
#include "llvm/Object/ELFTypes.h"<br>
#include "llvm/Object/Error.h"<br>
@@ -125,6 +127,8 @@ static void executeObjcopyOnBinary(const<br>
Buffer &Out) {<br>
if (auto *ELFBinary = dyn_cast<object::ELFObjectFileBase>(&In))<br>
return elf::executeObjcopyOnBinary(Config, *ELFBinary, Out);<br>
+ else if (auto *COFFBinary = dyn_cast<object::COFFObjectFile>(&In))<br>
+ return coff::executeObjcopyOnBinary(Config, *COFFBinary, Out);<br>
else<br>
error("Unsupported object file format");<br>
}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>