From: Mark Wielaard Date: Tue, 10 Feb 2026 17:25:42 +0000 (+0100) Subject: tests: Skip tests on non-ELF bitcode object files X-Git-Tag: elfutils-0.195~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=559234740d435cfdc16333ec4645a8144a4a2319;p=thirdparty%2Felfutils.git tests: Skip tests on non-ELF bitcode object files clang with -flto produces object files that contain bitcode. This breaks various (self) testcases that expect those .o files are ELF files. eu-readelf, eu-nm, eu-elfline and eu-elfcompress won't work on such files. Add a helper function is_obj_bitcode in test-subr.sh that tests can use to possibly skip a check on an .o file. * tests/test-subr.sh (is_obj_bitcode): New function. (testrun_on_self): Use is_obj_bitcode to possibly skip a file. (testrun_on_self_obj): Likewise. (testrun_on_self_compressed): Likewise. (testrun_on_self_quiet): Likewise. * tests/run-elfclassify-self.sh: Check if the object files are actually ELF files. * tests/run-nm-self.sh: Use is_obj_bitcode to possibly skip file. * tests/run-reverse-sections-self.sh: Likewise. * tests/run-strip-reloc-self.sh: Likewise. * tests/run-strip-strmerge.sh: Likewise. * tests/strip-reloc-subr.sh: Likewise. Signed-off-by: Mark Wielaard --- diff --git a/tests/run-elfclassify-self.sh b/tests/run-elfclassify-self.sh index c48ab9c9..4d86cb24 100755 --- a/tests/run-elfclassify-self.sh +++ b/tests/run-elfclassify-self.sh @@ -32,5 +32,10 @@ testrun_on_self_exe ${abs_top_builddir}/src/elfclassify --program testrun_on_self_exe ${abs_top_builddir}/src/elfclassify --loadable testrun_on_self_exe ${abs_top_builddir}/src/elfclassify --not-shared -testrun ${abs_top_builddir}/src/elfclassify --not-shared $self_test_files_obj -testrun ${abs_top_builddir}/src/elfclassify --not-executable $self_test_files_obj +# Check if the object files are actually ELF files (could be bitcode lto) +if ${abs_top_builddir}/src/elfclassify -v --elf $self_test_files_obj; then + testrun ${abs_top_builddir}/src/elfclassify --not-shared $self_test_files_obj + testrun ${abs_top_builddir}/src/elfclassify --not-executable $self_test_files_obj +else + echo "*** Skipping testing not ELF files $self_test_files_obj" +fi diff --git a/tests/run-nm-self.sh b/tests/run-nm-self.sh index 6a31afcf..e7d7c58d 100755 --- a/tests/run-nm-self.sh +++ b/tests/run-nm-self.sh @@ -28,7 +28,11 @@ for what_arg in --debug-syms --defined-only --dynamic --extern-only; do for self_file in $ET_REL $ET_EXEC $ET_DYN; do # --dynamic doesn't make sense for ET_REL. if ! test "$what_arg" = "--dynamic" -a "$self_file" = "$ET_REL"; then - testrun ${abs_top_builddir}/src/nm $what_arg $format_arg $out_arg $self_file > /dev/null + if is_obj_bitcode "$self_file"; then + echo "*** skipping bitcode file $self_file" + else + testrun ${abs_top_builddir}/src/nm $what_arg $format_arg $out_arg $self_file > /dev/null + fi fi done done diff --git a/tests/run-reverse-sections-self.sh b/tests/run-reverse-sections-self.sh index 71afd6ac..d2417759 100755 --- a/tests/run-reverse-sections-self.sh +++ b/tests/run-reverse-sections-self.sh @@ -39,7 +39,11 @@ test_reverse_self () # Only really makes sense for ET_REL files, but try all, just to check # it also works if we keep the order for the allocated sections. for file in $self_test_files; do - test_reverse_self $file + if is_obj_bitcode "$file"; then + echo "*** skipping bitcode file $file" + else + test_reverse_self $file + fi done exit 0 diff --git a/tests/run-strip-reloc-self.sh b/tests/run-strip-reloc-self.sh index 68ed4cc2..73f5b6c3 100755 --- a/tests/run-strip-reloc-self.sh +++ b/tests/run-strip-reloc-self.sh @@ -8,6 +8,10 @@ runtest ${abs_top_builddir}/src/strip.o 1 # Copy ET_REL file for self-test and make sure to run with/without # elf section compression. +if is_obj_bitcode ${abs_top_builddir}/src/strip.o; then + echo "*** skipping bitcode file" + exit $runtest_status +fi tempfiles strip-uncompressed.o strip-compressed.o testrun ${abs_top_builddir}/src/elfcompress -o strip-uncompressed.o -t none \ ${abs_top_builddir}/src/strip.o diff --git a/tests/run-strip-strmerge.sh b/tests/run-strip-strmerge.sh index aa9c1eb9..0d24adef 100755 --- a/tests/run-strip-strmerge.sh +++ b/tests/run-strip-strmerge.sh @@ -50,6 +50,10 @@ testrun ${abs_top_builddir}/src/elfcmp $merged $remerged # A random ET_REL file input=${abs_top_builddir}/tests/elfstrmerge.o +if is_obj_bitcode "$input"; then + echo "*** skipping bitcode file $self_file" + exit 0 +fi merged=merged.elf stripped=${merged}.stripped debugfile=${merged}.debug diff --git a/tests/strip-reloc-subr.sh b/tests/strip-reloc-subr.sh index c4d55ced..045f5b07 100755 --- a/tests/strip-reloc-subr.sh +++ b/tests/strip-reloc-subr.sh @@ -36,6 +36,11 @@ runtest() { echo "runtest $infile" + if is_obj_bitcode "$infile"; then + echo "*** skipping bitcode file $infile" + return + fi + rm -f $outfile1 $debugfile1 $outfile2 $debugfile2 testrun ${abs_top_builddir}/src/strip -o $outfile1 -f $debugfile1 $infile || diff --git a/tests/test-subr.sh b/tests/test-subr.sh index 2a956b47..623b5b77 100644 --- a/tests/test-subr.sh +++ b/tests/test-subr.sh @@ -1,5 +1,6 @@ #! /bin/sh # Copyright (C) 2005-2015, 2017 Red Hat, Inc. +# Copyright (C) 2026 Mark J. Wielaard # This file is part of elfutils. # # This file is free software; you can redistribute it and/or modify @@ -118,6 +119,13 @@ program_transform() echo "$*" | sed "${program_transform_name}" } +is_obj_bitcode() +{ + bcfile="$1" + BC=$(od -An -tx2 -N2 "$bcfile" | sed -e 's/^[[:space:]]*//') + if [ "'$BC'" = "'4342'" ]; then return 0; else return 1; fi +} + self_test_files_exe=`echo ${abs_top_builddir}/src/addr2line \ ${abs_top_builddir}/src/elfclassify \ ${abs_top_builddir}/src/stack \ @@ -137,8 +145,12 @@ testrun_on_self() exit_status=0 for file in $self_test_files; do + if is_obj_bitcode "$file"; then + echo "*** skipping bitcode file in $* $file" + else testrun $* $file \ || { echo "*** failure in $* $file"; exit_status=1; } + fi done # Only exit if something failed @@ -176,8 +188,12 @@ testrun_on_self_obj() exit_status=0 for file in $self_test_files_obj; do + if is_obj_bitcode "$file"; then + echo "*** skipping bitcode file in $* $file" + else testrun $* $file \ || { echo "*** failure in $* $file"; exit_status=1; } + fi done # Only exit if something failed @@ -190,12 +206,16 @@ testrun_on_self_compressed() exit_status=0 for file in $self_test_files; do + if is_obj_bitcode "$file"; then + echo "*** skipping bitcode file in $* $file" + else tempfiles ${file}z testrun ${abs_top_builddir}/src/elfcompress -f -q -o ${file}z ${file} testrun ${abs_top_builddir}/src/elfcompress -f -q --name='.s??tab' ${file}z testrun $* ${file}z \ || { echo "*** failure in $* ${file}z"; exit_status=1; } + fi done # Only exit if something failed @@ -208,8 +228,12 @@ testrun_on_self_quiet() exit_status=0 for file in $self_test_files; do + if is_obj_bitcode "$file"; then + echo "*** skipping bitcode file in $* $file" + else testrun $* $file > /dev/null \ || { echo "*** failure in $* $file"; exit_status=1; } + fi done # Only exit if something failed