mirror of
https://github.com/openembedded/meta-openembedded.git
synced 2026-09-28 13:00:23 +00:00
bpftrace: Fix tests to cross compile
Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
This commit is contained in:
+79
@@ -0,0 +1,79 @@
|
||||
From 94892d6ac971155b43a6bbff942acede21b60efb Mon Sep 17 00:00:00 2001
|
||||
From: x <x@x>
|
||||
Date: Mon, 7 Sep 2026 17:54:26 +0000
|
||||
Subject: [PATCH] tests: pass C/linker flags and sysroot to raw compiler
|
||||
invocations in testprogs
|
||||
|
||||
Several add_custom_command() rules in tests/testprogs invoke
|
||||
${CMAKE_C_COMPILER} directly (false.bin and the split-DWARF dwo/dwp
|
||||
builds). Unlike add_executable() targets, these do not automatically
|
||||
receive CMAKE_C_FLAGS, CMAKE_EXE_LINKER_FLAGS or CMAKE_SYSROOT, so with
|
||||
cross toolchains that have no built-in default sysroot (e.g.
|
||||
Yocto/OpenEmbedded) the compile fails with:
|
||||
|
||||
uprobe_test.c:1:10: fatal error: unistd.h: No such file or directory
|
||||
|
||||
Build a flag list from CMAKE_C_COMPILER_ARG1, CMAKE_SYSROOT and
|
||||
CMAKE_C_FLAGS and pass it to each raw compiler invocation. The dwo/dwp
|
||||
commands compile and link in a single step, so also pass
|
||||
CMAKE_EXE_LINKER_FLAGS to those.
|
||||
|
||||
Upstream-Status: Pending
|
||||
Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
|
||||
---
|
||||
tests/testprogs/CMakeLists.txt | 23 ++++++++++++++++++++---
|
||||
1 file changed, 20 insertions(+), 3 deletions(-)
|
||||
|
||||
--- a/tests/testprogs/CMakeLists.txt
|
||||
+++ b/tests/testprogs/CMakeLists.txt
|
||||
@@ -17,6 +17,23 @@ test_and_add_testprog_cflag("-fno-omit-f
|
||||
test_and_add_testprog_cflag("-mno-omit-leaf-frame-pointer")
|
||||
get_property(testprog_cflags GLOBAL PROPERTY testprog_cflags)
|
||||
|
||||
+# Flags for the add_custom_command() invocations below that call the C
|
||||
+# compiler directly. Unlike add_executable(), custom commands do not
|
||||
+# automatically receive CMAKE_C_FLAGS or the sysroot, which breaks cross
|
||||
+# compilation with toolchains that have no default sysroot (e.g. Yocto).
|
||||
+set(testprog_raw_cc_flags "")
|
||||
+if(CMAKE_C_COMPILER_ARG1)
|
||||
+ separate_arguments(_arg1 UNIX_COMMAND "${CMAKE_C_COMPILER_ARG1}")
|
||||
+ list(APPEND testprog_raw_cc_flags ${_arg1})
|
||||
+endif()
|
||||
+if(CMAKE_SYSROOT)
|
||||
+ list(APPEND testprog_raw_cc_flags "--sysroot=${CMAKE_SYSROOT}")
|
||||
+endif()
|
||||
+separate_arguments(_c_flags UNIX_COMMAND "${CMAKE_C_FLAGS}")
|
||||
+list(APPEND testprog_raw_cc_flags ${_c_flags})
|
||||
+# Linker flags for the custom commands that compile and link in one step.
|
||||
+separate_arguments(testprog_raw_ld_flags UNIX_COMMAND "${CMAKE_EXE_LINKER_FLAGS}")
|
||||
+
|
||||
file(GLOB testprog_sources CONFIGURE_DEPENDS *.c *.cpp)
|
||||
set(testprogtargets "")
|
||||
function(testprog_compile is_pie)
|
||||
@@ -85,7 +102,7 @@ endif()
|
||||
find_program(LLVM_OBJCOPY llvm-objcopy REQUIRED)
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/false.bin
|
||||
- COMMAND ${CMAKE_C_COMPILER} -c ${CMAKE_CURRENT_SOURCE_DIR}/false.c -o ${CMAKE_CURRENT_BINARY_DIR}/false.o
|
||||
+ COMMAND ${CMAKE_C_COMPILER} ${testprog_raw_cc_flags} -c ${CMAKE_CURRENT_SOURCE_DIR}/false.c -o ${CMAKE_CURRENT_BINARY_DIR}/false.o
|
||||
COMMAND ${LLVM_OBJCOPY} -S --only-section=.text --keep-symbol=main -O binary ${CMAKE_CURRENT_BINARY_DIR}/false.o ${CMAKE_CURRENT_BINARY_DIR}/false.bin
|
||||
COMMAND ${CMAKE_COMMAND} -E rm -f ${CMAKE_CURRENT_BINARY_DIR}/false.o
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
@@ -147,7 +164,7 @@ add_custom_command(
|
||||
OUTPUT
|
||||
${EXTERNAL_DEBUG_DIR}/dwo/uprobe_test-split
|
||||
${EXTERNAL_DEBUG_DIR}/dwo/uprobe_test-split-uprobe_test.dwo
|
||||
- COMMAND ${CMAKE_C_COMPILER} -g -O0 -gsplit-dwarf ${CMAKE_CURRENT_SOURCE_DIR}/uprobe_test.c -o ${EXTERNAL_DEBUG_DIR}/dwo/uprobe_test-split
|
||||
+ COMMAND ${CMAKE_C_COMPILER} ${testprog_raw_cc_flags} -g -O0 -gsplit-dwarf ${CMAKE_CURRENT_SOURCE_DIR}/uprobe_test.c -o ${EXTERNAL_DEBUG_DIR}/dwo/uprobe_test-split ${testprog_raw_ld_flags}
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/uprobe_test.c
|
||||
)
|
||||
list(APPEND testprogtargets ${EXTERNAL_DEBUG_DIR}/dwo/uprobe_test-split)
|
||||
@@ -159,7 +176,7 @@ add_custom_command(
|
||||
OUTPUT
|
||||
${EXTERNAL_DEBUG_DIR}/dwp/uprobe_test-split
|
||||
${EXTERNAL_DEBUG_DIR}/dwp/uprobe_test-split.dwp
|
||||
- COMMAND ${CMAKE_C_COMPILER} -g -O0 -gsplit-dwarf ${CMAKE_CURRENT_SOURCE_DIR}/uprobe_test.c -o ${EXTERNAL_DEBUG_DIR}/dwp/uprobe_test-split
|
||||
+ COMMAND ${CMAKE_C_COMPILER} ${testprog_raw_cc_flags} -g -O0 -gsplit-dwarf ${CMAKE_CURRENT_SOURCE_DIR}/uprobe_test.c -o ${EXTERNAL_DEBUG_DIR}/dwp/uprobe_test-split ${testprog_raw_ld_flags}
|
||||
COMMAND ${LLVM_DWP} -e ${EXTERNAL_DEBUG_DIR}/dwp/uprobe_test-split -o ${EXTERNAL_DEBUG_DIR}/dwp/uprobe_test-split.dwp
|
||||
COMMAND ${CMAKE_COMMAND} -E rm -f ${EXTERNAL_DEBUG_DIR}/dwp/*.dwo
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/uprobe_test.c
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
From bc125c84cffdbb23ea7977b1f235635607e00a18 Mon Sep 17 00:00:00 2001
|
||||
From: Khem Raj <khem.raj@oss.qualcomm.com>
|
||||
Date: Mon, 7 Sep 2026 16:36:50 -0700
|
||||
Subject: [PATCH] tests: do not embed build paths in split DWARF test programs
|
||||
|
||||
The two split-DWARF test binaries are compiled by add_custom_command() with
|
||||
an absolute -o path. clang derives the .dwo file name from -o and records it
|
||||
verbatim in DW_AT_dwo_name, without applying -ffile-prefix-map, so the
|
||||
absolute build directory ends up baked into uprobe_test-split, its .dwo and
|
||||
the .dwp built from it. gcc remaps it, clang does not.
|
||||
|
||||
Compile from inside the target directory with a relative -o instead. The
|
||||
recorded DW_AT_dwo_name then becomes a plain file name, which is what the
|
||||
dwarf parser looks for anyway (it uses only the basename), and llvm-dwp
|
||||
resolves it relative to its working directory.
|
||||
|
||||
This keeps the shipped test programs free of build paths, which matters for
|
||||
distributions that package tests/ and check for host paths in the output.
|
||||
|
||||
Upstream-Status: Pending
|
||||
|
||||
Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
|
||||
---
|
||||
tests/testprogs/CMakeLists.txt | 12 +++++++++---
|
||||
1 file changed, 9 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/tests/testprogs/CMakeLists.txt b/tests/testprogs/CMakeLists.txt
|
||||
index 4cc9967..2b407b7 100644
|
||||
--- a/tests/testprogs/CMakeLists.txt
|
||||
+++ b/tests/testprogs/CMakeLists.txt
|
||||
@@ -160,11 +160,16 @@ list(APPEND testprogtargets
|
||||
${CMAKE_CURRENT_BINARY_DIR}/.debug/uprobe_separate_debug-stripped.debug)
|
||||
|
||||
# Build a binary with split DWARF (.dwo files) to verify parsing of the split debug info format.
|
||||
+# Compile from within the output directory and pass a relative -o: some compilers
|
||||
+# (e.g. clang) record the -o derived .dwo path verbatim in DW_AT_dwo_name without
|
||||
+# applying -ffile-prefix-map, which would bake the absolute build directory into
|
||||
+# both the binary and the .dwo file.
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
${EXTERNAL_DEBUG_DIR}/dwo/uprobe_test-split
|
||||
${EXTERNAL_DEBUG_DIR}/dwo/uprobe_test-split-uprobe_test.dwo
|
||||
- COMMAND ${CMAKE_C_COMPILER} ${testprog_raw_cc_flags} -g -O0 -gsplit-dwarf ${CMAKE_CURRENT_SOURCE_DIR}/uprobe_test.c -o ${EXTERNAL_DEBUG_DIR}/dwo/uprobe_test-split ${testprog_raw_ld_flags}
|
||||
+ COMMAND ${CMAKE_C_COMPILER} ${testprog_raw_cc_flags} -g -O0 -gsplit-dwarf ${CMAKE_CURRENT_SOURCE_DIR}/uprobe_test.c -o uprobe_test-split ${testprog_raw_ld_flags}
|
||||
+ WORKING_DIRECTORY ${EXTERNAL_DEBUG_DIR}/dwo
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/uprobe_test.c
|
||||
)
|
||||
list(APPEND testprogtargets ${EXTERNAL_DEBUG_DIR}/dwo/uprobe_test-split)
|
||||
@@ -176,9 +181,10 @@ add_custom_command(
|
||||
OUTPUT
|
||||
${EXTERNAL_DEBUG_DIR}/dwp/uprobe_test-split
|
||||
${EXTERNAL_DEBUG_DIR}/dwp/uprobe_test-split.dwp
|
||||
- COMMAND ${CMAKE_C_COMPILER} ${testprog_raw_cc_flags} -g -O0 -gsplit-dwarf ${CMAKE_CURRENT_SOURCE_DIR}/uprobe_test.c -o ${EXTERNAL_DEBUG_DIR}/dwp/uprobe_test-split ${testprog_raw_ld_flags}
|
||||
- COMMAND ${LLVM_DWP} -e ${EXTERNAL_DEBUG_DIR}/dwp/uprobe_test-split -o ${EXTERNAL_DEBUG_DIR}/dwp/uprobe_test-split.dwp
|
||||
+ COMMAND ${CMAKE_C_COMPILER} ${testprog_raw_cc_flags} -g -O0 -gsplit-dwarf ${CMAKE_CURRENT_SOURCE_DIR}/uprobe_test.c -o uprobe_test-split ${testprog_raw_ld_flags}
|
||||
+ COMMAND ${LLVM_DWP} -e uprobe_test-split -o uprobe_test-split.dwp
|
||||
COMMAND ${CMAKE_COMMAND} -E rm -f ${EXTERNAL_DEBUG_DIR}/dwp/*.dwo
|
||||
+ WORKING_DIRECTORY ${EXTERNAL_DEBUG_DIR}/dwp
|
||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/uprobe_test.c
|
||||
)
|
||||
list(APPEND testprogtargets
|
||||
@@ -19,6 +19,8 @@ SRC_URI = "git://github.com/iovisor/bpftrace;branch=release/0.26.x;protocol=http
|
||||
file://0003-cmake-BuildBPF.cmake-link-data-source-binary-without.patch \
|
||||
file://0004-IRBuilderBPF-Fix-HasTerminator-on-LLVM-23.patch \
|
||||
file://0005-CMakeLists-Add-support-for-LLVM-23.patch \
|
||||
file://0001-tests-pass-C-linker-flags-and-sysroot-to-raw-compile.patch \
|
||||
file://0006-tests-do-not-embed-build-paths-in-split-DWARF-test-pr.patch \
|
||||
"
|
||||
SRCREV = "1bac8a8daad6e0aa579980e877d0c9d5fc296593"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user