diff --git a/bolt/test/AArch64/array_end.c b/bolt/test/AArch64/array_end.c index 6f4f9800c3903..c20844449672f 100644 --- a/bolt/test/AArch64/array_end.c +++ b/bolt/test/AArch64/array_end.c @@ -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 diff --git a/bolt/test/AArch64/asm-func-debug.test b/bolt/test/AArch64/asm-func-debug.test index 546add5ade02f..262d8b377cefa 100644 --- a/bolt/test/AArch64/asm-func-debug.test +++ b/bolt/test/AArch64/asm-func-debug.test @@ -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 diff --git a/bolt/test/AArch64/data-in-code.s b/bolt/test/AArch64/data-in-code.s index 1df5d4568542f..c021fb48128ad 100644 --- a/bolt/test/AArch64/data-in-code.s +++ b/bolt/test/AArch64/data-in-code.s @@ -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. diff --git a/bolt/test/AArch64/hook-fini.s b/bolt/test/AArch64/hook-fini.s index 4f321d463ef32..9860368095e6c 100644 --- a/bolt/test/AArch64/hook-fini.s +++ b/bolt/test/AArch64/hook-fini.s @@ -12,13 +12,13 @@ ## - 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 @@ -26,8 +26,8 @@ # 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 diff --git a/bolt/test/AArch64/ifunc.test b/bolt/test/AArch64/ifunc.test index 3da42c67c5a0a..42d0b4ec78756 100644 --- a/bolt/test/AArch64/ifunc.test +++ b/bolt/test/AArch64/ifunc.test @@ -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 | \ @@ -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 @@ -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 | \ @@ -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 | \ diff --git a/bolt/test/AArch64/jmp-table-unsupported.s b/bolt/test/AArch64/jmp-table-unsupported.s index 1228149430449..7c08d3d6ffef4 100644 --- a/bolt/test/AArch64/jmp-table-unsupported.s +++ b/bolt/test/AArch64/jmp-table-unsupported.s @@ -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 @@ -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 @@ -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 @@ -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 \ @@ -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 \ @@ -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 \ diff --git a/bolt/test/AArch64/lit.local.cfg b/bolt/test/AArch64/lit.local.cfg index 9432240469c7b..06f092a01357d 100644 --- a/bolt/test/AArch64/lit.local.cfg +++ b/bolt/test/AArch64/lit.local.cfg @@ -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}")) diff --git a/bolt/test/AArch64/tls.c b/bolt/test/AArch64/tls.c index b531811f679ff..8c1a393f420bc 100644 --- a/bolt/test/AArch64/tls.c +++ b/bolt/test/AArch64/tls.c @@ -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 diff --git a/bolt/test/AArch64/veneer-lld-abs.s b/bolt/test/AArch64/veneer-lld-abs.s index b22301db66c54..3fe896e45aafb 100644 --- a/bolt/test/AArch64/veneer-lld-abs.s +++ b/bolt/test/AArch64/veneer-lld-abs.s @@ -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 diff --git a/bolt/test/lit.local.cfg b/bolt/test/lit.local.cfg index 8a61d11f5825f..d958960bfc120 100644 --- a/bolt/test/lit.local.cfg +++ b/bolt/test/lit.local.cfg @@ -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}"))