Skip to content

[BOLT][AArch64] Add base_cflags for PI flags #145502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bolt/test/AArch64/array_end.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// __init_array_end address would not be owned by any section.

// REQUIRES: system-linux
// RUN: %clang %cflags -no-pie %s -o %t.exe -Wl,-q \
// RUN: %clang %nopie_cflags %s -o %t.exe -Wl,-q \
// RUN: -Wl,-T %S/Inputs/array_end.lld_script
// RUN: llvm-bolt %t.exe -o %t.bolt --print-disasm \
// RUN: --print-only="callFini" | FileCheck %s
Expand Down
2 changes: 1 addition & 1 deletion bolt/test/AArch64/asm-func-debug.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# The input test case foo() contains nops that we remove.

RUN: %clang %cflags -gdwarf-5 -no-pie %p/../Inputs/asm_foo.s %p/../Inputs/asm_main.c -o %t.exe
RUN: %clang %nopie_cflags -gdwarf-5 %p/../Inputs/asm_foo.s %p/../Inputs/asm_main.c -o %t.exe
RUN: llvm-bolt %t.exe -o %t --update-debug-sections
RUN: llvm-dwarfdump -all %t | FileCheck %s

Expand Down
2 changes: 1 addition & 1 deletion bolt/test/AArch64/data-in-code.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Check that llvm-bolt prints data embedded in code.

# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
# RUN: %clang %cflags -fno-PIC -no-pie %t.o -o %t.exe -nostdlib \
# RUN: %clang %nopie_cflags -fno-PIC %t.o -o %t.exe -nostdlib \
# RUN: -fuse-ld=lld -Wl,-q

## Check disassembly of BOLT input.
Expand Down
8 changes: 4 additions & 4 deletions bolt/test/AArch64/hook-fini.s
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
## - Verify generated binary
# REQUIRES: system-linux,bolt-runtime,target=aarch64{{.*}}

# RUN: %clang %cflags -pie %s -Wl,-q -o %t.exe
# RUN: %clang %pie_cflags %s -Wl,-q -o %t.exe
# RUN: llvm-readelf -d %t.exe | FileCheck --check-prefix=DYN-FINI %s
# RUN: llvm-readelf -r %t.exe | FileCheck --check-prefix=RELOC-PIE %s
# RUN: llvm-bolt %t.exe -o %t --instrument
# RUN: llvm-readelf -drs %t | FileCheck --check-prefix=CHECK-FINI %s

# RUN: %clang %cflags -pie %s -Wl,-q,-fini=0 -o %t-no-fini.exe
# RUN: %clang %pie_cflags %s -Wl,-q,-fini=0 -o %t-no-fini.exe
# RUN: llvm-readelf -d %t-no-fini.exe | FileCheck --check-prefix=DYN-NO-FINI %s
# RUN: llvm-readelf -r %t-no-fini.exe | FileCheck --check-prefix=RELOC-PIE %s
# RUN: llvm-bolt %t-no-fini.exe -o %t-no-fini --instrument
# RUN: llvm-readelf -drs %t-no-fini | FileCheck --check-prefix=CHECK-NO-FINI %s
# RUN: llvm-readelf -ds -x .fini_array %t-no-fini | FileCheck --check-prefix=CHECK-NO-FINI-RELOC %s

