]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
tests: Skip tests on non-ELF bitcode object files
authorMark Wielaard <mark@klomp.org>
Tue, 10 Feb 2026 17:25:42 +0000 (18:25 +0100)
committerMark Wielaard <mark@klomp.org>
Tue, 17 Feb 2026 12:47:29 +0000 (13:47 +0100)
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 <mark@klomp.org>
tests/run-elfclassify-self.sh
tests/run-nm-self.sh
tests/run-reverse-sections-self.sh
tests/run-strip-reloc-self.sh
tests/run-strip-strmerge.sh
tests/strip-reloc-subr.sh
tests/test-subr.sh

index c48ab9c93e92eb85ce50b8b5bd460387f12517d7..4d86cb24e7118534572b4ccb9197a5aa9841eb91 100755 (executable)
@@ -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
index 6a31afcf6bede655f907d0637493018690c6d607..e7d7c58d41d010ec1a0311538b2db4c449b55082 100755 (executable)
@@ -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
index 71afd6aca1f1ff6694a0c79ff6dba4e68e7085d8..d241775993d9d9479d0cfe85588e235481abcfa7 100755 (executable)
@@ -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
index 68ed4cc2702bacb67d4d72186ed194bf5ce0b7bb..73f5b6c366062ebe6b9a1b441b71dd03cca3d9fc 100755 (executable)
@@ -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
index aa9c1eb93283a26a5585b48d803144b935e89f72..0d24adef90b9282168ff30d91579081f1595df8f 100755 (executable)
@@ -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
index c4d55ced1596ae9f9076646228369052302254cb..045f5b0798ba534ed15c39a0c64cfab1eff21c64 100755 (executable)
@@ -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 ||
index 2a956b47de2f8fafea2cc1445275d6f37eea19c2..623b5b77451144aabcaf8a8c55bab32bfce71cd2 100644 (file)
@@ -1,5 +1,6 @@
 #! /bin/sh
 # Copyright (C) 2005-2015, 2017 Red Hat, Inc.
+# Copyright (C) 2026 Mark J. Wielaard <mark@klomp.org>
 # 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