[PATCH] D145268: [lld-macho] Fix default LTO triple

Keith Smiley via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 3 12:39:46 PST 2023


keith created this revision.
Herald added subscribers: ormris, steven_wu, hiraditya, inglorion.
Herald added projects: lld-macho, All.
Herald added a reviewer: lld-macho.
keith requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

In the case you pass -object_path_lto without any IR files, the LTO
infrastructure attempts to derive the default triple and fails if none
is found. This sets the default triple to the one we've derived from
-platform_version / -arch.

Fixes https://github.com/llvm/llvm-project/issues/61031


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145268

Files:
  lld/MachO/LTO.cpp
  lld/test/MachO/lto-object-path.ll


Index: lld/test/MachO/lto-object-path.ll
===================================================================
--- lld/test/MachO/lto-object-path.ll
+++ lld/test/MachO/lto-object-path.ll
@@ -2,12 +2,17 @@
 ; UNSUPPORTED: system-windows
 
 ; RUN: rm -rf %t; mkdir %t
+; RUN: llc -filetype=obj %s -o %t/test-obj.o
 ; RUN: opt -thinlto-bc %s -o %t/test.o
 ; RUN: opt %s -o %t/test-nonthin.o
 
 ; RUN: %lld %t/test.o -o %t/test
 ; RUN: llvm-nm -pa %t/test | FileCheck %s --check-prefixes CHECK,NOOBJPATH
 
+; RUN: %lld %t/test-obj.o -o %t/test-obj -object_path_lto %t/lto-temps-obj
+; RUN: llvm-nm -pa %t/test-obj | FileCheck %s --check-prefixes CHECK,NOLTOPATH -DDIR=%t
+; RUN: llvm-otool -l %t/lto-temps-obj/0.x86_64.lto.o | FileCheck %s --check-prefixes=MINOS-DEFAULT
+
 ; RUN: ZERO_AR_DATE=0 %lld %t/test.o -o %t/test -object_path_lto %t/lto-temps
 ; RUN: llvm-nm -pa %t/test | FileCheck %s --check-prefixes CHECK,OBJPATH-DIR -DDIR=%t/lto-temps
 
@@ -31,10 +36,12 @@
 ; RUN: touch %t/lto-tmp.o
 ; RUN: ZERO_AR_DATE=0 %lld %t/test-nonthin.o -o %t/test -object_path_lto %t/lto-tmp.o
 ; RUN: llvm-nm -pa %t/test | FileCheck %s --check-prefixes CHECK,OBJPATH-FILE -DFILE=%t/lto-tmp.o
+; RUN: llvm-otool -l %t/lto-tmp.o | FileCheck %s --check-prefixes=MINOS
 
 
 ; CHECK:             0000000000000000                - 00 0000    SO /tmp/test.cpp
 ; NOOBJPATH-NEXT:    0000000000000000                - 03 0001   OSO /tmp/lto.tmp
+; NOLTOPATH-NEXT:    0000000000000000                - 03 0001   OSO [[DIR]]/test-obj.o
 ;; check that modTime is nonzero when `-object_path_lto` is provided
 ; OBJPATH-DIR-NEXT:  {{[0-9a-f]*[1-9a-f]+[0-9a-f]*}} - 03 0001   OSO [[DIR]]/1.x86_64.lto.o
 ; OBJPATH-FILE-NEXT: {{[0-9a-f]*[1-9a-f]+[0-9a-f]*}} - 03 0001   OSO [[FILE]]
@@ -45,6 +52,9 @@
 ; DSYM: DW_AT_name ("test.cpp")
 ; HARDLINK: 2
 
+; MINOS: 10.15
+; MINOS-DEFAULT: 11.0
+
 target triple = "x86_64-apple-macosx10.15.0"
 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
 
Index: lld/MachO/LTO.cpp
===================================================================
--- lld/MachO/LTO.cpp
+++ lld/MachO/LTO.cpp
@@ -59,6 +59,7 @@
     c.MllvmArgs.emplace_back(C.str());
   c.CodeModel = getCodeModelFromCMModel();
   c.CPU = getCPUStr();
+  c.DefaultTriple = getTargetTripleName(config->platformInfo.target);
   c.MAttrs = getMAttrs();
   c.DiagHandler = diagnosticHandler;
   c.PreCodeGenPassesHook = [](legacy::PassManager &pm) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145268.502227.patch
Type: text/x-patch
Size: 2461 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230303/d0763b88/attachment.bin>


More information about the llvm-commits mailing list