[PATCH] D155716: [clang][CodeGen] Introduce `-frecord-command-line` for MachO

Antonio Frighetto via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 20 06:15:47 PDT 2023


antoniofrighetto updated this revision to Diff 542483.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155716/new/

https://reviews.llvm.org/D155716

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/clang_f_opts.c
  llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/test/CodeGen/AArch64/commandline-metadata.ll


Index: llvm/test/CodeGen/AArch64/commandline-metadata.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AArch64/commandline-metadata.ll
@@ -0,0 +1,24 @@
+; RUN: llc -mtriple=arm64-linux-gnu < %s | FileCheck %s
+; RUN: llc -mtriple=arm64-apple-darwin < %s | FileCheck %s --check-prefix=CHECK-MACHO
+
+; Verify that llvm.commandline metadata is emitted to the corresponding command line section.
+
+; CHECK:              .text
+; CHECK:              .section .GCC.command.line,"MS", at progbits,1
+; CHECK-NEXT:         .zero 1
+; CHECK-NEXT:         .ascii "clang -command1"
+; CHECK-NEXT:         .zero 1
+; CHECK-NEXT:         .ascii "clang -command2"
+; CHECK-NEXT:         .zero 1
+
+; CHECK-MACHO:        .section	__TEXT,__text,regular,pure_instructions
+; CHECK-MACHO-NEXT:   .section	__TEXT,__command_line
+; CHECK-MACHO-NEXT:   .space	1
+; CHECK-MACHO-NEXT:   .ascii	"clang -command1"
+; CHECK-MACHO-NEXT:   .space	1
+; CHECK-MACHO-NEXT:   .ascii	"clang -command2"
+; CHECK-MACHO-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/test/Driver/clang_f_opts.c
===================================================================
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -541,7 +541,7 @@
 // RUN: %clang -### -S -target x86_64-unknown-linux -fno-record-command-line -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
 // RUN: %clang -### -S -target x86_64-unknown-linux -frecord-command-line -fno-record-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
 // Test with a couple examples of non-ELF object file formats
-// RUN: %clang -### -S -target x86_64-unknown-macosx -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES-ERROR %s
+// RUN: %clang -### -S -target x86_64-unknown-macosx -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
 // RUN: %clang -### -S -target x86_64-unknown-windows -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES-ERROR %s
 // CHECK-RECORD-GCC-SWITCHES: "-record-command-line"
 // CHECK-NO-RECORD-GCC-SWITCHES-NOT: "-record-command-line"
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.542483.patch
Type: text/x-patch
Size: 4232 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230720/e09f44de/attachment.bin>


More information about the llvm-commits mailing list