[PATCH] D119773: [PowerPC][LLD] Fix linking weak hidden callees.

Stefan Pintilie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 14 13:21:12 PST 2022


stefanp created this revision.
stefanp added reviewers: nemanjai, sfertile, MaskRay.
Herald added subscribers: shchenz, kbarton, arichardson, emaste.
stefanp requested review of this revision.
Herald added a project: LLVM.

It seems that linking functions that are marked as weak and hidden is no longer
working because the linker incorrectly asumes that it needs a thunk for the
call. The linker converts weak hidden functions into local functions before the
call the check if a Thunk is needed and so isWeakUndef() no longer returns true.

This patch adds a check to look for local and undef.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119773

Files:
  lld/ELF/Arch/PPC64.cpp
  lld/test/ELF/ppc64-weak-hidden-undef.s


Index: lld/test/ELF/ppc64-weak-hidden-undef.s
===================================================================
--- /dev/null
+++ lld/test/ELF/ppc64-weak-hidden-undef.s
@@ -0,0 +1,17 @@
+# REQUIRES: ppc
+# RUN: llvm-mc -filetype=obj -triple=powerpc64le %s -o %t.o
+# RUN: ld.lld %t.o -o %t
+# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
+
+# CHECK-LABEL: <main>:
+# CHECK:         bl
+# CHECK-NEXT:    nop
+# CHECK-NEXT:    blr
+
+main:
+	bl callee
+	nop
+	blr
+
+	.hidden	callee
+	.weak	callee
Index: lld/ELF/Arch/PPC64.cpp
===================================================================
--- lld/ELF/Arch/PPC64.cpp
+++ lld/ELF/Arch/PPC64.cpp
@@ -1373,6 +1373,10 @@
   if (s.isUndefWeak() && !config->shared)
     return false;
 
+  // Local undefined.
+  if (s.isUndefined() && s.isLocal())
+    return false;
+
   // If the offset exceeds the range of the branch type then it will need
   // a range-extending thunk.
   // See the comment in getRelocTargetVA() about R_PPC64_CALL.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119773.408591.patch
Type: text/x-patch
Size: 1003 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220214/c3a90867/attachment.bin>


More information about the llvm-commits mailing list