llvm-project/bolt/test/X86/plt-call.test
Fangrui Song a907008bcb
[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.)
2025-02-05 09:31:58 -08:00

14 lines
469 B
Plaintext

// Verify that PLTCall optimization works.
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
// Call to printf
CHECK: callq *printf@GOT(%rip) # PLTCall: 1
// Call to puts, that was tail-call optimized
CHECK: jmpl *puts@GOT(%rip) # TAILCALL # PLTCall: 1