## Create a dummy shared library to link against to force creation of the dynamic section.
# RUN: %clang %cflags %p/../Inputs/stub.c -fPIC -shared -o %t-stub.so
# RUN: %clang %cflags %s -no-pie -Wl,-q,-fini=0 %t-stub.so -o %t-no-pie-no-fini.exe
# RUN: %clang %pie_cflags -fPIC %p/../Inputs/stub.c -shared -o %t-stub.so
# RUN: %clang %nopie_cflags %s -Wl,-q,-fini=0 %t-stub.so -o %t-no-pie-no-fini.exe
# RUN: llvm-readelf -r %t-no-pie-no-fini.exe | FileCheck --check-prefix=RELOC-NO-PIE %s
# RUN: llvm-bolt %t-no-pie-no-fini.exe -o %t-no-pie-no-fini --instrument
# RUN: llvm-readelf -ds -x .fini_array %t-no-pie-no-fini | FileCheck --check-prefix=CHECK-NO-PIE-NO-FINI %s
Expand Down
10 changes: 5 additions & 5 deletions bolt/test/AArch64/ifunc.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// With -O0 indirect call is performed on IPLT trampoline. IPLT trampoline
// has IFUNC symbol.
// RUN: %clang %cflags -nostdlib -O0 -no-pie %p/../Inputs/ifunc.c -fuse-ld=lld \
// RUN: %clang %nopie_cflags -nostdlib -O0 %p/../Inputs/ifunc.c -fuse-ld=lld \
// RUN: -o %t.O0.exe -Wl,-q
// RUN: llvm-bolt %t.O0.exe -o %t.O0.bolt.exe \
// RUN: --print-disasm --print-only=_start | \
Expand All @@ -9,8 +9,8 @@
// RUN: FileCheck --check-prefix=REL_CHECK %s

// Non-pie static executable doesn't generate PT_DYNAMIC, check relocation
// is readed successfully and IPLT trampoline has been identified by bolt.
// RUN: %clang %cflags -nostdlib -O3 %p/../Inputs/ifunc.c -fuse-ld=lld -no-pie \
// is read successfully and IPLT trampoline has been identified by bolt.
// RUN: %clang %nopie_cflags -nostdlib -O3 %p/../Inputs/ifunc.c -fuse-ld=lld \
// RUN: -o %t.O3_nopie.exe -Wl,-q
// RUN: llvm-readelf -l %t.O3_nopie.exe | \
// RUN: FileCheck --check-prefix=NON_DYN_CHECK %s
Expand All @@ -23,7 +23,7 @@
// With -O3 direct call is performed on IPLT trampoline. IPLT trampoline
// doesn't have associated symbol. The ifunc symbol has the same address as
// IFUNC resolver function.
// RUN: %clang %cflags -nostdlib -O3 %p/../Inputs/ifunc.c -fuse-ld=lld -fPIC -pie \
// RUN: %clang %pie_cflags -fPIC -nostdlib -O3 %p/../Inputs/ifunc.c -fuse-ld=lld \
// RUN: -o %t.O3_pie.exe -Wl,-q
// RUN: llvm-bolt %t.O3_pie.exe -o %t.O3_pie.bolt.exe \
// RUN: --print-disasm --print-only=_start | \
Expand All @@ -33,7 +33,7 @@

