[PATCH] D155716: [clang][CodeGen] Introduce `-frecord-command-line` for MachO
Antonio Frighetto via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 19 08:26:24 PDT 2023
antoniofrighetto created this revision.
antoniofrighetto added reviewers: davide, ab, scott.linder.
Herald added a subscriber: hiraditya.
Herald added a project: All.
antoniofrighetto requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.
Allow clang driver command-line recording when targeting MachO object files as well.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D155716
Files:
clang/lib/Driver/ToolChains/Clang.cpp
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/test/CodeGen/AArch64/arm64-command-line-metadata.ll
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"}
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/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
===================================================================
--- llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
+++ llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
@@ -156,6 +156,8 @@
void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
const TargetMachine &TM) const override;
+
+ MCSection *getSectionForCommandLines() const override;
};
class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155716.542041.patch
Type: text/x-patch
Size: 2717 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230719/d88bf68d/attachment.bin>
More information about the llvm-commits
mailing list