[lld] 6e92f46 - [lld/mac] warn on -install_name without -dylib
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 10 06:14:17 PST 2021
Author: Nico Weber
Date: 2021-03-10T09:05:44-05:00
New Revision: 6e92f468c82bac06051675fa94f72ca2789d2bc0
URL: https://github.com/llvm/llvm-project/commit/6e92f468c82bac06051675fa94f72ca2789d2bc0
DIFF: https://github.com/llvm/llvm-project/commit/6e92f468c82bac06051675fa94f72ca2789d2bc0.diff
LOG: [lld/mac] warn on -install_name without -dylib
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.
Differential Revision: https://reviews.llvm.org/D98259
Added:
lld/test/MachO/install-name.s
Modified:
lld/MachO/Driver.cpp
Removed:
################################################################################
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index b53ac2ebbd7e..ccef589104b5 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -827,8 +827,6 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
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);
@@ -850,6 +848,15 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
config->demangle = args.hasArg(OPT_demangle);
config->implicitDylibs = !args.hasArg(OPT_no_implicit_dylibs);
+ if (const 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 (args.hasArg(OPT_mark_dead_strippable_dylib)) {
if (config->outputType != MH_DYLIB)
warn("-mark_dead_strippable_dylib: ignored, only has effect with -dylib");
diff --git a/lld/test/MachO/install-name.s b/lld/test/MachO/install-name.s
new file mode 100644
index 000000000000..645679262a62
--- /dev/null
+++ b/lld/test/MachO/install-name.s
@@ -0,0 +1,29 @@
+# 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
More information about the llvm-commits
mailing list