llvm.org GIT mirror llvm / c75b449
[COFF] Emit @feat.00 on 64-bit and set the CFG bit when emitting guardcf tables The 0x800 bit in @feat.00 needs to be set in order to make LLD pick up the .gfid$y table. I believe this is fine to set even if we don't emit the instrumentation. We haven't emitted @feat.00 on 64-bit before. I see that MSVC does emit it, but I'm not entirely sure what the default value should be. I went with zero since that seems as safe as not emitting the symbol in the first place. Differential Revision: https://reviews.llvm.org/D52235 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342532 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 1 year, 9 months ago
2 changed file(s) with 18 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
586586 if (TT.isOSBinFormatCOFF()) {
587587 // Emit an absolute @feat.00 symbol. This appears to be some kind of
588588 // compiler features bitfield read by link.exe.
589 MCSymbol *S = MMI->getContext().getOrCreateSymbol(StringRef("@feat.00"));
590 OutStreamer->BeginCOFFSymbolDef(S);
591 OutStreamer->EmitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_STATIC);
592 OutStreamer->EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_NULL);
593 OutStreamer->EndCOFFSymbolDef();
594 int64_t Feat00Flags = 0;
595
589596 if (TT.getArch() == Triple::x86) {
590 MCSymbol *S = MMI->getContext().getOrCreateSymbol(StringRef("@feat.00"));
591 OutStreamer->BeginCOFFSymbolDef(S);
592 OutStreamer->EmitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_STATIC);
593 OutStreamer->EmitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_NULL);
594 OutStreamer->EndCOFFSymbolDef();
595597 // According to the PE-COFF spec, the LSB of this value marks the object
596598 // for "registered SEH". This means that all SEH handler entry points
597599 // must be registered in .sxdata. Use of any unregistered handlers will
598600 // cause the process to terminate immediately. LLVM does not know how to
599601 // register any SEH handlers, so its object files should be safe.
600 OutStreamer->EmitSymbolAttribute(S, MCSA_Global);
601 OutStreamer->EmitAssignment(
602 S, MCConstantExpr::create(int64_t(1), MMI->getContext()));
603 }
602 Feat00Flags |= 1;
603 }
604
605 if (M.getModuleFlag("cfguardtable"))
606 Feat00Flags |= 0x800; // Object is CFG-aware.
607
608 OutStreamer->EmitSymbolAttribute(S, MCSA_Global);
609 OutStreamer->EmitAssignment(
610 S, MCConstantExpr::create(Feat00Flags, MMI->getContext()));
604611 }
605612 OutStreamer->EmitSyntaxDirective();
606613
0 ; RUN: llc < %s | FileCheck %s
1
2 ; CHECK: .set @feat.00, 2048
13
24 ; CHECK: .section .gfids$y
35 ; CHECK: .symidx "?address_taken@@YAXXZ"