Skip to content

Commit 6e92f46

Browse files
committed
[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
1 parent 1aafaac commit 6e92f46

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

lld/MachO/Driver.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,6 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
827827
symtab->addDynamicLookup(arg->getValue());
828828

829829
config->outputFile = args.getLastArgValue(OPT_o, "a.out");
830-
config->installName =
831-
args.getLastArgValue(OPT_install_name, config->outputFile);
832830
config->headerPad = args::getHex(args, OPT_headerpad, /*Default=*/32);
833831
config->headerPadMaxInstallNames =
834832
args.hasArg(OPT_headerpad_max_install_names);
@@ -850,6 +848,15 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
850848
config->demangle = args.hasArg(OPT_demangle);
851849
config->implicitDylibs = !args.hasArg(OPT_no_implicit_dylibs);
852850

851+
if (const Arg *arg = args.getLastArg(OPT_install_name)) {
852+
if (config->outputType != MH_DYLIB)
853+
warn(arg->getAsString(args) + ": ignored, only has effect with -dylib");
854+
else
855+
config->installName = arg->getValue();
856+
} else if (config->outputType == MH_DYLIB) {
857+
config->installName = config->outputFile;
858+
}
859+
853860
if (args.hasArg(OPT_mark_dead_strippable_dylib)) {
854861
if (config->outputType != MH_DYLIB)
855862
warn("-mark_dead_strippable_dylib: ignored, only has effect with -dylib");

lld/test/MachO/install-name.s

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# REQUIRES: x86
2+
3+
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t.o %s
4+
5+
# RUN: %no_fatal_warnings_lld -o %t.exec %t.o -install_name foo 2>&1 \
6+
# RUN: | FileCheck --check-prefix=WARN %s
7+
# RUN: llvm-objdump --macho --all-headers %t.exec \
8+
# RUN: | FileCheck --check-prefix=NO-ID %s
9+
10+
# RUN: %no_fatal_warnings_lld -bundle -o %t.bundle %t.o -install_name foo 2>&1 \
11+
# RUN: | FileCheck --check-prefix=WARN %s
12+
# RUN: llvm-objdump --macho --all-headers %t.bundle \
13+
# RUN: | FileCheck --check-prefix=NO-ID %s
14+
15+
# RUN: %lld -dylib -o %t.dylib %t.o -install_name foo 2>&1
16+
# RUN: llvm-objdump --macho --all-headers %t.dylib \
17+
# RUN: | FileCheck --check-prefix=ID %s
18+
19+
# WARN: warning: -install_name foo: ignored, only has effect with -dylib
20+
21+
# NO-ID-NOT: LC_ID_DYLIB
22+
23+
# ID: cmd LC_ID_DYLIB
24+
# ID-NEXT: cmdsize
25+
# LID-NEXT: name foo
26+
27+
.globl _main
28+
_main:
29+
ret

0 commit comments

Comments
 (0)