[clang] [compiler-rt] [XRay] Remove reliance on default PIC behavior in DSO tests (PR #113892)

Sebastian Kreutzer via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 28 03:14:54 PDT 2024


https://github.com/sebastiankreutzer created https://github.com/llvm/llvm-project/pull/113892

Compiling with `-fxray-shared` requires position-independent code. 
Some tests do not explicitly specify this, thus falling back to the compiler default. 
If, for example, Clang is compiled with `-DCLANG_DEFAULT_PIE_ON_LINUX=OFF`, these checks fail.

This patch addresses this issue in two tests:
- Removing a check in `xray-shared.cpp` that only tests default PIC behavior
- Adding `-fPIC` explicitly in `clang-xray-shared.cpp` 

>From c7e2d0a4a92d2676c1d79efadae5d800fc8fc5b1 Mon Sep 17 00:00:00 2001
From: Sebastian Kreutzer <SebastianKreutzer at gmx.net>
Date: Mon, 28 Oct 2024 10:50:47 +0100
Subject: [PATCH] [XRay] Remove reliance on default PIC behavior in DSO tests

---
 clang/test/Driver/XRay/xray-shared.cpp                      | 1 -
 compiler-rt/test/xray/TestCases/Posix/clang-xray-shared.cpp | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/test/Driver/XRay/xray-shared.cpp b/clang/test/Driver/XRay/xray-shared.cpp
index 215854e1fc7cef..e331fefed1e0c9 100644
--- a/clang/test/Driver/XRay/xray-shared.cpp
+++ b/clang/test/Driver/XRay/xray-shared.cpp
@@ -1,6 +1,5 @@
 // RUN: %clang -### --target=x86_64-unknown-linux-gnu -fPIC -fxray-instrument -fxray-shared -c %s -o /dev/null 2>&1 | FileCheck %s
 // RUN: %clang -### --target=x86_64-unknown-linux-gnu -fpic -fxray-instrument -fxray-shared -c %s -o /dev/null 2>&1 | FileCheck %s
-// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fxray-instrument -fxray-shared -c %s -o /dev/null 2>&1 | FileCheck %s
 // RUN: not %clang -### --target=x86_64-unknown-linux-gnu -fno-PIC -fxray-instrument -fxray-shared -c %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR-PIC
 // RUN: not %clang -### --target=x86_64-unknown-linux-gnu -fno-pic -fxray-instrument -fxray-shared -c %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR-PIC
 
diff --git a/compiler-rt/test/xray/TestCases/Posix/clang-xray-shared.cpp b/compiler-rt/test/xray/TestCases/Posix/clang-xray-shared.cpp
index 92f3c29e970d42..0dd721571de9b8 100644
--- a/compiler-rt/test/xray/TestCases/Posix/clang-xray-shared.cpp
+++ b/compiler-rt/test/xray/TestCases/Posix/clang-xray-shared.cpp
@@ -1,6 +1,6 @@
 // Test that the DSO-local runtime library has been linked if -fxray-shared is passed.
 //
-// RUN: %clangxx -fxray-instrument -fxray-shared %s -shared -o %t.so
+// RUN: %clangxx -fxray-instrument -fxray-shared -fPIC %s -shared -o %t.so
 // RUN: llvm-nm %t.so | FileCheck %s --check-prefix ENABLED
 
 // RUN: %clangxx -fxray-instrument %s -shared -o %t.so



More information about the cfe-commits mailing list