This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Check native binary format


If our native binary format is not ELF, there is no point in doing the
textrel check and we have to exclude some tests that compile source
code with the native compiler and then check something on the resulting
binary with elfutils.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
---
 ChangeLog                          |  4 ++++
 config/ChangeLog                   |  4 ++++
 config/eu.am                       |  4 ++++
 configure.ac                       |  3 +++
 tests/ChangeLog                    | 16 ++++++++++++++++
 tests/run-disasm-x86-64.sh         |  5 +++++
 tests/run-disasm-x86.sh            |  5 +++++
 tests/run-dwfllines.sh             |  5 +++++
 tests/run-elf_cntl_gelf_getshdr.sh |  5 +++++
 tests/run-elflint-self.sh          |  5 +++++
 tests/run-low_high_pc.sh           |  6 ++++++
 tests/run-native-test.sh           |  5 +++++
 tests/run-nm-self.sh               |  5 +++++
 tests/run-readelf-self.sh          |  5 +++++
 tests/run-strip-reloc.sh           |  5 +++++
 tests/run-strip-strmerge.sh        |  5 +++++
 tests/test-nlist.c                 |  6 +++++-
 17 files changed, 92 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 3613beb..d43eeb6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2017-04-28  Ulf Hermann  <ulf.hermann@qt.io>
 
+	* configure.ac: Determine the binary format we're building natively.
+
+2017-04-28  Ulf Hermann  <ulf.hermann@qt.io>
+
 	* configure.ac: Determine library naming conventions and define
 	LIBPREFIX, LIBEXT and common names for elf, dw, asm accordingly.
 
diff --git a/config/ChangeLog b/config/ChangeLog
index 59569e3..0f240ea 100644
--- a/config/ChangeLog
+++ b/config/ChangeLog
@@ -1,3 +1,7 @@
+2017-04-28  Ulf Hermann  <ulf.hermann@qt.io>
+
+	* eu.am: Disable textrel_check if we're not building ELF files.
+
 2017-04-27  Ulf Hermann  <ulf.hermann@qt.io>
 
 	* eu.am: Use fpic_CFLAGS.
diff --git a/config/eu.am b/config/eu.am
index bc8c767..e692341 100644
--- a/config/eu.am
+++ b/config/eu.am
@@ -107,7 +107,11 @@ textrel_found = $(textrel_msg); exit 1
 else
 textrel_found = $(textrel_msg)
 endif
+if NATIVE_ELF
 textrel_check = if $(READELF) -d $@ | fgrep -q TEXTREL; then $(textrel_found); fi
+else
+textrel_check =
+endif
 
 print-%:
 	@echo $*=$($*)
diff --git a/configure.ac b/configure.ac
index b2e03bb..18ef6d6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -88,6 +88,9 @@ AC_SUBST([LIBPREFIX])
 AC_DEFINE_UNQUOTED(LIBPREFIX, "$LIBPREFIX")
 AH_TEMPLATE([LIBPREFIX], [Host system file name prefix for dynamic libraries.])
 AM_CONDITIONAL(POSTFIX_LIB_VERSION, test "$eu_postfix_lib_version" = "yes")
+AM_CONDITIONAL(NATIVE_ELF, test "$LIBEXT" = ".so")
+AM_CONDITIONAL(NATIVE_PE, test "$LIBEXT" = ".dll")
+AM_CONDITIONAL(NATIVE_MACHO, test "$LIBEXT" = ".dylib")
 
 eu_LIBNAME(elf,1)
 eu_LIBNAME(dw,1)
diff --git a/tests/ChangeLog b/tests/ChangeLog
index d5bda6d..a9bc6fa 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,21 @@
 2017-04-28  Ulf Hermann  <ulf.hermann@qt.io>
 
+	* run-disasm-x86-64.sh: Disable if the native binary format is not
+	ELF.
+	* run-disasm-x86.sh: Likewise.
+	* run-dwfllines.sh: Likewise.
+	* run-elf_cntl_gelf_getshdr.sh: Likewise.
+	* run-elflint-self.sh: Likewise.
+	* run-low_high_pc.sh: Likewise.
+	* run-native-test.sh: Likewise.
+	* run-nm-self.sh: Likewise.
+	* run-readelf-self.sh: Likewise.
+	* run-strip-reloc.sh: Likewise.
+	* run-strip-strmerge.sh: Likewise.
+	* test-nlist.c: Likewise.
+
+2017-04-28  Ulf Hermann  <ulf.hermann@qt.io>
+
 	* Makefile.am: Use the predefined names for libelf, libdw, libasm,
 	rather than hardcoding to the elf conventions and add the right
 	extension to deleted-lib.<libext>.
