diff options
author | Rui Ueyama <ruiu@google.com> | 2015-07-24 23:51:14 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2015-07-24 23:51:14 +0000 |
commit | cd3f99b6c534ad0d0e2040c6beea8e82b575123b (patch) | |
tree | c8d8811b7aa8a48c7bfd86203dc3e7634967470e | |
parent | 39497e9f5bd9c82c15b4d1798976e5daad5c7767 (diff) | |
download | bcm5719-llvm-cd3f99b6c534ad0d0e2040c6beea8e82b575123b.tar.gz bcm5719-llvm-cd3f99b6c534ad0d0e2040c6beea8e82b575123b.zip |
COFF: Implement Safe SEH support for x86.
An object file compatible with Safe SEH contains a .sxdata section.
The section contains a list of symbol table indices, each of which
is an exception handler function. A safe SEH-enabled executable
contains a list of exception handler RVAs. So, what the linker has
to do to support Safe SEH is basically to read the .sxdata section,
interpret the contents as a list of symbol indices, unique-fy and
sort their RVAs, and then emit that list to .rdata. This patch
implements that feature.
llvm-svn: 243182
-rw-r--r-- | lld/COFF/Chunks.cpp | 9 | ||||
-rw-r--r-- | lld/COFF/Chunks.h | 13 | ||||
-rw-r--r-- | lld/COFF/Config.h | 6 | ||||
-rw-r--r-- | lld/COFF/Driver.cpp | 10 | ||||
-rw-r--r-- | lld/COFF/InputFiles.cpp | 33 | ||||
-rw-r--r-- | lld/COFF/InputFiles.h | 11 | ||||
-rw-r--r-- | lld/COFF/SymbolTable.cpp | 12 | ||||
-rw-r--r-- | lld/COFF/SymbolTable.h | 3 | ||||
-rw-r--r-- | lld/COFF/Symbols.h | 1 | ||||
-rw-r--r-- | lld/COFF/Writer.cpp | 30 | ||||
-rw-r--r-- | lld/COFF/Writer.h | 2 | ||||
-rw-r--r-- | lld/test/COFF/Inputs/seh.c | 13 | ||||
-rw-r--r-- | lld/test/COFF/Inputs/seh.obj.yaml | 387 | ||||
-rw-r--r-- | lld/test/COFF/seh.test | 24 |
14 files changed, 545 insertions, 9 deletions
diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp index 4f1ac166847..30e52963da0 100644 --- a/lld/COFF/Chunks.cpp +++ b/lld/COFF/Chunks.cpp @@ -23,6 +23,7 @@ using namespace llvm; using namespace llvm::object; using namespace llvm::support::endian; using namespace llvm::COFF; +using llvm::support::ulittle32_t; namespace lld { namespace coff { @@ -280,6 +281,14 @@ void LocalImportChunk::writeTo(uint8_t *Buf) { } } +void SEHTableChunk::writeTo(uint8_t *Buf) { + ulittle32_t *Begin = reinterpret_cast<ulittle32_t *>(Buf + FileOff); + size_t Cnt = 0; + for (Defined *D : Syms) + Begin[Cnt++] = D->getRVA(); + std::sort(Begin, Begin + Cnt); +} + // Windows-specific. // This class represents a block in .reloc section. BaserelChunk::BaserelChunk(uint32_t Page, uint32_t *Begin, uint32_t *End) { diff --git a/lld/COFF/Chunks.h b/lld/COFF/Chunks.h index a069f31e945..e84c11e50e7 100644 --- a/lld/COFF/Chunks.h +++ b/lld/COFF/Chunks.h @@ -255,6 +255,19 @@ private: }; // Windows-specific. +// A chunk for SEH table which contains RVAs of safe exception handler +// functions. x86-only. +class SEHTableChunk : public Chunk { +public: + explicit SEHTableChunk(std::set<Defined *> S) : Syms(S) {} + size_t getSize() const override { return Syms.size() * 4; } + void writeTo(uint8_t *Buf) override; + +private: + std::set<Defined *> Syms; +}; + +// Windows-specific. // This class represents a block in .reloc section. // See the PE/COFF spec 5.6 for details. class BaserelChunk : public Chunk { diff --git a/lld/COFF/Config.h b/lld/COFF/Config.h index 8fe537a9abd..d0ddc194e60 100644 --- a/lld/COFF/Config.h +++ b/lld/COFF/Config.h @@ -24,6 +24,8 @@ using llvm::COFF::IMAGE_FILE_MACHINE_AMD64; using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN; using llvm::COFF::WindowsSubsystem; using llvm::StringRef; +class DefinedAbsolute; +class DefinedRelative; class Undefined; // Represents an /export option. @@ -72,6 +74,10 @@ struct Configuration { std::set<std::string> DelayLoads; Undefined *DelayLoadHelper = nullptr; + // Used for SafeSEH. + DefinedRelative *SEHTable = nullptr; + DefinedAbsolute *SEHCount = nullptr; + // Used for /opt:icf bool ICF = false; diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 689892be489..7156b359e20 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -603,6 +603,10 @@ bool LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) { } Symtab.addRelative(mangle("__ImageBase"), 0); + if (Config->MachineType == IMAGE_FILE_MACHINE_I386) { + Config->SEHTable = Symtab.addRelative("___safe_se_handler_table", 0); + Config->SEHCount = Symtab.addAbsolute("___safe_se_handler_count", 0); + } // Read as much files as we can from directives sections. if (auto EC = Symtab.run()) { @@ -639,6 +643,12 @@ bool LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) { U->WeakAlias = Symtab.addUndefined(To); } + // Windows specific -- if __load_config_used can be resolved, resolve it. + if (Config->MachineType == IMAGE_FILE_MACHINE_I386) + if (Symbol *Sym = Symtab.find("__load_config_used")) + if (isa<Lazy>(Sym->Body)) + Symtab.addUndefined("__load_config_used"); + if (Symtab.queueEmpty()) break; if (auto EC = Symtab.run()) { diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp index d9312f633f3..4e5e34c3405 100644 --- a/lld/COFF/InputFiles.cpp +++ b/lld/COFF/InputFiles.cpp @@ -25,6 +25,7 @@ using namespace llvm::object; using namespace llvm::support::endian; using llvm::RoundUpToAlignment; using llvm::Triple; +using llvm::support::ulittle32_t; using llvm::sys::fs::file_magic; using llvm::sys::fs::identify_magic; @@ -112,7 +113,9 @@ std::error_code ObjectFile::parse() { // Read section and symbol tables. if (auto EC = initializeChunks()) return EC; - return initializeSymbols(); + if (auto EC = initializeSymbols()) + return EC; + return initializeSEH(); } std::error_code ObjectFile::initializeChunks() { @@ -132,6 +135,10 @@ std::error_code ObjectFile::initializeChunks() { << EC.message() << "\n"; return make_error_code(LLDError::BrokenFile); } + if (Name == ".sxdata") { + SXData = Sec; + continue; + } if (Name == ".drectve") { ArrayRef<uint8_t> Data; COFFObj->getSectionContents(Sec, Data); @@ -214,8 +221,14 @@ Defined *ObjectFile::createDefined(COFFSymbolRef Sym, const void *AuxP, if (Sym.isAbsolute()) { COFFObj->getSymbolName(Sym, Name); // Skip special symbols. - if (Name == "@comp.id" || Name == "@feat.00") + if (Name == "@comp.id") return nullptr; + // COFF spec 5.10.1. The .sxdata section. + if (Name == "@feat.00") { + if (Sym.getValue() & 1) + SEHCompat = true; + return nullptr; + } return new (Alloc) DefinedAbsolute(Name, Sym); } if (Sym.getSectionNumber() == llvm::COFF::IMAGE_SYM_DEBUG) @@ -242,6 +255,22 @@ Defined *ObjectFile::createDefined(COFFSymbolRef Sym, const void *AuxP, return B; } +std::error_code ObjectFile::initializeSEH() { + if (!SEHCompat || !SXData) + return std::error_code(); + ArrayRef<uint8_t> A; + COFFObj->getSectionContents(SXData, A); + if (A.size() % 4 != 0) { + llvm::errs() << ".sxdata must be an array of symbol table indices\n"; + return make_error_code(LLDError::BrokenFile); + } + auto *I = reinterpret_cast<const ulittle32_t *>(A.data()); + auto *E = reinterpret_cast<const ulittle32_t *>(A.data() + A.size()); + for (; I != E; ++I) + SEHandlers.insert(SparseSymbolBodies[*I]); + return std::error_code(); +} + MachineTypes ObjectFile::getMachineType() { if (COFFObj) return static_cast<MachineTypes>(COFFObj->getMachine()); diff --git a/lld/COFF/InputFiles.h b/lld/COFF/InputFiles.h index 361d97d8af1..6f201d66892 100644 --- a/lld/COFF/InputFiles.h +++ b/lld/COFF/InputFiles.h @@ -29,6 +29,7 @@ using llvm::COFF::MachineTypes; using llvm::object::Archive; using llvm::object::COFFObjectFile; using llvm::object::COFFSymbolRef; +using llvm::object::coff_section; class Chunk; class Defined; @@ -130,9 +131,18 @@ public: // Returns the underying COFF file. COFFObjectFile *getCOFFObj() { return COFFObj.get(); } + // True if this object file is compatible with SEH. + // COFF-specific and x86-only. + bool SEHCompat = false; + + // The list of safe exception handlers listed in .sxdata section. + // COFF-specific and x86-only. + std::set<SymbolBody *> SEHandlers; + private: std::error_code initializeChunks(); std::error_code initializeSymbols(); + std::error_code initializeSEH(); Defined *createDefined(COFFSymbolRef Sym, const void *Aux, bool IsFirst); Undefined *createUndefined(COFFSymbolRef Sym); @@ -140,6 +150,7 @@ private: std::unique_ptr<COFFObjectFile> COFFObj; llvm::BumpPtrAllocator Alloc; + const coff_section *SXData = nullptr; // List of all chunks defined by this file. This includes both section // chunks and non-section chunks for common symbols. diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp index 14fb72480d9..d3f8b038460 100644 --- a/lld/COFF/SymbolTable.cpp +++ b/lld/COFF/SymbolTable.cpp @@ -317,8 +317,16 @@ Undefined *SymbolTable::addUndefined(StringRef Name) { return New; } -void SymbolTable::addRelative(StringRef Name, uint64_t VA) { - addSymbol(new (Alloc) DefinedRelative(Name, VA)); +DefinedRelative *SymbolTable::addRelative(StringRef Name, uint64_t VA) { + auto *New = new (Alloc) DefinedRelative(Name, VA); + addSymbol(New); + return New; +} + +DefinedAbsolute *SymbolTable::addAbsolute(StringRef Name, uint64_t VA) { + auto *New = new (Alloc) DefinedAbsolute(Name, VA); + addSymbol(New); + return New; } void SymbolTable::printMap(llvm::raw_ostream &OS) { diff --git a/lld/COFF/SymbolTable.h b/lld/COFF/SymbolTable.h index a8d12b876ae..479dce6fbcb 100644 --- a/lld/COFF/SymbolTable.h +++ b/lld/COFF/SymbolTable.h @@ -81,7 +81,8 @@ public: // Creates an Undefined symbol for a given name. Undefined *addUndefined(StringRef Name); - void addRelative(StringRef Name, uint64_t VA); + DefinedRelative *addRelative(StringRef Name, uint64_t VA); + DefinedAbsolute *addAbsolute(StringRef Name, uint64_t VA); // A list of chunks which to be added to .rdata. std::vector<Chunk *> LocalImportChunks; diff --git a/lld/COFF/Symbols.h b/lld/COFF/Symbols.h index 2730f9bc044..bb199a99be5 100644 --- a/lld/COFF/Symbols.h +++ b/lld/COFF/Symbols.h @@ -218,6 +218,7 @@ public: } uint64_t getRVA() { return VA - Config->ImageBase; } + void setVA(uint64_t V) { VA = V; } private: uint64_t VA; diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index 8825f664f90..1245a21da37 100644 --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -58,6 +58,7 @@ std::error_code Writer::write(StringRef OutputPath) { } else { writeHeader<pe32_header>(); } + fixSafeSEHSymbols(); writeSections(); sortExceptionTable(); return Buffer->commit(); @@ -211,11 +212,25 @@ void Writer::createSections() { } void Writer::createMiscChunks() { - if (Symtab->LocalImportChunks.empty()) + // Create thunks for locally-dllimported symbols. + if (!Symtab->LocalImportChunks.empty()) { + OutputSection *Sec = createSection(".rdata"); + for (Chunk *C : Symtab->LocalImportChunks) + Sec->addChunk(C); + } + + // Create SEH table. x86-only. + if (Config->MachineType != IMAGE_FILE_MACHINE_I386) return; - OutputSection *Sec = createSection(".rdata"); - for (Chunk *C : Symtab->LocalImportChunks) - Sec->addChunk(C); + std::set<Defined *> Handlers; + for (ObjectFile *File : Symtab->ObjectFiles) { + if (!File->SEHCompat) + return; + for (SymbolBody *B : File->SEHandlers) + Handlers.insert(cast<Defined>(B->repl())); + } + SEHTable.reset(new SEHTableChunk(Handlers)); + createSection(".rdata")->addChunk(SEHTable.get()); } // Create .idata section for the DLL-imported symbol table. @@ -524,6 +539,13 @@ std::error_code Writer::openFile(StringRef Path) { return std::error_code(); } +void Writer::fixSafeSEHSymbols() { + if (!SEHTable) + return; + Config->SEHTable->setRVA(SEHTable->getRVA()); + Config->SEHCount->setVA(SEHTable->getSize() / 4); +} + // Write section contents to a mmap'ed file. void Writer::writeSections() { uint8_t *Buf = Buffer->getBufferStart(); diff --git a/lld/COFF/Writer.h b/lld/COFF/Writer.h index fdeb28a5941..5af6b3d0660 100644 --- a/lld/COFF/Writer.h +++ b/lld/COFF/Writer.h @@ -89,6 +89,7 @@ private: void createSymbolAndStringTable(); std::error_code openFile(StringRef OutputPath); template <typename PEHeaderTy> void writeHeader(); + void fixSafeSEHSymbols(); void writeSections(); void sortExceptionTable(); void applyRelocations(); @@ -114,6 +115,7 @@ private: IdataContents Idata; DelayLoadContents DelayIdata; EdataContents Edata; + std::unique_ptr<SEHTableChunk> SEHTable; bool Is64; uint64_t FileSize; diff --git a/lld/test/COFF/Inputs/seh.c b/lld/test/COFF/Inputs/seh.c new file mode 100644 index 00000000000..b1c139a58f2 --- /dev/null +++ b/lld/test/COFF/Inputs/seh.c @@ -0,0 +1,13 @@ +__declspec(noinline) void triggerSEH() { + volatile int *p = 0; + *p = 1; +} + +int main() { + __try { + triggerSEH(); + } __except(1) { + return 42; + } + return 0; +} diff --git a/lld/test/COFF/Inputs/seh.obj.yaml b/lld/test/COFF/Inputs/seh.obj.yaml new file mode 100644 index 00000000000..6767671cdaf --- /dev/null +++ b/lld/test/COFF/Inputs/seh.obj.yaml @@ -0,0 +1,387 @@ +--- +header: + Machine: IMAGE_FILE_MACHINE_I386 + Characteristics: [ ] +sections: + - Name: .drectve + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + Alignment: 1 + SectionData: 2020202F44454641554C544C49423A22757569642E6C696222202F44454641554C544C49423A22757569642E6C696222202F4641494C49464D49534D415443483A225F4D53435F5645523D3138303022202F4641494C49464D49534D415443483A225F4954455241544F525F44454255475F4C4556454C3D3022202F4641494C49464D49534D415443483A2252756E74696D654C6962726172793D4D445F44796E616D696352656C6561736522202F44454641554C544C49423A226D73766370727422202F44454641554C544C49423A224D535643525422202F44454641554C544C49423A224F4C444E414D45532220 + - Name: '.debug$S' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 04000000F1000000600000002200011100000000433A5C63796777696E5C686F6D655C727569755C7365682E6F626A003A003C11012200000700120000000D520100120000000D5201004D6963726F736F667420285229204F7074696D697A696E6720436F6D70696C657200 + - Name: .rdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 00 + - Name: .rdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 01 + - Name: .rdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 54726967676572696E672053454820657863657074696F6E0D0A0000457865637574696E6720534548205F5F65786365707420626C6F636B20696E20666F6F0D0A000000457865637574696E6720534548205F5F65786365707420626C6F636B0D0A00 + - Name: '.text$mn' + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 558BEC516800000000FF150000000083C404C745FC000000008B45FCC700140000008BE55DC3CCCCCCCCCCCCCCCCCCCC558BEC51E8000000008D4DFFE8000000008BE55DC3CCCCCCCCCCCCCCCCCCCCCC558BEC6AFE6800000000680000000064A1000000005083EC08535657A1000000003145F833C5508D45F064A3000000008965E8C745FC00000000E800000000C745FCFEFFFFFFEB1EB801000000C38B65E86800000000FF150000000083C404C745FCFEFFFFFF8B4DF064890D00000000595F5E5B8BE55DC3CCCCCCCCCCCCCCCC558BEC6AFE6800000000680000000064A1000000005083EC08535657A1000000003145F833C5508D45F064A3000000008965E8C745FC00000000E800000000E800000000C745FCFEFFFFFFEB1EB801000000C38B65E86800000000FF150000000083C404C745FCFEFFFFFF33C08B4DF064890D00000000595F5E5B8BE55DC3 + Relocations: + - VirtualAddress: 5 + SymbolName: '$SG73531' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 11 + SymbolName: __imp__printf + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 53 + SymbolName: '?TestCPPEX@@YAXXZ' + Type: IMAGE_REL_I386_REL32 + - VirtualAddress: 61 + SymbolName: '??1TestClass@@QAE@XZ' + Type: IMAGE_REL_I386_REL32 + - VirtualAddress: 86 + SymbolName: '__sehtable$?foo@@YAXXZ' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 91 + SymbolName: __except_handler4 + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 109 + SymbolName: ___security_cookie + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 139 + SymbolName: '?TestExceptions@@YAXXZ' + Type: IMAGE_REL_I386_REL32 + - VirtualAddress: 162 + SymbolName: '$SG73539' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 168 + SymbolName: __imp__printf + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 214 + SymbolName: '__sehtable$_main' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 219 + SymbolName: __except_handler4 + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 237 + SymbolName: ___security_cookie + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 267 + SymbolName: '?foo@@YAXXZ' + Type: IMAGE_REL_I386_REL32 + - VirtualAddress: 272 + SymbolName: '?TestExceptions@@YAXXZ' + Type: IMAGE_REL_I386_REL32 + - VirtualAddress: 295 + SymbolName: '$SG73543' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 301 + SymbolName: __imp__printf + Type: IMAGE_REL_I386_DIR32 + - Name: '.text$mn' + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 558BEC51894DFC6800000000FF150000000083C4048BE55DC3 + Relocations: + - VirtualAddress: 8 + SymbolName: '??_C@_0BI@BBHGNMOG@Destroying?5TestClass?$CB?$AN?6?$AA@' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 14 + SymbolName: __imp__printf + Type: IMAGE_REL_I386_DIR32 + - Name: '.xdata$x' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 8 + SectionData: FEFFFFFF00000000D8FFFFFF00000000FEFFFFFF000000000000000000000000FEFFFFFF00000000D8FFFFFF00000000FEFFFFFF0000000000000000 + Relocations: + - VirtualAddress: 20 + SymbolName: '$LN5' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 24 + SymbolName: '$LN6' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 52 + SymbolName: '$LN5' + Type: IMAGE_REL_I386_DIR32 + - VirtualAddress: 56 + SymbolName: '$LN6' + Type: IMAGE_REL_I386_DIR32 + - Name: .rdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 44657374726F79696E672054657374436C617373210D0A00 + - Name: .sxdata + Characteristics: [ IMAGE_SCN_LNK_INFO ] + Alignment: 4 + SectionData: 1B0000001A000000 +symbols: + - Name: '@comp.id' + Value: 14766605 + SectionNumber: 65535 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '@feat.00' + Value: 2147484049 + SectionNumber: 65535 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .drectve + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 240 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: '.debug$S' + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 108 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: .rdata + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 1 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_ANY + - Name: '?value@?$integral_constant@_N$0A@@std@@2_NB' + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: .rdata + Value: 0 + SectionNumber: 4 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 1 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 1996959894 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_ANY + - Name: '?value@?$integral_constant@_N$00@std@@2_NB' + Value: 0 + SectionNumber: 4 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: .rdata + Value: 0 + SectionNumber: 5 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 99 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 2801625422 + Number: 0 + - Name: '$SG73531' + Value: 0 + SectionNumber: 5 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '$SG73539' + Value: 28 + SectionNumber: 5 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '$SG73543' + Value: 68 + SectionNumber: 5 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '.text$mn' + Value: 0 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 335 + NumberOfRelocations: 17 + NumberOfLinenumbers: 0 + CheckSum: 2488225337 + Number: 0 + - Name: '.text$mn' + Value: 0 + SectionNumber: 7 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 25 + NumberOfRelocations: 2 + NumberOfLinenumbers: 0 + CheckSum: 210566957 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_ANY + - Name: __imp__printf + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: '??1TestClass@@QAE@XZ' + Value: 0 + SectionNumber: 7 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: '?TestCPPEX@@YAXXZ' + Value: 0 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: '?TestExceptions@@YAXXZ' + Value: 48 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: '?foo@@YAXXZ' + Value: 80 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: _main + Value: 208 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __except_handler4 + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: '$LN5' + Value: 152 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_LABEL + - Name: '$LN7' + Value: 157 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_LABEL + - Name: '$LN6' + Value: 158 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_LABEL + - Name: '$LN5' + Value: 285 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_LABEL + - Name: '$LN7' + Value: 290 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_LABEL + - Name: '$LN6' + Value: 291 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_LABEL + - Name: '.xdata$x' + Value: 0 + SectionNumber: 8 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 60 + NumberOfRelocations: 4 + NumberOfLinenumbers: 0 + CheckSum: 2900129504 + Number: 0 + - Name: '__sehtable$?foo@@YAXXZ' + Value: 32 + SectionNumber: 8 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '__sehtable$_main' + Value: 0 + SectionNumber: 8 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .rdata + Value: 0 + SectionNumber: 9 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 24 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 1296623929 + Number: 0 + Selection: IMAGE_COMDAT_SELECT_ANY + - Name: '??_C@_0BI@BBHGNMOG@Destroying?5TestClass?$CB?$AN?6?$AA@' + Value: 0 + SectionNumber: 9 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: ___security_cookie + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: .sxdata + Value: 0 + SectionNumber: 10 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 4 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 +... diff --git a/lld/test/COFF/seh.test b/lld/test/COFF/seh.test new file mode 100644 index 00000000000..2082aad1e35 --- /dev/null +++ b/lld/test/COFF/seh.test @@ -0,0 +1,24 @@ +# RUN: yaml2obj %p/Inputs/seh.obj.yaml > %t.obj +# +# RUN: lld -flavor link /out:%t.exe /subsystem:console /force /nodefaultlib %t.obj +# RUN: llvm-objdump -private-headers %t.exe | FileCheck %s + +CHECK: Load configuration: +CHECK: Timestamp: 0 +CHECK: Major Version: 0 +CHECK: Minor Version: 0 +CHECK: GlobalFlags Clear: 0 +CHECK: GlobalFlags Set: 0 +CHECK: Critical Section Default Timeout: 0 +CHECK: Decommit Free Block Threshold: 0 +CHECK: Decommit Total Free Threshold: 0 +CHECK: Lock Prefix Table: 0 +CHECK: Maximum Allocation Size: 0 +CHECK: Virtual Memory Threshold: 0 +CHECK: Process Affinity Mask: 0 +CHECK: Process Heap Flags: 0 +CHECK: CSD Version: 0 +CHECK: Security Cookie: 0 +CHECK: SEH Table: 4206592 +CHECK: SEH Count: 2 +CHECK: SEH Table: 0x80001b 0x8040ea |