Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -7179,7 +7179,7 @@ Args.hasFlag(options::OPT_frecord_command_line, options::OPT_fno_record_command_line, false); if (FRecordSwitches && !Triple.isOSBinFormatELF() && - !Triple.isOSBinFormatXCOFF()) + !Triple.isOSBinFormatXCOFF() && !Triple.isOSBinFormatMachO()) D.Diag(diag::err_drv_unsupported_opt_for_target) << Args.getLastArg(options::OPT_frecord_command_line)->getAsString(Args) << TripleStr; Index: llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h =================================================================== --- llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h +++ llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h @@ -156,6 +156,8 @@ void getNameWithPrefix(SmallVectorImpl &OutName, const GlobalValue *GV, const TargetMachine &TM) const override; + + MCSection *getSectionForCommandLines() const override; }; class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile { Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp =================================================================== --- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1420,6 +1420,11 @@ return ReadOnlySection; // .const } +MCSection *TargetLoweringObjectFileMachO::getSectionForCommandLines() const { + return getContext().getMachOSection("__TEXT", "__command_line", 0, + SectionKind::getReadOnly()); +} + const MCExpr *TargetLoweringObjectFileMachO::getTTypeGlobalReference( const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const { Index: llvm/test/CodeGen/AArch64/arm64-command-line-metadata.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/AArch64/arm64-command-line-metadata.ll @@ -0,0 +1,15 @@ +; RUN: llc -mtriple=aarch64-apple-darwin < %s | FileCheck %s +; Verify that llvm.commandline metadata is emitted to a +; MachO section named __command_line within __TEXT segment. + +; CHECK: .section __TEXT,__text,regular,pure_instructions +; CHECK-NEXT: .section __TEXT,__command_line +; CHECK-NEXT: .space 1 +; CHECK-NEXT: .ascii "clang -command1" +; CHECK-NEXT: .space 1 +; CHECK-NEXT: .ascii "clang -command2" +; CHECK-NEXT: .space 1 + +!llvm.commandline = !{!0, !1} +!0 = !{!"clang -command1"} +!1 = !{!"clang -command2"}