[lld] 20894a4 - [lld-macho] Prevent assertions for aliases to weak_def_can_be_hidden symbols

Paul Kirth via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 9 09:50:53 PST 2023


Author: Paul Kirth
Date: 2023-01-09T17:50:45Z
New Revision: 20894a478da224bdd69c91a22a5175b28bc08ed9

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

LOG: [lld-macho] Prevent assertions for aliases to weak_def_can_be_hidden symbols

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 removes the assert and tests that LLD handles such aliases
gracefully.

Reviewed By: #lld-macho, int3

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index b7d3379a12bed..5a858c0205aff 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -698,8 +698,6 @@ static macho::Symbol *createDefined(const NList &sym, StringRef name,
         sym.n_desc & REFERENCED_DYNAMICALLY, sym.n_desc & N_NO_DEAD_STRIP,
         isWeakDefCanBeHidden);
   }
-  assert(!isWeakDefCanBeHidden &&
-         "weak_def_can_be_hidden on already-hidden symbol?");
   bool includeInSymtab = !isPrivateLabel(name) && !isEhFrameSection(isec);
   return make<Defined>(
       name, isec->getFile(), isec, value, size, sym.n_desc & N_WEAK_DEF,

diff  --git a/lld/test/MachO/weak-def-can-be-hidden.s b/lld/test/MachO/weak-def-can-be-hidden.s
index 4552582df3d10..091ad618dba9a 100644
--- a/lld/test/MachO/weak-def-can-be-hidden.s
+++ b/lld/test/MachO/weak-def-can-be-hidden.s
@@ -116,6 +116,10 @@ _foo:
 _foo:
   retq
 
+# An alias is the only way to set .weak_def_can_be_hidden on an already-hidden symbol.
+# Veryify that LLD can handle these double-hidden symbols gracefully.
+.set l_foo, _foo
+
 #--- weak-foo-pe.s
 .private_extern _foo
 .globl _foo


        


More information about the llvm-commits mailing list