From 3abc97620b7e4015705e4767ffa1ed7f6609505f Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: May 21 2019 09:25:27 +0000 Subject: Support build-id generation from compressed ELF files (#1650072) --- diff --git a/0001-Detect-kernel-modules-by-.modinfo-section-presence-f.patch b/0001-Detect-kernel-modules-by-.modinfo-section-presence-f.patch new file mode 100644 index 0000000..5bf673b --- /dev/null +++ b/0001-Detect-kernel-modules-by-.modinfo-section-presence-f.patch @@ -0,0 +1,69 @@ +From 68d383c39cef8d58b80940b13dd132d3f41a03f0 Mon Sep 17 00:00:00 2001 +Message-Id: <68d383c39cef8d58b80940b13dd132d3f41a03f0.1558430547.git.pmatilai@redhat.com> +From: Panu Matilainen +Date: Tue, 2 Apr 2019 15:22:07 +0300 +Subject: [PATCH 1/2] Detect kernel modules by .modinfo section presence for + build-id generation + +File extension based heuristics only work so far at best, and break +completely on compressed files with arbitrary .gz/.xz etc extension. +This isn't supposed to change any behavior as such, only provide more +reliable detection of kernel modules. +--- + build/files.c | 27 ++++++++++++++++++++++++--- + 1 file changed, 24 insertions(+), 3 deletions(-) + +diff --git a/build/files.c b/build/files.c +index dbad9a7f3..3822be3d3 100644 +--- a/build/files.c ++++ b/build/files.c +@@ -1739,6 +1739,28 @@ static int addNewIDSymlink(ARGV_t *files, + return rc; + } + ++static int haveModinfo(Elf *elf) ++{ ++ Elf_Scn * scn = NULL; ++ size_t shstrndx; ++ int have_modinfo = 0; ++ const char *sname; ++ ++ if (elf_getshdrstrndx(elf, &shstrndx) == 0) { ++ while ((scn = elf_nextscn(elf, scn)) != NULL) { ++ GElf_Shdr shdr_mem, *shdr = gelf_getshdr(scn, &shdr_mem); ++ if (shdr == NULL) ++ continue; ++ sname = elf_strptr(elf, shstrndx, shdr->sh_name); ++ if (sname && rstreq(sname, ".modinfo")) { ++ have_modinfo = 1; ++ break; ++ } ++ } ++ } ++ return have_modinfo; ++} ++ + static int generateBuildIDs(FileList fl, ARGV_t *files) + { + int rc = 0; +@@ -1803,15 +1825,14 @@ static int generateBuildIDs(FileList fl, ARGV_t *files) + int fd = open (flp->diskPath, O_RDONLY); + if (fd >= 0) { + /* Only real ELF files, that are ET_EXEC, ET_DYN or +- kernel modules (ET_REL files with names ending in .ko) ++ kernel modules (ET_REL files with .modinfo section) + should have build-ids. */ + GElf_Ehdr ehdr; + Elf *elf = elf_begin (fd, ELF_C_READ, NULL); + if (elf != NULL && elf_kind(elf) == ELF_K_ELF + && gelf_getehdr(elf, &ehdr) != NULL + && (ehdr.e_type == ET_EXEC || ehdr.e_type == ET_DYN +- || (ehdr.e_type == ET_REL +- && rpmFileHasSuffix (flp->diskPath, ".ko")))) { ++ || (ehdr.e_type == ET_REL && haveModinfo(elf)))) { + const void *build_id; + ssize_t len = dwelf_elf_gnu_build_id (elf, &build_id); + /* len == -1 means error. Zero means no +-- +2.21.0 + diff --git a/0002-Support-build-id-generation-from-compressed-ELF-file.patch b/0002-Support-build-id-generation-from-compressed-ELF-file.patch new file mode 100644 index 0000000..2c34ed1 --- /dev/null +++ b/0002-Support-build-id-generation-from-compressed-ELF-file.patch @@ -0,0 +1,52 @@ +From d48981ad7e36abb3500161d823acf92345c94f5d Mon Sep 17 00:00:00 2001 +Message-Id: +In-Reply-To: <68d383c39cef8d58b80940b13dd132d3f41a03f0.1558430547.git.pmatilai@redhat.com> +References: <68d383c39cef8d58b80940b13dd132d3f41a03f0.1558430547.git.pmatilai@redhat.com> +From: Panu Matilainen +Date: Tue, 2 Apr 2019 16:07:56 +0300 +Subject: [PATCH 2/2] Support build-id generation from compressed ELF files + (elfutils >= 0.175) + +Use dwelf_elf_begin() for reading ELF files for build-id generation on +versions that have it to support compressed ELF files such as kernel +modules (RhBug:1650072,1650074). Note that debugedit still cannot handle +compressed files, this is only for build-id generation. +--- + build/files.c | 4 ++++ + configure.ac | 4 ++++ + 2 files changed, 8 insertions(+) + +diff --git a/build/files.c b/build/files.c +index 3822be3d3..f72a7c866 100644 +--- a/build/files.c ++++ b/build/files.c +@@ -1828,7 +1828,11 @@ static int generateBuildIDs(FileList fl, ARGV_t *files) + kernel modules (ET_REL files with .modinfo section) + should have build-ids. */ + GElf_Ehdr ehdr; ++#if HAVE_DWELF_ELF_BEGIN ++ Elf *elf = dwelf_elf_begin(fd); ++#else + Elf *elf = elf_begin (fd, ELF_C_READ, NULL); ++#endif + if (elf != NULL && elf_kind(elf) == ELF_K_ELF + && gelf_getehdr(elf, &ehdr) != NULL + && (ehdr.e_type == ET_EXEC || ehdr.e_type == ET_DYN +diff --git a/configure.ac b/configure.ac +index 99ce7df32..b2d7ed806 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -487,6 +487,10 @@ AS_IF([test "$WITH_LIBELF" = yes],[ + # If possible we also want the strtab functions from elfutils 0.167. + # But we can fall back on the (unsupported) ebl alternatives if not. + AC_CHECK_LIB(dw, dwelf_strtab_init, [HAVE_LIBDW_STRTAB=yes]) ++ # whether libdw supports compressed ELF objects ++ AC_CHECK_LIB(dw, dwelf_elf_begin, [ ++ AC_DEFINE(HAVE_DWELF_ELF_BEGIN, 1, [Have dwelf_elf_begin?]) ++ ]) + ]) + ]) + ]) +-- +2.21.0 + diff --git a/rpm.spec b/rpm.spec index 903dba4..4110b99 100644 --- a/rpm.spec +++ b/rpm.spec @@ -23,7 +23,7 @@ %global rpmver 4.14.2.1 #global snapver rc2 -%global rel 9 +%global rel 10 %global srcver %{version}%{?snapver:-%{snapver}} %global srcdir %{?snapver:testing}%{!?snapver:%{name}-%(echo %{version} | cut -d'.' -f1-2).x} @@ -63,6 +63,8 @@ Patch104: 0001-Take-_prefix-into-account-when-compressing-man-pages.patch Patch105: rpm-4.14.2-RPMTAG_MODULARITYLABEL.patch Patch106: 0001-find-debuginfo.sh-Handle-position-independent-execut.patch Patch107: 0001-Add-flag-to-use-strip-g-instead-of-full-strip-on-DSO.patch +Patch108: 0001-Detect-kernel-modules-by-.modinfo-section-presence-f.patch +Patch109: 0002-Support-build-id-generation-from-compressed-ELF-file.patch # Python 3 string API sanity Patch150: 0001-In-Python-3-return-all-our-string-data-as-surrogate-.patch @@ -578,6 +580,9 @@ make check || (cat tests/rpmtests.log; exit 1) %doc doc/librpm/html/* %changelog +* Tue May 21 2019 Panu Matilainen - 4.14.2.1-10 +- Support build-id generation from compressed ELF files (#1650072) + * Fri May 03 2019 Igor Gnatenko - 4.14.2.1-9 - Suggest gdb-minimal