https://github.com/llvmbot updated https://github.com/llvm/llvm-project/pull/126351
>From 553185bd7188fa1c48cce8a661df812a03afb5b7 Mon Sep 17 00:00:00 2001 From: Fangrui Song <i...@maskray.me> Date: Wed, 5 Feb 2025 09:31:58 -0800 Subject: [PATCH] [BOLT,test] Link against a shared object to test PLT (#125625) A few tests generate a statically-linked position-independent executable with `-nostdlib -Wl,--unresolved-symbols=ignore-all -pie` (`%clang`) and test PLT handling. (--unresolved-symbols=ignore-all suppresses undefined symbol errors and serves as a convenience hack.) This relies on an unguaranteed linker behavior: a statically-linked PIE does not necessarily generate PLT entries. While current lld generates a PLT entry, it will change to suppress the PLT entry to simplify internal handling and improve consistency. (The behavior has no consistency in GNU ld, some ports generated a .dynsym entry while some don't. While most seem to generate a PLT entry but some ports use a weird `R_*_NONE` relocation.) (cherry picked from commit a907008bcb8dcc093f8aa5c0450d92cd63473b81) --- bolt/test/AArch64/exceptions-plt.cpp | 4 +++- bolt/test/AArch64/plt-call.test | 4 +++- bolt/test/X86/callcont-fallthru.s | 4 +++- bolt/test/X86/cfi-instrs-reordered.s | 4 +++- bolt/test/X86/plt-call.test | 4 +++- bolt/test/runtime/exceptions-plt.cpp | 4 +++- bolt/test/runtime/plt-lld.test | 7 ++++--- 7 files changed, 22 insertions(+), 9 deletions(-) diff --git a/bolt/test/AArch64/exceptions-plt.cpp b/bolt/test/AArch64/exceptions-plt.cpp index 576f0fc91a9d8..33c28406ca8d6 100644 --- a/bolt/test/AArch64/exceptions-plt.cpp +++ b/bolt/test/AArch64/exceptions-plt.cpp @@ -2,7 +2,9 @@ // REQUIRES: system-linux -// RUN: %clangxx %cxxflags -O1 -Wl,-q,-znow %s -o %t.exe +// RUN: %clang %cflags -fpic -shared -xc /dev/null -o %t.so +// Link against a DSO to ensure PLT entries. +// RUN: %clangxx %cxxflags -O1 -Wl,-q,-znow %s %t.so -o %t.exe // RUN: llvm-bolt %t.exe -o %t.bolt.exe --plt=all --print-only=.*main.* \ // RUN: --print-finalized 2>&1 | FileCheck %s diff --git a/bolt/test/AArch64/plt-call.test b/bolt/test/AArch64/plt-call.test index da307d4a6c01e..1fa62c4a36aaf 100644 --- a/bolt/test/AArch64/plt-call.test +++ b/bolt/test/AArch64/plt-call.test @@ -1,6 +1,8 @@ // Verify that PLTCall optimization works. -RUN: %clang %cflags %p/../Inputs/plt-tailcall.c \ +RUN: %clang %cflags -fpic -shared -xc /dev/null -o %t.so +// Link against a DSO to ensure PLT entries. +RUN: %clang %cflags %p/../Inputs/plt-tailcall.c %t.so \ RUN: -o %t -Wl,-q RUN: llvm-bolt %t -o %t.bolt --plt=all --print-plt --print-only=foo | FileCheck %s diff --git a/bolt/test/X86/callcont-fallthru.s b/bolt/test/X86/callcont-fallthru.s index 31a7910d7fa3f..d76f869c971fd 100644 --- a/bolt/test/X86/callcont-fallthru.s +++ b/bolt/test/X86/callcont-fallthru.s @@ -1,7 +1,9 @@ ## Ensures that a call continuation fallthrough count is set when using ## pre-aggregated perf data. -# RUN: %clangxx %cxxflags %s -o %t -Wl,-q -nostdlib +# RUN: %clang %cflags -fpic -shared -xc /dev/null -o %t.so +## Link against a DSO to ensure PLT entries. +# RUN: %clangxx %cxxflags %s %t.so -o %t -Wl,-q -nostdlib # RUN: link_fdata %s %t %t.pa1 PREAGG # RUN: link_fdata %s %t %t.pa2 PREAGG2 # RUN: link_fdata %s %t %t.pa3 PREAGG3 diff --git a/bolt/test/X86/cfi-instrs-reordered.s b/bolt/test/X86/cfi-instrs-reordered.s index c325aaf1ad8b1..5173fa6c3c7d0 100644 --- a/bolt/test/X86/cfi-instrs-reordered.s +++ b/bolt/test/X86/cfi-instrs-reordered.s @@ -3,7 +3,9 @@ # RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o # RUN: llvm-strip --strip-unneeded %t.o -# RUN: %clangxx %cflags %t.o -o %t.exe +# RUN: %clang %cflags -fpic -shared -xc /dev/null -o %t.so +## Link against a DSO to ensure PLT entries. +# RUN: %clangxx %cflags %t.o %t.so -o %t.exe # RUN: llvm-bolt %t.exe -o %t --reorder-blocks=cache --print-after-lowering \ # RUN: --print-only=_Z10SolveCubicddddPiPd 2>&1 | FileCheck %s # diff --git a/bolt/test/X86/plt-call.test b/bolt/test/X86/plt-call.test index e6ae86c179d27..aeee3024ac170 100644 --- a/bolt/test/X86/plt-call.test +++ b/bolt/test/X86/plt-call.test @@ -1,6 +1,8 @@ // Verify that PLTCall optimization works. -RUN: %clang %cflags %p/../Inputs/plt-tailcall.c \ +RUN: %clang %cflags -fpic -shared -xc /dev/null -o %t.so +// Link against a DSO to ensure PLT entries. +RUN: %clang %cflags %p/../Inputs/plt-tailcall.c %t.so \ RUN: -o %t -Wl,-q RUN: llvm-bolt %t -o %t.bolt --plt=all --print-plt --print-only=foo | FileCheck %s diff --git a/bolt/test/runtime/exceptions-plt.cpp b/bolt/test/runtime/exceptions-plt.cpp index 8a75a3cb384b9..3d8e7a5133e2c 100644 --- a/bolt/test/runtime/exceptions-plt.cpp +++ b/bolt/test/runtime/exceptions-plt.cpp @@ -2,7 +2,9 @@ // REQUIRES: system-linux -// RUN: %clangxx %cxxflags -O1 -Wl,-q,-znow %s -o %t.exe +// RUN: %clang %cflags -fpic -shared -xc /dev/null -o %t.so +// Link against a DSO to ensure PLT entries. +// RUN: %clangxx %cxxflags -O1 -Wl,-q,-znow %s %t.so -o %t.exe // RUN: llvm-bolt %t.exe -o %t.bolt.exe --plt=all // RUN: %t.bolt.exe diff --git a/bolt/test/runtime/plt-lld.test b/bolt/test/runtime/plt-lld.test index b505a191f90ab..3432e18bf4daf 100644 --- a/bolt/test/runtime/plt-lld.test +++ b/bolt/test/runtime/plt-lld.test @@ -1,14 +1,15 @@ // This test checks that the pointers to PLT are properly updated. -// The test is using lld linker. +// The test uses lld and links against a DSO to ensure PLT entries. +RUN: %clang %cflags -fpic -shared -xc /dev/null -o %t.so // Non-PIE: -RUN: %clang %cflags -no-pie %p/../Inputs/plt.c -fuse-ld=lld \ +RUN: %clang %cflags -no-pie %p/../Inputs/plt.c %t.so -fuse-ld=lld \ RUN: -o %t.lld.exe -Wl,-q RUN: llvm-bolt %t.lld.exe -o %t.lld.bolt.exe --use-old-text=0 --lite=0 RUN: %t.lld.bolt.exe | FileCheck %s // PIE: -RUN: %clang %cflags -fPIC -pie %p/../Inputs/plt.c -fuse-ld=lld \ +RUN: %clang %cflags -fPIC -pie %p/../Inputs/plt.c %t.so -fuse-ld=lld \ RUN: -o %t.lld.pie.exe -Wl,-q RUN: llvm-bolt %t.lld.pie.exe -o %t.lld.bolt.pie.exe --use-old-text=0 --lite=0 RUN: %t.lld.bolt.pie.exe | FileCheck %s _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits