[PATCH] D98259: [lld/mac] warn on -install_name without -dylib

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 9 07:05:10 PST 2021


thakis created this revision.
thakis added a reviewer: lld-macho.
Herald added a reviewer: int3.
Herald added a project: lld-macho.
thakis requested review of this revision.

The flag doesn't (and shouldn't) have an effect in that case.
ld64 doesn't warn on this, but it seems like a good thing to do.
If it causes problems in practice for some reason, we can revert it.

Also add a dedicated test for install_name.


https://reviews.llvm.org/D98259

Files:
  lld/MachO/Driver.cpp
  lld/test/MachO/install-name.s


Index: lld/test/MachO/install-name.s
===================================================================
--- /dev/null
+++ lld/test/MachO/install-name.s
@@ -0,0 +1,30 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t.o %s
+
+# RUN: %no_fatal_warnings_lld -o %t.exec %t.o -install_name foo 2>&1 \
+# RUN:     | FileCheck --check-prefix=WARN %s
+# RUN: llvm-objdump --macho --all-headers %t.exec \
+# RUN:     | FileCheck --check-prefix=NO-ID %s
+
+# RUN: %no_fatal_warnings_lld -bundle -o %t.bundle %t.o -install_name foo 2>&1 \
+# RUN:     | FileCheck --check-prefix=WARN %s
+# RUN: llvm-objdump --macho --all-headers %t.bundle \
+# RUN:     | FileCheck --check-prefix=NO-ID %s
+
+# RUN: %lld -dylib -o %t.dylib %t.o -install_name foo 2>&1
+# RUN: llvm-objdump --macho --all-headers %t.dylib \
+# RUN:     | FileCheck --check-prefix=ID %s
+
+# WARN: warning: -install_name foo: ignored, only has effect with -dylib
+
+# NO-ID-NOT: LC_ID_DYLIB
+
+# ID:          cmd LC_ID_DYLIB
+# ID-NEXT: cmdsize
+# LID-NEXT:   name foo
+
+
+.globl _main
+_main:
+  ret
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -777,8 +777,7 @@
     symtab->addDynamicLookup(arg->getValue());
 
   config->outputFile = args.getLastArgValue(OPT_o, "a.out");
-  config->installName =
-      args.getLastArgValue(OPT_install_name, config->outputFile);
+
   config->headerPad = args::getHex(args, OPT_headerpad, /*Default=*/32);
   config->headerPadMaxInstallNames =
       args.hasArg(OPT_headerpad_max_install_names);
@@ -800,6 +799,15 @@
   config->demangle = args.hasArg(OPT_demangle);
   config->implicitDylibs = !args.hasArg(OPT_no_implicit_dylibs);
 
+  if (const opt::Arg *arg = args.getLastArg(OPT_install_name)) {
+    if (config->outputType != MH_DYLIB)
+      warn(arg->getAsString(args) + ": ignored, only has effect with -dylib");
+    else
+      config->installName = arg->getValue();
+  } else if (config->outputType == MH_DYLIB) {
+    config->installName = config->outputFile;
+  }
+
   if (const opt::Arg *arg = args.getLastArg(OPT_static, OPT_dynamic))
     config->staticLink = (arg->getOption().getID() == OPT_static);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98259.329326.patch
Type: text/x-patch
Size: 2250 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210309/101ffc55/attachment.bin>


More information about the llvm-commits mailing list