diff --git a/tests/run-disasm-x86-64.sh b/tests/run-disasm-x86-64.sh
index a6be62b..c5256b7 100755
--- a/tests/run-disasm-x86-64.sh
+++ b/tests/run-disasm-x86-64.sh
@@ -17,6 +17,11 @@
 
 . $srcdir/test-subr.sh
 
+if ! grep -q -F '#define LIBEXT ".so"' ${abs_top_builddir}/config.h; then
+  echo "only works with native ELF binaries."
+  exit 77
+fi
+
 # Run x86-64 test.
 case "`uname -m`" in
   x86_64)
diff --git a/tests/run-disasm-x86.sh b/tests/run-disasm-x86.sh
index 28a3df7..e0b6ee3 100755
--- a/tests/run-disasm-x86.sh
+++ b/tests/run-disasm-x86.sh
@@ -17,6 +17,11 @@
 
 . $srcdir/test-subr.sh
 
+if ! grep -q -F '#define LIBEXT ".so"' ${abs_top_builddir}/config.h; then
+  echo "only works with native ELF binaries."
+  exit 77
+fi
+
 # Run x86 test.
 case "`uname -m`" in
   x86_64 | i?86 )
diff --git a/tests/run-dwfllines.sh b/tests/run-dwfllines.sh
index b384de0..c228d7d 100755
--- a/tests/run-dwfllines.sh
+++ b/tests/run-dwfllines.sh
@@ -83,6 +83,11 @@ mod:  CU: [9e4] m.c
  time: 0, len: 0, idx: 0, b: 1, e: 1, pe: 0, eb: 0, block: 0, isa: 0, disc: 0
 EOF
 
+if ! grep -q -F '#define LIBEXT ".so"' ${abs_top_builddir}/config.h; then
+  echo "self tests only work with native ELF binaries."
+  exit 77
+fi
+
 testrun_on_self_quiet ${abs_builddir}/dwfllines -e
 
 exit 0
diff --git a/tests/run-elf_cntl_gelf_getshdr.sh b/tests/run-elf_cntl_gelf_getshdr.sh
index 94b477c..6cf93af 100755
--- a/tests/run-elf_cntl_gelf_getshdr.sh
+++ b/tests/run-elf_cntl_gelf_getshdr.sh
@@ -17,6 +17,11 @@
 
 . $srcdir/test-subr.sh
 
+if ! grep -q -F '#define LIBEXT ".so"' ${abs_top_builddir}/config.h; then
+  echo "self tests only work with native ELF binaries."
+  exit 77
+fi
+
 tempfiles test_shdr.out
 
 # However we open the elf file, the shdrs should be the same.
diff --git a/tests/run-elflint-self.sh b/tests/run-elflint-self.sh
index 58fa7d0..fe6b0a4 100755
--- a/tests/run-elflint-self.sh
+++ b/tests/run-elflint-self.sh
@@ -18,5 +18,10 @@
 
 . $srcdir/test-subr.sh
 
+if ! grep -q -F '#define LIBEXT ".so"' ${abs_top_builddir}/config.h; then
+  echo "only works with native ELF binaries."
+  exit 77
+fi
+
 testrun_on_self ${abs_top_builddir}/src/elflint --quiet --gnu-ld
 testrun_on_self_compressed ${abs_top_builddir}/src/elflint --quiet --gnu-ld
diff --git a/tests/run-low_high_pc.sh b/tests/run-low_high_pc.sh
index ab5f2c3..db5b097 100755
--- a/tests/run-low_high_pc.sh
+++ b/tests/run-low_high_pc.sh
@@ -26,6 +26,12 @@
 testfiles testfile_low_high_pc
 
 testrun ${abs_builddir}/low_high_pc -e ./testfile_low_high_pc
