diff options
author | Steven Wu <stevenwu@apple.com> | 2018-12-12 17:30:16 +0000 |
---|---|---|
committer | Steven Wu <stevenwu@apple.com> | 2018-12-12 17:30:16 +0000 |
commit | fc109152eabcbc013d152e0a9599c4422f58203c (patch) | |
tree | ece73e7a4a0e254a5a0c915c422164994524d07a /tools | |
parent | bbecc2dcf078e7f40a97f1c040bb49856c62aeb9 (diff) |
[Driver] Add support for -fembed-bitcode for assembly file
Summary:
Handle -fembed-bitcode for assembly inputs. When the input file is
assembly, write a marker as "__LLVM,__asm" section.
Fix llvm.org/pr39659
Reviewers: compnerd, dexonsmith
Reviewed By: compnerd
Subscribers: rjmccall, dblaikie, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D55525
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348943 91177308-0d34-0410-b5e6-96231b3b80d8
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); |