[llvm] [BOLT] Account for stubs with symbols in plt (PR #192716)

Maksim Panchenko via llvm-commits llvm-commits at lists.llvm.org
Thu May 7 15:49:54 PDT 2026


================
@@ -0,0 +1,36 @@
+## Test that BOLT correctly handles mold-style STT_FUNC symbols in PLT
+## sections.
+
+# REQUIRES: system-linux
+
+## Build a shared library from the common stubs.
+# RUN: %clang %cflags %p/../Inputs/stub.c -fPIC -shared -o %t.so
+
+## Build and link the main binary. The linker creates a real PLT entry.
+# RUN: llvm-mc -filetype=obj -triple aarch64-linux %s -o %t.o
+# RUN: ld.lld -pie %t.o %t.so -o %t.exe --emit-relocs
+
+## Inject a mold-style STT_FUNC symbol at the PLT entry for printf.
+## Mold places "printf$plt" directly on the PLT stub; we simulate this
+## with llvm-objcopy. The PLT header is 32 bytes on AArch64, and each
+## entry is 16 bytes. printf is the only entry after the header.
+# RUN: llvm-objcopy --add-symbol "printf\$plt=.plt:32,function,local" \
+# RUN:   %t.exe %t
+
+## Verify BOLT resolves the call as printf at PLT, not printf$plt.
+# RUN: llvm-bolt %t -o %t.bolt --print-cfg --print-only=_start 2>&1 \
+# RUN:   | FileCheck %s
+# RUN: llvm-readobj --syms %t.bolt | grep -A7 printf$plt | FileCheck \
+# RUN:   %s --check-prefix=CHECK-SYM
+
+# CHECK:     bl printf at PLT
+# CHECK-NOT: printf$plt
+# CHECK-SYM: Section: .plt
----------------
maksfb wrote:

What are we checking for here?

https://github.com/llvm/llvm-project/pull/192716


More information about the llvm-commits mailing list