// Check that IPLT trampoline located in .plt section are normally handled by
// BOLT. The gnu-ld linker doesn't use separate .iplt section.
// RUN: %clang %cflags -nostdlib -O3 %p/../Inputs/ifunc.c -fuse-ld=lld -fPIC -pie \
// RUN: %clang %pie_cflags -fPIC -nostdlib -O3 %p/../Inputs/ifunc.c -fuse-ld=lld \
// RUN: -T %p/../Inputs/iplt.ld -o %t.iplt_O3_pie.exe -Wl,-q
// RUN: llvm-bolt %t.iplt_O3_pie.exe -o %t.iplt_O3_pie.bolt.exe \
// RUN: --print-disasm --print-only=_start | \
Expand Down
12 changes: 6 additions & 6 deletions bolt/test/AArch64/jmp-table-unsupported.s
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
## Prepare binary (1)
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %t/jt_nop_adr.s \
# RUN: -o %t/jt_nop_adr.o
# RUN: %clang %cflags --target=aarch64-unknown-linux %t/jt_nop_adr.o \
# RUN: %clang %pie_cflags --target=aarch64-unknown-linux %t/jt_nop_adr.o \
# RUN: -Wl,-q -Wl,-z,now, -Wl,-T,%t/within-adr-range.t -o %t/jt_nop_adr.exe
# RUN: llvm-objdump --no-show-raw-insn -d %t/jt_nop_adr.exe | FileCheck \
# RUN: --check-prefix=JT-RELAXED %s
Expand All @@ -40,7 +40,7 @@ SECTIONS {
## Prepare binary (2)
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %t/jt_sub_ldr.s \
# RUN: -o %t/jt_sub_ldr.o
# RUN: %clang %cflags --target=aarch64-unknown-linux %t/jt_sub_ldr.o \
# RUN: %clang %pie_cflags --target=aarch64-unknown-linux %t/jt_sub_ldr.o \
# RUN: -Wl,-q -Wl,-z,now -o %t/jt_sub_ldr.exe
# RUN: llvm-objdump --no-show-raw-insn -d %t/jt_sub_ldr.exe | FileCheck \
# RUN: --check-prefix=JT-SUB-LDR %s
Expand All @@ -56,7 +56,7 @@ SECTIONS {
## Prepare binary (3)
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %t/jt_adrp_ldr.s \
# RUN: -o %t/jt_adrp_ldr.o
# RUN: %clang %cflags --target=aarch64-unknown-linux %t/jt_adrp_ldr.o \
# RUN: %clang %pie_cflags --target=aarch64-unknown-linux %t/jt_adrp_ldr.o \
# RUN: -Wl,-q -Wl,-z,now -Wl,--no-relax -o %t/jt_adrp_ldr.exe
# RUN: llvm-objdump --no-show-raw-insn -d %t/jt_adrp_ldr.exe | FileCheck \
# RUN: --check-prefix=JT-ADRP-LDR %s
Expand All @@ -73,7 +73,7 @@ SECTIONS {
# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown \
# RUN: --position-independent %t/jt_pic_with_relative_offset.s \
# RUN: -o %t/jt_pic_with_relative_offset.o
# RUN: %clang %cflags -fPIC -O0 %t/jt_pic_with_relative_offset.o \
# RUN: %clang %pie_cflags -fPIC -O0 %t/jt_pic_with_relative_offset.o \
# RUN: -o %t/jt_pic_with_relative_offset.exe -Wl,-q -Wl,--no-relax
# RUN: llvm-bolt %t/jt_pic_with_relative_offset.exe \
# RUN: -o %t/jt_pic_with_relative_offset.bolt -v 3 2>&1 | FileCheck \
Expand All @@ -82,7 +82,7 @@ SECTIONS {
# JT-BOLT-JT-PIC-OFFSETS: failed to match indirect branch

## Prepare binary (5)
# RUN: %clang %cflags %t/jt_fixed_branch.s -Wl,-q -Wl,--no-relax \
# RUN: %clang %pie_cflags %t/jt_fixed_branch.s -Wl,-q -Wl,--no-relax \
# RUN: -o %t/jt_fixed_branch.exe

# RUN: llvm-bolt %t/jt_fixed_branch.exe \
Expand All @@ -92,7 +92,7 @@ SECTIONS {
# JT-BOLT-FIXED-BR: failed to match indirect branch

## Prepare binary (6)
# RUN: %clang %cflags -no-pie %t/jt_type_normal.c \
# RUN: %clang %nopie_cflags %t/jt_type_normal.c \
# RUN: -Wl,-q -Wl,-z,now -Wl,--no-relax \
# RUN: -o %t/jt_type_normal.exe
# RUN: llvm-objdump --no-show-raw-insn -d %t/jt_type_normal.exe | FileCheck \
Expand Down
7 changes: 5 additions & 2 deletions bolt/test/AArch64/lit.local.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ if "AArch64" not in config.root.targets:

flags = "--target=aarch64-unknown-linux-gnu -nostartfiles -nostdlib -ffreestanding"

config.substitutions.insert(0, ("%cflags", f"%cflags {flags}"))
config.substitutions.insert(0, ("%cxxflags", f"%cxxflags {flags}"))
config.substitutions.insert(0, ("%pie_cflags", f"%pie_cflags {flags}"))
config.substitutions.insert(0, ("%pie_cxxflags", f"%pie_cxxflags {flags}"))

config.substitutions.insert(0, ("%nopie_cflags", f"%nopie_cflags {flags}"))
config.substitutions.insert(0, ("%nopie_cxxflags", f"%nopie_cxxflags {flags}"))
6 changes: 3 additions & 3 deletions bolt/test/AArch64/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ int main() {
}

// REQUIRES: system-linux
// RUN: %clang %cflags -no-pie %s -o %t.exe -Wl,-q \
// RUN: %clang %nopie_cflags %s -o %t.exe -Wl,-q \
// RUN: -Wl,--unresolved-symbols=ignore-all \
// RUN: -fuse-ld=lld \
// RUN: -nostdlib
// RUN: llvm-bolt %t.exe -o %t.bolt
// RUN: %clang %cflags -fPIC -pie %s -o %t_pie.exe -Wl,-q \
// RUN: %clang %pie_cflags -fPIC %s -o %t_pie.exe -Wl,-q \
// RUN: -Wl,--unresolved-symbols=ignore-all \
// RUN: -target aarch64-linux -fuse-ld=lld \
// RUN: -nostdlib
// RUN: llvm-bolt %t_pie.exe -o %t.bolt

// RUN: %clang %cflags -fPIC -shared %s -o %t.so -Wl,-q -fuse-ld=lld
// RUN: %clang %pie_cflags -fPIC -shared %s -o %t.so -Wl,-q -fuse-ld=lld
// RUN: llvm-objdump -d -r --disassemble-symbols=main %t.so | FileCheck %s
// RUN: llvm-bolt %t.so -o %t.bolt.so

Expand Down
2 changes: 1 addition & 1 deletion bolt/test/AArch64/veneer-lld-abs.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## generated by LLD.

# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
# RUN: %clang %cflags -fno-PIC -no-pie %t.o -o %t.exe -nostdlib \
# RUN: %clang %nopie_cflags -fno-PIC %t.o -o %t.exe -nostdlib \
# RUN: -fuse-ld=lld -Wl,-q
# RUN: llvm-objdump -d %t.exe | FileCheck --check-prefix=CHECK-INPUT %s
# RUN: llvm-objcopy --remove-section .rela.mytext %t.exe
Expand Down
18 changes: 14 additions & 4 deletions bolt/test/lit.local.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ host_triple = config.target_triple
if not "linux" in host_triple:
host_triple = host_triple.split("-")[0] + "-unknown-linux-gnu"

common_linker_flags = "-fuse-ld=lld -Wl,--unresolved-symbols=ignore-all -Wl,--build-id=none -pie"
flags = f"--target={host_triple} -fPIE {common_linker_flags}"
# TODO: Update comment
# By default, %cflags/%cxxflags enable position-independent code. To be explicit
# in tests, use %base_cflags/%base_cxxflags and provide any relevant flags, ie
# -fPIE/-fPIC/-pie, and -fno-PIE/-fno-PIC/-no-pie

config.substitutions.insert(0, ("%cflags", f"%cflags {flags}"))
config.substitutions.insert(0, ("%cxxflags", f"%cxxflags {flags}"))
common_linker_flags = "-fuse-ld=lld -Wl,--unresolved-symbols=ignore-all -Wl,--build-id=none"
flags_base = f"--target={host_triple} {common_linker_flags}"

flags_pie = f"{flags_base} -fPIE -pie"
config.substitutions.insert(0, ("%pie_cflags", f"%cflags {flags_pie}"))
config.substitutions.insert(0, ("%pie_cxxflags", f"%cxxflags {flags_pie}"))

flags_nopie = f"{flags_base} -fno-PIE -no-pie"
config.substitutions.insert(0, ("%nopie_cflags", f"%cflags {flags_nopie}"))
config.substitutions.insert(0, ("%nopie_cxxflags", f"%cxxflags {flags_nopie}"))
Loading