diff options
| author | Hans Wennborg <hans@hanshq.net> | 2017-04-21 21:48:41 +0000 |
|---|---|---|
| committer | Hans Wennborg <hans@hanshq.net> | 2017-04-21 21:48:41 +0000 |
| commit | 9b9a5358dd35d63f83a54256aaf44e0c3cffdde2 (patch) | |
| tree | 28c4dbdc7d5f57afa287534e4878890cdb5b8a13 /llvm/lib/CodeGen/AsmPrinter | |
| parent | 5b0887025bbc3ded0a4a65adc34d7a07f76b6c77 (diff) | |
| download | bcm5719-llvm-9b9a5358dd35d63f83a54256aaf44e0c3cffdde2.tar.gz bcm5719-llvm-9b9a5358dd35d63f83a54256aaf44e0c3cffdde2.zip | |
Re-commit r301040 "X86: Don't emit zero-byte functions on Windows"
In addition to the original commit, tighten the condition for when to
pad empty functions to COFF Windows. This avoids running into problems
when targeting e.g. Win32 AMDGPU, which caused test failures when this
was committed initially.
llvm-svn: 301047
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter')
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 028c79f3ab6..58416a0334a 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1046,15 +1046,18 @@ void AsmPrinter::EmitFunctionBody() { // If the function is empty and the object file uses .subsections_via_symbols, // then we need to emit *something* to the function body to prevent the // labels from collapsing together. Just emit a noop. - if ((MAI->hasSubsectionsViaSymbols() && !HasAnyRealCode)) { + // Similarly, don't emit empty functions on Windows either. It can lead to + // duplicate entries (two functions with the same RVA) in the Guard CF Table + // after linking, causing the kernel not to load the binary: + // https://developercommunity.visualstudio.com/content/problem/45366/vc-linker-creates-invalid-dll-with-clang-cl.html + // FIXME: Hide this behind some API in e.g. MCAsmInfo or MCTargetStreamer. + const Triple &TT = TM.getTargetTriple(); + if (!HasAnyRealCode && (MAI->hasSubsectionsViaSymbols() || + (TT.isOSWindows() && TT.isOSBinFormatCOFF()))) { MCInst Noop; - MF->getSubtarget().getInstrInfo()->getNoopForMachoTarget(Noop); + MF->getSubtarget().getInstrInfo()->getNoop(Noop); OutStreamer->AddComment("avoids zero-length function"); - - // Targets can opt-out of emitting the noop here by leaving the opcode - // unspecified. - if (Noop.getOpcode()) - OutStreamer->EmitInstruction(Noop, getSubtargetInfo()); + OutStreamer->EmitInstruction(Noop, getSubtargetInfo()); } const Function *F = MF->getFunction(); |

