[PATCH] D94371: [lld/mac] Implement -u flag

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 9 05:23:41 PST 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGe0b8604e5d3c: [lld/mac] Implement -u flag (authored by thakis).
Herald added projects: LLVM, lld-macho.

Changed prior to commit:
  https://reviews.llvm.org/D94371?vs=315647&id=322352#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94371

Files:
  lld/MachO/Config.h
  lld/MachO/Driver.cpp
  lld/MachO/Options.td
  lld/test/MachO/u.s


Index: lld/test/MachO/u.s
===================================================================
--- /dev/null
+++ lld/test/MachO/u.s
@@ -0,0 +1,32 @@
+# REQUIRES: x86
+# RUN: rm -rf %t
+# RUN: split-file %s %t
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/foo.o %t/foo.s
+# RUN: llvm-ar csr  %t/lib.a %t/foo.o
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/main.o %t/main.s
+
+# RUN: %lld %t/main.o %t/lib.a -o /dev/null -why_load | \
+# RUN:     FileCheck %s --check-prefix=NOFOO --allow-empty
+
+# RUN: %lld %t/main.o %t/lib.a -u _foo -o /dev/null -why_load | \
+# RUN:     FileCheck %s --check-prefix=FOO
+
+# RUN: not %lld %t/main.o %t/lib.a -u _asdf -o /dev/null 2>&1 | \
+# RUN:     FileCheck %s --check-prefix=UNDEF
+
+# NOFOO-NOT: _foo forced load of lib.a(foo.o)
+# FOO: _foo forced load of lib.a(foo.o)
+# UNDEF: error: undefined symbol: _asdf
+
+#--- foo.s
+.globl _foo
+_foo:
+  ret
+
+#--- main.s
+.globl _main
+_main:
+  ret
+
Index: lld/MachO/Options.td
===================================================================
--- lld/MachO/Options.td
+++ lld/MachO/Options.td
@@ -454,7 +454,6 @@
 def u : Separate<["-"], "u">,
      MetaVarName<"<symbol>">,
      HelpText<"Require that <symbol> be defined for the link to succeed">,
-     Flags<[HelpHidden]>,
      Group<grp_resolve>;
 def U : Separate<["-"], "U">,
      MetaVarName<"<symbol>">,
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -734,6 +734,10 @@
   config->entry = symtab->addUndefined(args.getLastArgValue(OPT_e, "_main"),
                                        /*file=*/nullptr,
                                        /*isWeakRef=*/false);
+  for (auto *arg : args.filtered(OPT_u)) {
+    config->explicitUndefineds.push_back(symtab->addUndefined(
+        arg->getValue(), /*file=*/nullptr, /*isWeakRef=*/false));
+  }
   config->outputFile = args.getLastArgValue(OPT_o, "a.out");
   config->installName =
       args.getLastArgValue(OPT_install_name, config->outputFile);
@@ -864,6 +868,15 @@
     error("undefined symbol: " + toString(*config->entry));
     return false;
   }
+  // FIXME: This prints symbols that are undefined both in input files and
+  // via -u flag twice.
+  for (const auto *undefined : config->explicitUndefineds) {
+    if (isa<Undefined>(undefined)) {
+      error("undefined symbol: " + toString(*undefined) +
+            "\n>>> referenced by flag -u " + toString(*undefined));
+      return false;
+    }
+  }
 
   createSyntheticSections();
   symtab->addDSOHandle(in.header);
Index: lld/MachO/Config.h
===================================================================
--- lld/MachO/Config.h
+++ lld/MachO/Config.h
@@ -68,6 +68,7 @@
   std::vector<llvm::StringRef> librarySearchPaths;
   std::vector<llvm::StringRef> frameworkSearchPaths;
   std::vector<llvm::StringRef> runtimePaths;
+  std::vector<Symbol *> explicitUndefineds;
   llvm::DenseMap<llvm::StringRef, SymbolPriorityEntry> priorities;
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94371.322352.patch
Type: text/x-patch
Size: 3059 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210209/9c10e9cc/attachment.bin>


More information about the llvm-commits mailing list