diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -21,6 +21,7 @@ #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" +#include "llvm/BinaryFormat/COFF.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/DebugInfo/CodeView/SymbolRecord.h" #include "llvm/MC/MCAsmInfo.h" @@ -884,9 +885,36 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) { // Create the initial section, if requested. - if (!NoInitialTextSection) + if (!NoInitialTextSection) { Out.InitSections(false); + if (Ctx.getObjectFileInfo()->getObjectFileType() == + MCObjectFileInfo::IsCOFF) { + // Emit an absolute @feat.00 symbol. This appears to be some kind of + // compiler features bitfield read by link.exe. + MCSymbol *Feat00Sym = getContext().getOrCreateSymbol("@feat.00"); + getStreamer().BeginCOFFSymbolDef(Feat00Sym); + getStreamer().EmitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_STATIC); + getStreamer().EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_NULL); + getStreamer().EndCOFFSymbolDef(); + int64_t Feat00Flags = 0; + + if (getContext().getObjectFileInfo()->getTargetTriple().getArch() == + Triple::x86) { + // According to the PE-COFF spec, the LSB of this value marks the object + // for "registered SEH". This means that all SEH handler entry points + // must be registered in .sxdata. Use of any unregistered handlers will + // cause the process to terminate immediately. LLVM does not know how + // to register any SEH handlers, so its object files should be safe. + Feat00Flags |= 1; + } + + getStreamer().EmitSymbolAttribute(Feat00Sym, MCSA_Global); + getStreamer().EmitAssignment( + Feat00Sym, MCConstantExpr::create(Feat00Flags, getContext())); + } + } + // Prime the lexer. Lex();