diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/driver/cc1as_main.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tools/driver/cc1as_main.cpp b/tools/driver/cc1as_main.cpp index 9e454cdd0f..be4f174ed4 100644 --- a/tools/driver/cc1as_main.cpp +++ b/tools/driver/cc1as_main.cpp @@ -33,6 +33,7 @@ #include "llvm/MC/MCParser/MCAsmParser.h" #include "llvm/MC/MCParser/MCTargetAsmParser.h" #include "llvm/MC/MCRegisterInfo.h" +#include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCTargetOptions.h" @@ -132,6 +133,7 @@ struct AssemblerInvocation { unsigned NoExecStack : 1; unsigned FatalWarnings : 1; unsigned IncrementalLinkerCompatible : 1; + unsigned EmbedBitcode : 1; /// The name of the relocation model to use. std::string RelocationModel; @@ -153,6 +155,7 @@ public: FatalWarnings = 0; IncrementalLinkerCompatible = 0; DwarfVersion = 0; + EmbedBitcode = 0; } static bool CreateFromArgs(AssemblerInvocation &Res, @@ -284,6 +287,16 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, Args.hasArg(OPT_mincremental_linker_compatible); Opts.SymbolDefs = Args.getAllArgValues(OPT_defsym); + // EmbedBitcode Option. If -fembed-bitcode is enabled, set the flag. + // EmbedBitcode behaves the same for all embed options for assembly files. + if (auto *A = Args.getLastArg(OPT_fembed_bitcode_EQ)) { + Opts.EmbedBitcode = llvm::StringSwitch<unsigned>(A->getValue()) + .Case("all", 1) + .Case("bitcode", 1) + .Case("marker", 1) + .Default(0); + } + return Success; } @@ -449,6 +462,16 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, Str.get()->InitSections(Opts.NoExecStack); } + // When -fembed-bitcode is passed to clang_as, a 1-byte marker + // is emitted in __LLVM,__asm section if the object file is MachO format. + if (Opts.EmbedBitcode && Ctx.getObjectFileInfo()->getObjectFileType() == + MCObjectFileInfo::IsMachO) { + MCSection *AsmLabel = Ctx.getMachOSection( + "__LLVM", "__asm", MachO::S_REGULAR, 4, SectionKind::getReadOnly()); + Str.get()->SwitchSection(AsmLabel); + Str.get()->EmitZeros(1); + } + // Assembly to object compilation should leverage assembly info. Str->setUseAssemblerInfoForParsing(true); |