[lld] adfbb54 - [lld-macho] Add warn flags to enable/disable warnings on -install_name

Vincent Lee via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 17 16:18:34 PST 2021


Author: Vincent Lee
Date: 2021-11-17T16:18:14-08:00
New Revision: adfbb5411b0b0461c230b51623c9128e0ccc60c9

URL: https://github.com/llvm/llvm-project/commit/adfbb5411b0b0461c230b51623c9128e0ccc60c9
DIFF: https://github.com/llvm/llvm-project/commit/adfbb5411b0b0461c230b51623c9128e0ccc60c9.diff

LOG: [lld-macho] Add warn flags to enable/disable warnings on -install_name

ld64 doesn't warn on builds using `-install_name` if it's a bundle. But, the
current warning is nice to have because `install_name` only works with dylib.
To prevent an overflow of warnings in build logs and have parity with ld64,
create a `--warn-dylib-install-name` and `--warn-no-dylib-install-name` flag
that enables this LLD specific warning.

Reviewed By: #lld-macho, thakis

Differential Revision: https://reviews.llvm.org/D113534

Added: 
    

Modified: 
    lld/MachO/Config.h
    lld/MachO/Driver.cpp
    lld/MachO/Options.td
    lld/test/MachO/install-name.s

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index 090eb7a28cf9a..42528185e57c7 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -122,6 +122,7 @@ struct Configuration {
   bool dataConst = false;
   bool dedupLiterals = true;
   bool omitDebugInfo = false;
+  bool warnDylibInstallName = false;
   uint32_t headerPad;
   uint32_t dylibCompatibilityVersion = 0;
   uint32_t dylibCurrentVersion = 0;

diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 7cce6cd3bc351..e9d65d3c73f2f 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1264,6 +1264,8 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
   config->icfLevel = getICFLevel(args);
   config->dedupLiterals = args.hasArg(OPT_deduplicate_literals) ||
                           config->icfLevel != ICFLevel::none;
+  config->warnDylibInstallName = args.hasFlag(
+      OPT_warn_dylib_install_name, OPT_no_warn_dylib_install_name, false);
 
   // FIXME: Add a commandline flag for this too.
   config->zeroModTime = getenv("ZERO_AR_DATE");
@@ -1280,8 +1282,10 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
 #endif
 
   if (const Arg *arg = args.getLastArg(OPT_install_name)) {
-    if (config->outputType != MH_DYLIB)
-      warn(arg->getAsString(args) + ": ignored, only has effect with -dylib");
+    if (config->warnDylibInstallName && config->outputType != MH_DYLIB)
+      warn(
+          arg->getAsString(args) +
+          ": ignored, only has effect with -dylib [--warn-dylib-install-name]");
     else
       config->installName = arg->getValue();
   } else if (config->outputType == MH_DYLIB) {

diff  --git a/lld/MachO/Options.td b/lld/MachO/Options.td
index f4eb302a95b77..7cd4d01a0a5a6 100644
--- a/lld/MachO/Options.td
+++ b/lld/MachO/Options.td
@@ -73,6 +73,12 @@ def thinlto_cache_policy: Joined<["--"], "thinlto-cache-policy=">,
     Group<grp_lld>;
 def O : JoinedOrSeparate<["-"], "O">,
     HelpText<"Optimize output file size">;
+def no_warn_dylib_install_name: Joined<["--"], "no-warn-dylib-install-name">,
+    HelpText<"Do not warn on -install-name if -dylib is not passed (default)">,
+    Group<grp_lld>;
+def warn_dylib_install_name: Joined<["--"], "warn-dylib-install-name">,
+    HelpText<"Warn on -install-name if -dylib is not passed">,
+    Group<grp_lld>;
 
 // This is a complete Options.td compiled from Apple's ld(1) manpage
 // dated 2018-03-07 and cross checked with ld64 source code in repo

diff  --git a/lld/test/MachO/install-name.s b/lld/test/MachO/install-name.s
index 645679262a629..64136face9c74 100644
--- a/lld/test/MachO/install-name.s
+++ b/lld/test/MachO/install-name.s
@@ -2,13 +2,22 @@
 
 # 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: %no_fatal_warnings_lld --warn-dylib-install-name -o %t.exec %t.o \
+# RUN:     -install_name foo 2>&1 | 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: %no_fatal_warnings_lld --warn-dylib-install-name -bundle -o %t.bundle %t.o \
+# RUN:     -install_name foo 2>&1 | FileCheck --check-prefix=WARN %s
+# RUN: llvm-objdump --macho --all-headers %t.bundle \
+# RUN:     | FileCheck --check-prefix=NO-ID %s
+
+# RUN: %lld -bundle -o %t.bundle %t.o -install_name foo 2>&1
+# RUN: llvm-objdump --macho --all-headers %t.bundle \
+# RUN:     | FileCheck --check-prefix=NO-ID %s
+
+# RUN: %lld -bundle --warn-dylib-install-name --no-warn-dylib-install-name \
+# RUN:     -o %t.bundle %t.o -install_name foo 2>&1
 # RUN: llvm-objdump --macho --all-headers %t.bundle \
 # RUN:     | FileCheck --check-prefix=NO-ID %s
 
@@ -16,7 +25,7 @@
 # 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
+# WARN: warning: -install_name foo: ignored, only has effect with -dylib [--warn-dylib-install-name]
 
 # NO-ID-NOT: LC_ID_DYLIB
 


        


More information about the llvm-commits mailing list