[PATCH] D106566: [lld/mac] Handle symbols from -U in treatUndefinedSymbol()

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 22 16:44:13 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2d6fb62ef2d9: [lld/mac] Handle symbols from -U in treatUndefinedSymbol() (authored by thakis).
Herald added a project: LLVM.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106566/new/

https://reviews.llvm.org/D106566

Files:
  lld/MachO/Config.h
  lld/MachO/Driver.cpp
  lld/MachO/SymbolTable.cpp
  lld/test/MachO/dead-strip.s


Index: lld/test/MachO/dead-strip.s
===================================================================
--- lld/test/MachO/dead-strip.s
+++ lld/test/MachO/dead-strip.s
@@ -147,9 +147,9 @@
 # STRIPDYLIB-NEXT:  l {{.*}} __dyld_private
 # STRIPDYLIB-NEXT:  g {{.*}} _main
 # STRIPDYLIB-NEXT:  g {{.*}} __mh_execute_header
-# STRIPDYLIB-NEXT:  *UND* _ref_undef_fun
 # STRIPDYLIB-NEXT:  *UND* dyld_stub_binder
 # STRIPDYLIB-NEXT:  *UND* _ref_dylib_fun
+# STRIPDYLIB-NEXT:  *UND* _ref_undef_fun
 # STRIPDYLIB:      Bind table:
 # STRIPDYLIB:      Lazy bind table:
 # STRIPDYLIB:       __DATA   __la_symbol_ptr {{.*}} flat-namespace _ref_undef_fun
@@ -202,9 +202,9 @@
 # LIVESUPP-NEXT:   g {{.*}} _bar
 # LIVESUPP-NEXT:   g {{.*}} _foo
 # LIVESUPP-NEXT:   g {{.*}} __mh_execute_header
-# LIVESUPP-NEXT:   *UND* _ref_undef_fun
 # LIVESUPP-NEXT:   *UND* dyld_stub_binder
 # LIVESUPP-NEXT:   *UND* _ref_dylib_fun
+# LIVESUPP-NEXT:   *UND* _ref_undef_fun
 
 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos \
 # RUN:     %t/live-support-iterations.s -o %t/live-support-iterations.o
Index: lld/MachO/SymbolTable.cpp
===================================================================
--- lld/MachO/SymbolTable.cpp
+++ lld/MachO/SymbolTable.cpp
@@ -197,6 +197,13 @@
 }
 
 void lld::macho::treatUndefinedSymbol(const Undefined &sym, StringRef source) {
+  // Handle -U.
+  if (config->explicitDynamicLookups.count(sym.getName())) {
+    symtab->addDynamicLookup(sym.getName());
+    return;
+  }
+
+  // Handle -undefined.
   auto message = [source, &sym]() {
     std::string message = "undefined symbol";
     if (config->archMultiple)
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1175,7 +1175,7 @@
   }
 
   for (const Arg *arg : args.filtered(OPT_U))
-    symtab->addDynamicLookup(arg->getValue());
+    config->explicitDynamicLookups.insert(arg->getValue());
 
   config->mapFile = args.getLastArgValue(OPT_map);
   config->optimize = args::getInteger(args, OPT_O, 1);
Index: lld/MachO/Config.h
===================================================================
--- lld/MachO/Config.h
+++ lld/MachO/Config.h
@@ -13,6 +13,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/BinaryFormat/MachO.h"
 #include "llvm/Support/CachePruning.h"
 #include "llvm/Support/GlobPattern.h"
@@ -158,6 +159,7 @@
   std::vector<llvm::StringRef> runtimePaths;
   std::vector<std::string> astPaths;
   std::vector<Symbol *> explicitUndefineds;
+  llvm::StringSet<> explicitDynamicLookups;
   // There are typically few custom sectionAlignments or segmentProtections,
   // so use a vector instead of a map.
   std::vector<SectionAlign> sectionAlignments;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106566.361030.patch
Type: text/x-patch
Size: 2836 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210722/a25930ec/attachment.bin>


More information about the llvm-commits mailing list