commit 344ca0775da729e1bfdd61bb88ba4c64befece07 Author: Mark Wielaard Date: Wed Jan 13 17:16:48 2016 +0100 libelf: Add ELF compression types and defines to libelf.h for older glibc. Older glibc elf.h might not define the new ELF compression defines and types. If not just define them in libelf.h directly to make the libelf headers work on older glibc systems. Also include a testcase to check the libelf headers build against the system elf.h. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=810885 Signed-off-by: Mark Wielaard diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 3a1fe91..aabf6f6 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,8 @@ +2016-01-13 Mark Wielaard + + * libelf.h: Check SHF_COMPRESSED is defined. If not define it and the + associated ELF compression types/defines. + 2015-11-26 Mark Wielaard * elf_compress.c (__libelf_decompress_elf): New function, extracted diff --git a/libelf/libelf.h b/libelf/libelf.h index 364e776..c0d6389 100644 --- a/libelf/libelf.h +++ b/libelf/libelf.h @@ -35,6 +35,34 @@ /* Get the ELF types. */ #include +#ifndef SHF_COMPRESSED + /* Older glibc elf.h might not yet define the ELF compression types. */ + #define SHF_COMPRESSED (1 << 11) /* Section with compressed data. */ + + /* Section compression header. Used when SHF_COMPRESSED is set. */ + + typedef struct + { + Elf32_Word ch_type; /* Compression format. */ + Elf32_Word ch_size; /* Uncompressed data size. */ + Elf32_Word ch_addralign; /* Uncompressed data alignment. */ + } Elf32_Chdr; + + typedef struct + { + Elf64_Word ch_type; /* Compression format. */ + Elf64_Word ch_reserved; + Elf64_Xword ch_size; /* Uncompressed data size. */ + Elf64_Xword ch_addralign; /* Uncompressed data alignment. */ + } Elf64_Chdr; + + /* Legal values for ch_type (compression algorithm). */ + #define ELFCOMPRESS_ZLIB 1 /* ZLIB/DEFLATE algorithm. */ + #define ELFCOMPRESS_LOOS 0x60000000 /* Start of OS-specific. */ + #define ELFCOMPRESS_HIOS 0x6fffffff /* End of OS-specific. */ + #define ELFCOMPRESS_LOPROC 0x70000000 /* Start of processor-specific. */ + #define ELFCOMPRESS_HIPROC 0x7fffffff /* End of processor-specific. */ +#endif /* Known translation types. */ typedef enum diff --git a/tests/ChangeLog b/tests/ChangeLog index 366aea9..234ae56 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,11 @@ +2016-01-13 Mark Wielaard + + * system-elf-libelf-test.c: New test. + * Makefile.am (TESTS): Add system-elf-libelf-test, if !STANDALONE. + (check_PROGRAMS): Likewise. + (system_elf_libelf_test_CPPFLAGS): New variable. + (system_elf_libelf_test_LDADD): Likewise. + 2016-01-08 Mark Wielaard * elfputzdata.c (main): Fix parentheses in strncmp test. diff --git a/tests/Makefile.am b/tests/Makefile.am index d09a6d7..7b9e108 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -136,8 +136,8 @@ export ELFUTILS_DISABLE_DEMANGLE = 1 endif if !STANDALONE -check_PROGRAMS += msg_tst md5-sha1-test -TESTS += msg_tst md5-sha1-test +check_PROGRAMS += msg_tst md5-sha1-test system-elf-libelf-test +TESTS += msg_tst md5-sha1-test system-elf-libelf-test endif if LZMA @@ -473,6 +473,11 @@ elfgetzdata_LDADD = $(libelf) elfputzdata_LDADD = $(libelf) zstrptr_LDADD = $(libelf) +# We want to test the libelf header against the system elf.h header. +# Don't include any -I CPPFLAGS. +system_elf_libelf_test_CPPFLAGS = +system_elf_libelf_test_LDADD = $(libelf) + if GCOV check: check-am coverage .PHONY: coverage diff --git a/tests/system-elf-libelf-test.c b/tests/system-elf-libelf-test.c new file mode 100644 index 0000000..7dfe498 --- /dev/null +++ b/tests/system-elf-libelf-test.c @@ -0,0 +1,35 @@ +/* Explicit test compiling with system elf.h header plus libelf header. + + Copyright (C) 2016 Red Hat, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include +#include +#include "../libelf/libelf.h" + +int +main (void) +{ + /* Trivial test, this is really a compile test anyway. */ + if (elf_version (EV_CURRENT) == EV_NONE) + return -1; + + /* This will obviously fail. It is just to check that Elf32_Chdr and + elf32_getchdr are available (both at compile time and runtime). */ + Elf32_Chdr *chdr = elf32_getchdr (NULL); + + return chdr == NULL ? 0 : -1; +} diff -ru elfutils-0.165.orig/tests/Makefile.in elfutils-0.165/tests/Makefile.in --- elfutils-0.165.orig/tests/Makefile.in 2016-01-14 14:37:27.557995293 +0100 +++ elfutils-0.165/tests/Makefile.in 2016-01-14 14:37:39.621953358 +0100 @@ -186,8 +186,8 @@ run-elfputzdata.sh run-zstrptr.sh run-compress-test.sh \ run-readelf-zdebug.sh run-readelf-zdebug-rel.sh \ $(am__EXEEXT_2) $(am__append_8) $(am__EXEEXT_4) -@STANDALONE_FALSE@am__append_6 = msg_tst md5-sha1-test -@STANDALONE_FALSE@am__append_7 = msg_tst md5-sha1-test +@STANDALONE_FALSE@am__append_6 = msg_tst md5-sha1-test system-elf-libelf-test +@STANDALONE_FALSE@am__append_7 = msg_tst md5-sha1-test system-elf-libelf-test @LZMA_TRUE@am__append_8 = run-readelf-s.sh run-dwflsyms.sh @HAVE_LIBASM_TRUE@am__append_9 = $(asm_TESTS) @HAVE_LIBASM_TRUE@am__append_10 = $(asm_TESTS) @@ -206,7 +206,8 @@ CONFIG_CLEAN_VPATH_FILES = @BIARCH_TRUE@am__EXEEXT_1 = backtrace-child-biarch$(EXEEXT) @STANDALONE_FALSE@am__EXEEXT_2 = msg_tst$(EXEEXT) \ -@STANDALONE_FALSE@ md5-sha1-test$(EXEEXT) +@STANDALONE_FALSE@ md5-sha1-test$(EXEEXT) \ +@STANDALONE_FALSE@ system-elf-libelf-test$(EXEEXT) am__EXEEXT_3 = asm-tst1$(EXEEXT) asm-tst2$(EXEEXT) asm-tst3$(EXEEXT) \ asm-tst4$(EXEEXT) asm-tst5$(EXEEXT) asm-tst6$(EXEEXT) \ asm-tst7$(EXEEXT) asm-tst8$(EXEEXT) asm-tst9$(EXEEXT) @@ -490,6 +491,10 @@ strptr_SOURCES = strptr.c strptr_OBJECTS = strptr.$(OBJEXT) strptr_DEPENDENCIES = $(am__DEPENDENCIES_2) +system_elf_libelf_test_SOURCES = system-elf-libelf-test.c +system_elf_libelf_test_OBJECTS = \ + system_elf_libelf_test-system-elf-libelf-test.$(OBJEXT) +system_elf_libelf_test_DEPENDENCIES = $(am__DEPENDENCIES_2) test_elf_cntl_gelf_getshdr_SOURCES = test-elf_cntl_gelf_getshdr.c test_elf_cntl_gelf_getshdr_OBJECTS = \ test-elf_cntl_gelf_getshdr.$(OBJEXT) @@ -578,9 +583,10 @@ low_high_pc.c md5-sha1-test.c msg_tst.c newdata.c newfile.c \ newscn.c rdwrmmap.c rerequest_tag.c saridx.c scnnames.c \ sectiondump.c show-abbrev.c show-die-info.c showptable.c \ - strptr.c test-elf_cntl_gelf_getshdr.c test-flag-nobits.c \ - test-nlist.c typeiter.c typeiter2.c update1.c update2.c \ - update3.c update4.c varlocs.c vdsosyms.c zstrptr.c + strptr.c system-elf-libelf-test.c test-elf_cntl_gelf_getshdr.c \ + test-flag-nobits.c test-nlist.c typeiter.c typeiter2.c \ + update1.c update2.c update3.c update4.c varlocs.c vdsosyms.c \ + zstrptr.c DIST_SOURCES = addrcfi.c addrscopes.c aggregate_size.c alldts.c \ allfcts.c allregs.c arextract.c arls.c arsymtest.c asm-tst1.c \ asm-tst2.c asm-tst3.c asm-tst4.c asm-tst5.c asm-tst6.c \ @@ -599,9 +605,10 @@ low_high_pc.c md5-sha1-test.c msg_tst.c newdata.c newfile.c \ newscn.c rdwrmmap.c rerequest_tag.c saridx.c scnnames.c \ sectiondump.c show-abbrev.c show-die-info.c showptable.c \ - strptr.c test-elf_cntl_gelf_getshdr.c test-flag-nobits.c \ - test-nlist.c typeiter.c typeiter2.c update1.c update2.c \ - update3.c update4.c varlocs.c vdsosyms.c zstrptr.c + strptr.c system-elf-libelf-test.c test-elf_cntl_gelf_getshdr.c \ + test-flag-nobits.c test-nlist.c typeiter.c typeiter2.c \ + update1.c update2.c update3.c update4.c varlocs.c vdsosyms.c \ + zstrptr.c am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -1301,6 +1308,11 @@ elfgetzdata_LDADD = $(libelf) elfputzdata_LDADD = $(libelf) zstrptr_LDADD = $(libelf) + +# We want to test the libelf header against the system elf.h header. +# Don't include any -I CPPFLAGS. +system_elf_libelf_test_CPPFLAGS = +system_elf_libelf_test_LDADD = $(libelf) all: all-am .SUFFIXES: @@ -1635,6 +1647,10 @@ @rm -f strptr$(EXEEXT) $(AM_V_CCLD)$(LINK) $(strptr_OBJECTS) $(strptr_LDADD) $(LIBS) +system-elf-libelf-test$(EXEEXT): $(system_elf_libelf_test_OBJECTS) $(system_elf_libelf_test_DEPENDENCIES) $(EXTRA_system_elf_libelf_test_DEPENDENCIES) + @rm -f system-elf-libelf-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(system_elf_libelf_test_OBJECTS) $(system_elf_libelf_test_LDADD) $(LIBS) + test-elf_cntl_gelf_getshdr$(EXEEXT): $(test_elf_cntl_gelf_getshdr_OBJECTS) $(test_elf_cntl_gelf_getshdr_DEPENDENCIES) $(EXTRA_test_elf_cntl_gelf_getshdr_DEPENDENCIES) @rm -f test-elf_cntl_gelf_getshdr$(EXEEXT) $(AM_V_CCLD)$(LINK) $(test_elf_cntl_gelf_getshdr_OBJECTS) $(test_elf_cntl_gelf_getshdr_LDADD) $(LIBS) @@ -1764,6 +1780,7 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/show-die-info.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/showptable.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strptr.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/system_elf_libelf_test-system-elf-libelf-test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-elf_cntl_gelf_getshdr.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-flag-nobits.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-nlist.Po@am__quote@ @@ -1833,6 +1850,20 @@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(deleted_lib_so_CFLAGS) $(CFLAGS) -c -o deleted_lib_so-deleted-lib.obj `if test -f 'deleted-lib.c'; then $(CYGPATH_W) 'deleted-lib.c'; else $(CYGPATH_W) '$(srcdir)/deleted-lib.c'; fi` +system_elf_libelf_test-system-elf-libelf-test.o: system-elf-libelf-test.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(system_elf_libelf_test_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT system_elf_libelf_test-system-elf-libelf-test.o -MD -MP -MF $(DEPDIR)/system_elf_libelf_test-system-elf-libelf-test.Tpo -c -o system_elf_libelf_test-system-elf-libelf-test.o `test -f 'system-elf-libelf-test.c' || echo '$(srcdir)/'`system-elf-libelf-test.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/system_elf_libelf_test-system-elf-libelf-test.Tpo $(DEPDIR)/system_elf_libelf_test-system-elf-libelf-test.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='system-elf-libelf-test.c' object='system_elf_libelf_test-system-elf-libelf-test.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(system_elf_libelf_test_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o system_elf_libelf_test-system-elf-libelf-test.o `test -f 'system-elf-libelf-test.c' || echo '$(srcdir)/'`system-elf-libelf-test.c + +system_elf_libelf_test-system-elf-libelf-test.obj: system-elf-libelf-test.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(system_elf_libelf_test_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT system_elf_libelf_test-system-elf-libelf-test.obj -MD -MP -MF $(DEPDIR)/system_elf_libelf_test-system-elf-libelf-test.Tpo -c -o system_elf_libelf_test-system-elf-libelf-test.obj `if test -f 'system-elf-libelf-test.c'; then $(CYGPATH_W) 'system-elf-libelf-test.c'; else $(CYGPATH_W) '$(srcdir)/system-elf-libelf-test.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/system_elf_libelf_test-system-elf-libelf-test.Tpo $(DEPDIR)/system_elf_libelf_test-system-elf-libelf-test.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='system-elf-libelf-test.c' object='system_elf_libelf_test-system-elf-libelf-test.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(system_elf_libelf_test_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o system_elf_libelf_test-system-elf-libelf-test.obj `if test -f 'system-elf-libelf-test.c'; then $(CYGPATH_W) 'system-elf-libelf-test.c'; else $(CYGPATH_W) '$(srcdir)/system-elf-libelf-test.c'; fi` + ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-am @@ -3047,6 +3078,13 @@ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +system-elf-libelf-test.log: system-elf-libelf-test$(EXEEXT) + @p='system-elf-libelf-test$(EXEEXT)'; \ + b='system-elf-libelf-test'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) run-readelf-s.sh.log: run-readelf-s.sh @p='run-readelf-s.sh'; \