[PATCH] D141082: [lld] Prevent assertions for aliases to weak_def_can_be_hidden symbols

Paul Kirth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 5 12:47:29 PST 2023


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

In https://reviews.llvm.org/D137982 we found that on Mach-O private
aliases could trigger an assert in lld when the aliasee was a
weak_def_can_be_hidden symbol.

This appears to be incorrect, and should be allowed in Mach-O.
Disallowing this behavior is also inconsistent with how ld64 handles
a private alias to weak_def_can_be_hidden symbols.

This patch changes the assert to only trigger when the symbol is not an
alias.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141082

Files:
  lld/MachO/InputFiles.cpp
  lld/test/MachO/weak-def-can-be-hidden.s


Index: lld/test/MachO/weak-def-can-be-hidden.s
===================================================================
--- lld/test/MachO/weak-def-can-be-hidden.s
+++ lld/test/MachO/weak-def-can-be-hidden.s
@@ -116,6 +116,9 @@
 _foo:
   retq
 
+# A private alias to a weak_def_can_be_hidden symbol should not raise an error or assertion
+.set l_foo, _foo
+
 #--- weak-foo-pe.s
 .private_extern _foo
 .globl _foo
@@ -135,3 +138,5 @@
 _bar:
   callq _foo
   retq
+
+
Index: lld/MachO/InputFiles.cpp
===================================================================
--- lld/MachO/InputFiles.cpp
+++ lld/MachO/InputFiles.cpp
@@ -698,7 +698,10 @@
         sym.n_desc & REFERENCED_DYNAMICALLY, sym.n_desc & N_NO_DEAD_STRIP,
         isWeakDefCanBeHidden);
   }
-  assert(!isWeakDefCanBeHidden &&
+  // weak_def_can_be_hidden symbols should not reach this point, however a
+  // private alias to one can, so only assert if a weak_def_can_be_hidden symbol
+  // reaches this point, which is not an alias.
+  assert((!isWeakDefCanBeHidden || sym.n_type & N_INDR) &&
          "weak_def_can_be_hidden on already-hidden symbol?");
   bool includeInSymtab = !isPrivateLabel(name) && !isEhFrameSection(isec);
   return make<Defined>(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141082.486650.patch
Type: text/x-patch
Size: 1219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230105/d196c749/attachment.bin>


More information about the llvm-commits mailing list