[PATCH] D159095: [lld-macho]Add an option to suppress warnings when autohide symbols are in the list of exported_symbols.

Vy Nguyen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 29 07:13:55 PDT 2023


oontvoo created this revision.
Herald added projects: lld-macho, All.
Herald added a reviewer: lld-macho.
oontvoo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Details:
We often use wildcard symbols in the exported_symbols list, and sometimes they match autohide symbols, which triggers these "cannot export hidden symbols" warnings that can be a bit noisy.
An option to suppress these warnings would be useful.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159095

Files:
  lld/MachO/Driver.cpp
  lld/MachO/Options.td
  lld/test/MachO/export-options.s


Index: lld/test/MachO/export-options.s
===================================================================
--- lld/test/MachO/export-options.s
+++ lld/test/MachO/export-options.s
@@ -153,6 +153,9 @@
 # RUN: not %lld -dylib -exported_symbol "_foo" %t/autohide-private-extern.o \
 # RUN:   -o /dev/null  2>&1 | FileCheck %s --check-prefix=AUTOHIDE-PRIVATE
 
+## Test that the warning/error message can be suppressed.
+# RUN: %lld -dylib -exported_symbol "_foo" %t/autohide-private-extern.o -no_warn_export_hidden -o %t/autohide-pe-no-warn.out
+
 # RUN: not %lld -dylib -exported_symbol "_foo" %t/autohide.o \
 # RUN:   %t/glob-private-extern.o -o /dev/null 2>&1 | \
 # RUN:   FileCheck %s --check-prefix=AUTOHIDE-PRIVATE
Index: lld/MachO/Options.td
===================================================================
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -684,6 +684,10 @@
     HelpText<"Suppress warnings for static initializers in the output">,
     Flags<[HelpHidden]>,
     Group<grp_rare>;
+def no_warn_export_hidden : Flag<["-"], "no_warn_export_hidden">,
+    HelpText<"Suppress warnings for exporting weakdef-can-be-hidden symbols in the output">,
+    Flags<[HelpHidden]>,
+    Group<grp_rare>;    
 def unaligned_pointers : Separate<["-"], "unaligned_pointers">,
     MetaVarName<"<treatment>">,
     HelpText<"Handle unaligned pointers in __DATA segments according to <treatment>: warning, error, or suppress (default for arm64e is error, otherwise suppress)">,
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1,4 +1,5 @@
-//===- Driver.cpp ---------------------------------------------------------===//
+cannot //===- Driver.cpp
+       //---------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -53,7 +54,7 @@
 
 #include <algorithm>
 
-using namespace llvm;
+    using namespace llvm;
 using namespace llvm::MachO;
 using namespace llvm::object;
 using namespace llvm::opt;
@@ -1354,7 +1355,7 @@
   }
 }
 
-static void handleExplicitExports() {
+static void handleExplicitExports(bool noWarnExportHidden) {
   if (config->hasExplicitExports) {
     parallelForEach(symtab->getSymbols(), [](Symbol *sym) {
       if (auto *defined = dyn_cast<Defined>(sym)) {
@@ -1366,7 +1367,7 @@
               // it is explicitly exported.
               // The former can be exported but the latter cannot.
               defined->privateExtern = false;
-            } else {
+            } else if (!noWarnExportHidden) {
               warn("cannot export hidden symbol " + toString(*defined) +
                    "\n>>> defined in " + toString(defined->getFile()));
             }
@@ -1903,10 +1904,12 @@
     addSynthenticMethnames();
 
     createAliases();
+    const bool noWarnExportHidden =
+        args.hasFlag(OPT_no_warn_export_hidden, false);
     // If we are in "explicit exports" mode, hide everything that isn't
     // explicitly exported. Do this before running LTO so that LTO can better
     // optimize.
-    handleExplicitExports();
+    handleExplicitExports(noWarnExportHidden);
 
     bool didCompileBitcodeFiles = compileBitcodeFiles();
 
@@ -1923,7 +1926,7 @@
     // cross-module references to hidden symbols under ThinLTO. Thus, if we
     // compiled any bitcode files, we must redo the symbol hiding.
     if (didCompileBitcodeFiles)
-      handleExplicitExports();
+      handleExplicitExports(noWarnExportHidden);
     replaceCommonSymbols();
 
     StringRef orderFile = args.getLastArgValue(OPT_order_file);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159095.554318.patch
Type: text/x-patch
Size: 3718 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230829/231eba1e/attachment.bin>


More information about the llvm-commits mailing list