| ... | ... | @@ -33,6 +33,7 @@ |
| 33 | 33 | #include "llvm/MC/MCParser/MCAsmParser.h" |
| 34 | 34 | #include "llvm/MC/MCParser/MCTargetAsmParser.h" |
| 35 | 35 | #include "llvm/MC/MCRegisterInfo.h" |
| 36 | #include "llvm/MC/MCSectionMachO.h" |
| 36 | 37 | #include "llvm/MC/MCStreamer.h" |
| 37 | 38 | #include "llvm/MC/MCSubtargetInfo.h" |
| 38 | 39 | #include "llvm/MC/MCTargetOptions.h" |
| ... | ... | @@ -132,6 +133,7 @@ struct AssemblerInvocation { |
| 132 | 133 | unsigned NoExecStack : 1; |
| 133 | 134 | unsigned FatalWarnings : 1; |
| 134 | 135 | unsigned IncrementalLinkerCompatible : 1; |
| 136 | unsigned EmbedBitcode : 1; |
| 135 | 137 | |
| 136 | 138 | /// The name of the relocation model to use. |
| 137 | 139 | std::string RelocationModel; |
| ... | ... | @@ -153,6 +155,7 @@ public: |
| 153 | 155 | FatalWarnings = 0; |
| 154 | 156 | IncrementalLinkerCompatible = 0; |
| 155 | 157 | DwarfVersion = 0; |
| 158 | EmbedBitcode = 0; |
| 156 | 159 | } |
| 157 | 160 | |
| 158 | 161 | static bool CreateFromArgs(AssemblerInvocation &Res, |
| ... | ... | @@ -284,6 +287,16 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, |
| 284 | 287 | Args.hasArg(OPT_mincremental_linker_compatible); |
| 285 | 288 | Opts.SymbolDefs = Args.getAllArgValues(OPT_defsym); |
| 286 | 289 | |
| 290 | // EmbedBitcode Option. If -fembed-bitcode is enabled, set the flag. |
| 291 | // EmbedBitcode behaves the same for all embed options for assembly files. |
| 292 | if (auto *A = Args.getLastArg(OPT_fembed_bitcode_EQ)) { |
| 293 | Opts.EmbedBitcode = llvm::StringSwitch<unsigned>(A->getValue()) |
| 294 | .Case("all", 1) |
| 295 | .Case("bitcode", 1) |
| 296 | .Case("marker", 1) |
| 297 | .Default(0); |
| 298 | } |
| 299 | |
| 287 | 300 | return Success; |
| 288 | 301 | } |
| 289 | 302 | |
| ... | ... | @@ -449,6 +462,16 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 449 | 462 | Str.get()->InitSections(Opts.NoExecStack); |
| 450 | 463 | } |
| 451 | 464 | |
| 465 | // When -fembed-bitcode is passed to clang_as, a 1-byte marker |
| 466 | // is emitted in __LLVM,__asm section if the object file is MachO format. |
| 467 | if (Opts.EmbedBitcode && Ctx.getObjectFileInfo()->getObjectFileType() == |
| 468 | MCObjectFileInfo::IsMachO) { |
| 469 | MCSection *AsmLabel = Ctx.getMachOSection( |
| 470 | "__LLVM", "__asm", MachO::S_REGULAR, 4, SectionKind::getReadOnly()); |
| 471 | Str.get()->SwitchSection(AsmLabel); |
| 472 | Str.get()->EmitZeros(1); |
| 473 | } |
| 474 | |
| 452 | 475 | // Assembly to object compilation should leverage assembly info. |
| 453 | 476 | Str->setUseAssemblerInfoForParsing(true); |
| 454 | 477 | |
| ... | ... | @@ -534,7 +557,8 @@ int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
| 534 | 557 | |
| 535 | 558 | if (Asm.ShowHelp) { |
| 536 | 559 | std::unique_ptr<OptTable> Opts(driver::createDriverOptTable()); |
| 537 | | Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler", |
| 560 | Opts->PrintHelp(llvm::outs(), "clang -cc1as [options] file...", |
| 561 | "Clang Integrated Assembler", |
| 538 | 562 | /*Include=*/driver::options::CC1AsOption, /*Exclude=*/0, |
| 539 | 563 | /*ShowAllAliases=*/false); |
| 540 | 564 | return 0; |