[llvm] a49b05b - [JITLink][MachO] Use correct symbol scope when N_PEXT is set and N_EXT unset.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 15 15:54:20 PDT 2020


Author: Lang Hames
Date: 2020-08-15T15:53:33-07:00
New Revision: a49b05bb61f73eee3ebfa6c985c1d19356d383b5

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

LOG: [JITLink][MachO] Use correct symbol scope when N_PEXT is set and N_EXT unset.

MachOLinkGraphBuilder has been treating these as hidden, but they should be
treated as local.

Symbols with N_PEXT set and N_EXT unset are produced when hidden symbols are
run through 'ld -r' without passing -keep_private_externs. They will show up
under 'nm -m' as "was private extern", hence the name of the test cases.

Testcase commited as relocatable object to ensure that the test suite doesn't
depend on having 'ld -r' available.

Added: 
    llvm/test/ExecutionEngine/JITLink/X86/Inputs/MachO_x86-64_was_private_extern.o
    llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_was_private_extern.test

Modified: 
    llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp
index fa3f403b717c..cf1bb23da665 100644
--- a/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp
@@ -64,10 +64,8 @@ Linkage MachOLinkGraphBuilder::getLinkage(uint16_t Desc) {
 }
 
 Scope MachOLinkGraphBuilder::getScope(StringRef Name, uint8_t Type) {
-  if (Type & MachO::N_PEXT)
-    return Scope::Hidden;
   if (Type & MachO::N_EXT) {
-    if (Name.startswith("l"))
+    if ((Type & MachO::N_PEXT) || Name.startswith("l"))
       return Scope::Hidden;
     else
       return Scope::Default;

diff  --git a/llvm/test/ExecutionEngine/JITLink/X86/Inputs/MachO_x86-64_was_private_extern.o b/llvm/test/ExecutionEngine/JITLink/X86/Inputs/MachO_x86-64_was_private_extern.o
new file mode 100644
index 000000000000..c1357461b9dd
Binary files /dev/null and b/llvm/test/ExecutionEngine/JITLink/X86/Inputs/MachO_x86-64_was_private_extern.o 
diff er

diff  --git a/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_was_private_extern.test b/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_was_private_extern.test
new file mode 100644
index 000000000000..75e3847ae896
--- /dev/null
+++ b/llvm/test/ExecutionEngine/JITLink/X86/MachO_x86-64_was_private_extern.test
@@ -0,0 +1,9 @@
+# RUN: llvm-jitlink -noexec %S/Inputs/MachO_x86-64_was_private_extern.o
+#
+# Perform a no-exec link of MachO_x86-64_was_private_extern.o and verify that
+# it does not generate any errors despite the presence of a 'was private
+# extern' symbol (N_PEXT set, N_EXT unset).
+#
+# The test case for this is a relocatable object file rather than assembly as
+# objects must be run through ld64's 'ld -r' mode to produce them and we can't
+# assume that that is available everywhere.


        


More information about the llvm-commits mailing list