+
+if ! grep -q -F '#define LIBEXT ".so"' ${abs_top_builddir}/config.h; then
+  echo "self tests only work with native ELF binaries."
+  exit 77
+fi
+
 testrun ${abs_builddir}/low_high_pc -e ${abs_builddir}/low_high_pc
 testrun ${abs_builddir}/low_high_pc -e ${abs_top_builddir}/src/strip
 testrun ${abs_builddir}/low_high_pc -e ${abs_top_builddir}/src/strip.o
diff --git a/tests/run-native-test.sh b/tests/run-native-test.sh
index d19007f..4adef49 100755
--- a/tests/run-native-test.sh
+++ b/tests/run-native-test.sh
@@ -18,6 +18,11 @@
 
 . $srcdir/test-subr.sh
 
+if ! grep -q -F '#define LIBEXT ".so"' ${abs_top_builddir}/config.h; then
+  echo "only works with native ELF binaries."
+  exit 77
+fi
+
 # This tests all the miscellaneous components of backend support
 # against whatever this build is running on.  A platform will fail
 # this test if it is missing parts of the backend implementation.
diff --git a/tests/run-nm-self.sh b/tests/run-nm-self.sh
index 6a31afc..a062c37 100755
--- a/tests/run-nm-self.sh
+++ b/tests/run-nm-self.sh
@@ -17,6 +17,11 @@
 
 . $srcdir/test-subr.sh
 
+if ! grep -q -F '#define LIBEXT ".so"' ${abs_top_builddir}/config.h; then
+  echo "only works with native ELF binaries."
+  exit 77
+fi
+
 # Test different command line combinations on the nm binary itself.
 # Test on nm ET_REL, ET_EXEC and ET_DYN files.
 ET_REL=${abs_top_builddir}/src/nm.o
diff --git a/tests/run-readelf-self.sh b/tests/run-readelf-self.sh
index 7ffb357..f645a14 100755
--- a/tests/run-readelf-self.sh
+++ b/tests/run-readelf-self.sh
@@ -17,5 +17,10 @@
 
 . $srcdir/test-subr.sh
 
+if ! grep -q -F '#define LIBEXT ".so"' ${abs_top_builddir}/config.h; then
+  echo "only works with native ELF binaries."
+  exit 77
+fi
+
 # Just makes sure readelf doesn't crash
 testrun_on_self_quiet ${abs_top_builddir}/src/readelf -a -w
diff --git a/tests/run-strip-reloc.sh b/tests/run-strip-reloc.sh
index e587eab..50dddbf 100755
--- a/tests/run-strip-reloc.sh
+++ b/tests/run-strip-reloc.sh
@@ -104,6 +104,11 @@ runtest hello_s390.ko 1
 runtest hello_aarch64.ko 1
 runtest hello_m68k.ko 1
 
+if ! grep -q -F '#define LIBEXT ".so"' ${abs_top_builddir}/config.h; then
+  echo "only works with native ELF binaries."
+  exit 77
+fi
+
 # self test, shouldn't impact non-ET_REL files at all.
 runtest ${abs_top_builddir}/src/strip 0
 runtest ${abs_top_builddir}/src/strip.o 1
diff --git a/tests/run-strip-strmerge.sh b/tests/run-strip-strmerge.sh
index aa9c1eb..d9d75fd 100755
--- a/tests/run-strip-strmerge.sh
+++ b/tests/run-strip-strmerge.sh
@@ -17,6 +17,11 @@
 
 . $srcdir/test-subr.sh
 
+if ! grep -q -F '#define LIBEXT ".so"' ${abs_top_builddir}/config.h; then
+  echo "only works with native ELF binaries."
+  exit 77
+fi
+
 # Generate a file with merged .shstrtab/.strtab table.
 # strip and unstrip it. Check all files with elflint.
 
diff --git a/tests/test-nlist.c b/tests/test-nlist.c
index 679c911..0616398 100644
--- a/tests/test-nlist.c
+++ b/tests/test-nlist.c
@@ -15,10 +15,11 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+#include <config.h>
 #include <nlist.h>
 #include <stdio.h>
 #include <stdlib.h>
-
+#include <string.h>
 
 int var = 1;
 
@@ -34,6 +35,9 @@ foo (int a)
 int
 main (int argc, char *argv[] __attribute__ ((unused)))
 {
+  if (strcmp(LIBEXT, ".so") != 0)
+    return 77; // test-nlist needs to be an ELF binary for this.
+
   struct nlist nl[6] =
   {
     [0] = { .n_name = "var" },
-- 
2.1.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]