From 39568516c30c1ad5a956cfaca0d9fca8af3a5de5 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Mon, 30 Jul 2018 00:27:06 +0200 Subject: [PATCH] 0.173-7 - Add elfutils-0.173-strip-alloc-nonalloc.patch (#1609577) --- elfutils-0.173-strip-alloc-nonalloc.patch | 108 ++++++++++++++++++++++ elfutils.spec | 7 +- 2 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 elfutils-0.173-strip-alloc-nonalloc.patch diff --git a/elfutils-0.173-strip-alloc-nonalloc.patch b/elfutils-0.173-strip-alloc-nonalloc.patch new file mode 100644 index 0000000..700a516 --- /dev/null +++ b/elfutils-0.173-strip-alloc-nonalloc.patch @@ -0,0 +1,108 @@ +diff --git a/src/strip.c b/src/strip.c +index 791347c..1367de7 100644 +--- a/src/strip.c ++++ b/src/strip.c +@@ -661,6 +661,11 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, + memset (shdr_info, '\0', (shnum + 2) * sizeof (struct shdr_info)); + } + ++ /* Track whether allocated sections all come before non-allocated ones. */ ++ bool seen_allocated = false; ++ bool seen_unallocated = false; ++ bool mixed_allocated_unallocated = false; ++ + /* Prepare section information data structure. */ + scn = NULL; + cnt = 1; +@@ -676,6 +681,17 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, + if (gelf_getshdr (scn, &shdr_info[cnt].shdr) == NULL) + INTERNAL_ERROR (fname); + ++ /* Normally (in non-ET_REL files) we see all allocated sections first, ++ then all non-allocated. */ ++ if ((shdr_info[cnt].shdr.sh_flags & SHF_ALLOC) == 0) ++ seen_unallocated = true; ++ else ++ { ++ if (seen_unallocated && seen_allocated) ++ mixed_allocated_unallocated = true; ++ seen_allocated = true; ++ } ++ + /* Get the name of the section. */ + shdr_info[cnt].name = elf_strptr (elf, shstrndx, + shdr_info[cnt].shdr.sh_name); +@@ -1535,24 +1551,58 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, + } + } + +- /* If we have to, compute the offset of the section. */ +- if (shdr_info[cnt].shdr.sh_offset == 0) +- shdr_info[cnt].shdr.sh_offset +- = ((lastoffset + shdr_info[cnt].shdr.sh_addralign - 1) +- & ~((GElf_Off) (shdr_info[cnt].shdr.sh_addralign - 1))); +- +- /* Set the section header in the new file. */ +- if (unlikely (gelf_update_shdr (scn, &shdr_info[cnt].shdr) == 0)) +- /* There cannot be any overflows. */ +- INTERNAL_ERROR (fname); ++ /* If we have to, compute the offset of the section. ++ If allocate and unallocated sections are mixed, we only update ++ the allocated ones now. The unallocated ones come second. */ ++ if (! mixed_allocated_unallocated ++ || (shdr_info[cnt].shdr.sh_flags & SHF_ALLOC) != 0) ++ { ++ if (shdr_info[cnt].shdr.sh_offset == 0) ++ shdr_info[cnt].shdr.sh_offset ++ = ((lastoffset + shdr_info[cnt].shdr.sh_addralign - 1) ++ & ~((GElf_Off) (shdr_info[cnt].shdr.sh_addralign - 1))); ++ ++ /* Set the section header in the new file. */ ++ if (unlikely (gelf_update_shdr (scn, &shdr_info[cnt].shdr) == 0)) ++ /* There cannot be any overflows. */ ++ INTERNAL_ERROR (fname); + +- /* Remember the last section written so far. */ +- GElf_Off filesz = (shdr_info[cnt].shdr.sh_type != SHT_NOBITS +- ? shdr_info[cnt].shdr.sh_size : 0); +- if (lastoffset < shdr_info[cnt].shdr.sh_offset + filesz) +- lastoffset = shdr_info[cnt].shdr.sh_offset + filesz; ++ /* Remember the last section written so far. */ ++ GElf_Off filesz = (shdr_info[cnt].shdr.sh_type != SHT_NOBITS ++ ? shdr_info[cnt].shdr.sh_size : 0); ++ if (lastoffset < shdr_info[cnt].shdr.sh_offset + filesz) ++ lastoffset = shdr_info[cnt].shdr.sh_offset + filesz; ++ } + } + ++ /* We might have to update the unallocated sections after we done the ++ allocated ones. lastoffset is set to right after the last allocated ++ section. */ ++ if (mixed_allocated_unallocated) ++ for (cnt = 1; cnt <= shdridx; ++cnt) ++ if (shdr_info[cnt].idx > 0) ++ { ++ scn = elf_getscn (newelf, shdr_info[cnt].idx); ++ if ((shdr_info[cnt].shdr.sh_flags & SHF_ALLOC) == 0) ++ { ++ if (shdr_info[cnt].shdr.sh_offset == 0) ++ shdr_info[cnt].shdr.sh_offset ++ = ((lastoffset + shdr_info[cnt].shdr.sh_addralign - 1) ++ & ~((GElf_Off) (shdr_info[cnt].shdr.sh_addralign - 1))); ++ ++ /* Set the section header in the new file. */ ++ if (unlikely (gelf_update_shdr (scn, &shdr_info[cnt].shdr) == 0)) ++ /* There cannot be any overflows. */ ++ INTERNAL_ERROR (fname); ++ ++ /* Remember the last section written so far. */ ++ GElf_Off filesz = (shdr_info[cnt].shdr.sh_type != SHT_NOBITS ++ ? shdr_info[cnt].shdr.sh_size : 0); ++ if (lastoffset < shdr_info[cnt].shdr.sh_offset + filesz) ++ lastoffset = shdr_info[cnt].shdr.sh_offset + filesz; ++ } ++ } ++ + /* Adjust symbol references if symbol tables changed. */ + if (any_symtab_changes) + /* Find all relocation sections which use this symbol table. */ diff --git a/elfutils.spec b/elfutils.spec index 357fd55..49b9b1b 100644 --- a/elfutils.spec +++ b/elfutils.spec @@ -1,7 +1,7 @@ Name: elfutils Summary: A collection of utilities and DSOs to handle ELF files and DWARF data Version: 0.173 -%global baserelease 6 +%global baserelease 7 URL: http://elfutils.org/ %global source_url ftp://sourceware.org/pub/elfutils/%{version}/ License: GPLv3+ and (GPLv2+ or LGPLv3+) @@ -23,6 +23,7 @@ Source: %{?source_url}%{name}-%{version}.tar.bz2 Patch1: elfutils-0.173-new-notes-hack.patch Patch2: elfutils-0.173-elfcompress.patch Patch3: elfutils-0.173-annobingroup.patch +Patch4: elfutils-0.173-strip-alloc-nonalloc.patch Requires: elfutils-libelf%{depsuffix} = %{version}-%{release} Requires: elfutils-libs%{depsuffix} = %{version}-%{release} @@ -194,6 +195,7 @@ profiling) of processes. %patch1 -p1 -b .notes_hack %patch2 -p1 -b .elfcompress %patch3 -p1 -b .annobingroup +%patch4 -p1 -b .strip-alloc-nonalloc # In case the above patches added any new test scripts, make sure they # are executable. @@ -326,6 +328,9 @@ fi %endif %changelog +* Sun Jul 29 2018 Mark Wielaard - 0.173-7 +- Add elfutils-0.173-strip-alloc-nonalloc.patch (#1609577) + * Tue Jul 24 2018 Mark Wielaard - Drop libstdc++-devel BuildRequires. gcc-c++ will pull it in.