From c6952c636665d4852a91eb664c3856e766851820 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 17 Mar 2017 20:54:07 +0100 Subject: [PATCH] Fix reading and updating (cross-endian) build-id information. --- 0018-update-build-id-endian.patch | 91 +++++++++++++++++++++++++++++++ rpm.spec | 6 +- 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 0018-update-build-id-endian.patch diff --git a/0018-update-build-id-endian.patch b/0018-update-build-id-endian.patch new file mode 100644 index 0000000..18690a3 --- /dev/null +++ b/0018-update-build-id-endian.patch @@ -0,0 +1,91 @@ +diff --git a/tools/debugedit.c b/tools/debugedit.c +index 4798c63..47e5bbf 100644 +--- a/tools/debugedit.c ++++ b/tools/debugedit.c +@@ -2581,40 +2581,25 @@ main (int argc, char *argv[]) + break; + case SHT_NOTE: + if (do_build_id +- && build_id == NULL && (dso->shdr[i].sh_flags & SHF_ALLOC)) ++ && build_id == 0 && (dso->shdr[i].sh_flags & SHF_ALLOC)) + { + /* Look for a build-ID note here. */ ++ size_t off = 0; ++ GElf_Nhdr nhdr; ++ size_t name_off; ++ size_t desc_off; + Elf_Data *data = elf_getdata (elf_getscn (dso->elf, i), NULL); +- Elf32_Nhdr nh; +- Elf_Data dst = +- { +- .d_version = EV_CURRENT, .d_type = ELF_T_NHDR, +- .d_buf = &nh, .d_size = sizeof nh +- }; +- Elf_Data src = dst; +- src.d_buf = data->d_buf; +- assert (sizeof (Elf32_Nhdr) == sizeof (Elf64_Nhdr)); +- while ((char *) data->d_buf + data->d_size - +- (char *) src.d_buf > (int) sizeof nh +- && elf32_xlatetom (&dst, &src, dso->ehdr.e_ident[EI_DATA])) +- { +- Elf32_Word len = sizeof nh + nh.n_namesz; +- len = (len + 3) & ~3; +- +- if (nh.n_namesz == sizeof "GNU" && nh.n_type == 3 +- && !memcmp ((char *) src.d_buf + sizeof nh, "GNU", sizeof "GNU")) +- { +- build_id = data; +- build_id_offset = (char *) src.d_buf + len - +- (char *) data->d_buf; +- build_id_size = nh.n_descsz; +- break; +- } +- +- len += nh.n_descsz; +- len = (len + 3) & ~3; +- src.d_buf = (char *) src.d_buf + len; +- } ++ while ((off = gelf_getnote (data, off, ++ &nhdr, &name_off, &desc_off)) > 0) ++ if (nhdr.n_type == NT_GNU_BUILD_ID ++ && nhdr.n_namesz == sizeof "GNU" ++ && (memcmp ((char *)data->d_buf + name_off, "GNU", ++ sizeof "GNU") == 0)) ++ { ++ build_id = data; ++ build_id_offset = desc_off; ++ build_id_size = nhdr.n_descsz; ++ } + } + break; + default: +@@ -2622,6 +2607,20 @@ main (int argc, char *argv[]) + } + } + ++ /* Normally we only need to explicitly update the section headers ++ and data when any section data changed size. But because of a bug ++ in elfutils before 0.169 we will have to update and write out all ++ section data if any data has changed (when ELF_F_LAYOUT was ++ set). https://sourceware.org/bugzilla/show_bug.cgi?id=21199 */ ++ bool need_update = need_strp_update || need_stmt_update; ++ ++#if !_ELFUTILS_PREREQ (0, 169) ++ /* string replacements or build_id updates don't change section size. */ ++ need_update = (need_update ++ || need_string_replacement ++ || (do_build_id && build_id != NULL)); ++#endif ++ + /* We might have changed the size of some debug sections. If so make + sure the section headers are updated and the data offsets are + correct. We set ELF_F_LAYOUT above because we don't want libelf +@@ -2631,7 +2630,7 @@ main (int argc, char *argv[]) + anything for the phdrs allocated sections. Keep the offset of + allocated sections so they are at the same place in the file. Add + unallocated ones after the allocated ones. */ +- if (dso->phnum != 0 && (need_strp_update || need_stmt_update)) ++ if (dso->phnum != 0 && need_update) + { + Elf *elf = dso->elf; + GElf_Off last_offset; diff --git a/rpm.spec b/rpm.spec index 3259100..97bcdd8 100644 --- a/rpm.spec +++ b/rpm.spec @@ -29,7 +29,7 @@ Summary: The RPM package management system Name: rpm Version: %{rpmver} -Release: %{?snapver:0.%{snapver}.}11%{?dist} +Release: %{?snapver:0.%{snapver}.}12%{?dist} Group: System Environment/Base Url: http://www.rpm.org/ Source0: http://rpm.org/releases/%{srcdir}/%{name}-%{srcver}.tar.bz2 @@ -89,6 +89,7 @@ Patch263: 0014-generateBuildIDs-Fix-error-handling.patch Patch264: 0015-reset-buildid-file-attrs.patch Patch265: 0016-debugedit-replace-files.patch Patch266: 0017-do-not-process-buildi-ds-for-noarch.patch +Patch267: 0018-update-build-id-endian.patch # OpenSSL backend Patch300: 0001-Add-OpenSSL-support-for-digest-and-signatures.patch @@ -593,6 +594,9 @@ exit 0 %doc doc/librpm/html/* %changelog +* Fri Mar 17 2017 Mark Wielaard - 4.13.0.1-12 +- Fix reading and updating (cross-endian) build-id information. + * Fri Mar 17 2017 Mark Wielaard - 4.13.0.1-11 - Do not process build-ids for noarch packages.