diff options
author | jbj <devnull@localhost> | 2002-11-12 20:09:04 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2002-11-12 20:09:04 +0000 |
commit | 937ba6c27ce37057fed550927e1f5c523475d33f (patch) | |
tree | 1f1fc167806af6d39ec9ec6238ce01181b51fcf8 | |
parent | 4b68a64e6b866f54fd5f396605dc9a5ca63979bb (diff) | |
download | rpm-937ba6c27ce37057fed550927e1f5c523475d33f.tar.gz rpm-937ba6c27ce37057fed550927e1f5c523475d33f.tar.bz2 rpm-937ba6c27ce37057fed550927e1f5c523475d33f.zip |
Elfutils fiddles fo fix striptofile.
CVS patchset: 5847
CVS date: 2002/11/12 20:09:04
-rw-r--r-- | elfutils/libelf/elf32_newphdr.c | 3 | ||||
-rw-r--r-- | elfutils/libelf/elf32_updatefile.c | 15 | ||||
-rw-r--r-- | elfutils/libelf/elf_newscn.c | 1 | ||||
-rw-r--r-- | macros.in | 4 | ||||
-rw-r--r-- | scripts/find-debuginfo.sh | 16 | ||||
-rw-r--r-- | tools/debugedit.c | 3 | ||||
-rw-r--r-- | tools/sections.c | 3 | ||||
-rw-r--r-- | tools/striptofile.c | 65 | ||||
-rw-r--r-- | tools/unstripfile.c | 3 | ||||
-rw-r--r-- | tools/utils.c | 3 |
10 files changed, 70 insertions, 46 deletions
diff --git a/elfutils/libelf/elf32_newphdr.c b/elfutils/libelf/elf32_newphdr.c index 05aa7a17a..1f48009fe 100644 --- a/elfutils/libelf/elf32_newphdr.c +++ b/elfutils/libelf/elf32_newphdr.c @@ -86,7 +86,8 @@ elfw2(LIBELFBITS,newphdr) (Elf *elf, size_t count) result = NULL; } - else if (elf->state.ELFW(elf,LIBELFBITS).ehdr->e_phnum != count) + else if (elf->state.ELFW(elf,LIBELFBITS).ehdr->e_phnum != count || + elf->state.ELFW(elf,LIBELFBITS).phdr == NULL) { /* Allocate a new program header with the appropriate number of elements. */ diff --git a/elfutils/libelf/elf32_updatefile.c b/elfutils/libelf/elf32_updatefile.c index 36b3f0d13..f84ec75a2 100644 --- a/elfutils/libelf/elf32_updatefile.c +++ b/elfutils/libelf/elf32_updatefile.c @@ -257,19 +257,19 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum) on the stack. */ #define MAX_TMPBUF 32768 - /* Helper function to write out fill bytes. */ static int fill (int fd, off_t pos, size_t len, char *fillbuf, size_t *filledp) /*@modifies fillbuf, filledp @*/ { size_t filled = *filledp; + size_t fill_len = MIN (len, FILLBUFSIZE); - if (unlikely (len > filled) && filled < FILLBUFSIZE) + if (unlikely (fill_len > filled) && (filled < FILLBUFSIZE)) { /* Initialize a few more bytes. */ - memset (fillbuf + filled, __libelf_fill_byte, len - filled); - *filledp = filled = len; + memset (fillbuf + filled, __libelf_fill_byte, fill_len - filled); + *filledp = filled = fill_len; } do @@ -353,7 +353,8 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf, int change_bo, size_t shnum) == elf_typesize (LIBELFBITS, ELF_T_PHDR, 1)); /* Write out the program header table. */ - if ((elf->state.ELFW(elf,LIBELFBITS).phdr_flags | elf->flags) & ELF_F_DIRTY) + if (elf->state.ELFW(elf,LIBELFBITS).phdr != NULL + && (elf->state.ELFW(elf,LIBELFBITS).phdr_flags | elf->flags) & ELF_F_DIRTY) { ElfW2(LIBELFBITS,Phdr) tmp_phdr; ElfW2(LIBELFBITS,Phdr) *out_phdr = elf->state.ELFW(elf,LIBELFBITS).phdr; @@ -539,8 +540,8 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf, int change_bo, size_t shnum) } while ((list = list->next) != NULL); - - assert (shdr_data == &shdr_data_begin[shnum]); + if (change_bo || elf->state.ELFW(elf,LIBELFBITS).shdr == NULL) + assert (shdr_data == &shdr_data_begin[shnum]); /* Write out the section header table. */ if (shdr_flags & ELF_F_DIRTY diff --git a/elfutils/libelf/elf_newscn.c b/elfutils/libelf/elf_newscn.c index 8f84988c3..1d8d2e132 100644 --- a/elfutils/libelf/elf_newscn.c +++ b/elfutils/libelf/elf_newscn.c @@ -121,6 +121,7 @@ elf_newscn (Elf *elf) result->elf = elf; result->shdr_flags = ELF_F_DIRTY | ELF_F_MALLOCED; + result->list = elf->state.elf.scns_last; /* Initialize the data part. */ result->data_read = 1; @@ -1,7 +1,7 @@ #/*! \page config_macros Default configuration: @RPMCONFIGDIR@/macros # \verbatim # -# $Id: macros.in,v 1.126 2002/11/09 19:25:14 jbj Exp $ +# $Id: macros.in,v 1.127 2002/11/12 20:09:04 jbj Exp $ # # This is a global RPM configuration file. All changes made here will # be lost when the rpm package is upgraded. Any per-system configuration @@ -110,7 +110,7 @@ # Path to script that creates debug symbols in a /usr/lib/debug # shadow tree. %__debug_install_post \ - @RPMCONFIGDIR@/find-debuginfo.sh \ + @RPMCONFIGDIR@/find-debuginfo.sh %{_builddir}/%{buildsubdir} \ %{nil} # Template for debug information sub-package. diff --git a/scripts/find-debuginfo.sh b/scripts/find-debuginfo.sh index 960067533..d483d3e48 100644 --- a/scripts/find-debuginfo.sh +++ b/scripts/find-debuginfo.sh @@ -2,10 +2,14 @@ #find-debuginfo.sh - automagically generate debug info and file list #for inclusion in an rpm spec file. -LISTFILE=debugfiles.list -SOURCEFILE=debugsources.list +if [ -z "$1" ] ; then BUILDDIR="." +else BUILDDIR=$1 +fi -touch .debug_saved_mode +LISTFILE=$BUILDDIR/debugfiles.list +SOURCEFILE=$BUILDDIR/debugsources.list + +touch $BUILDDIR/.debug_saved_mode echo -n > $SOURCEFILE # Strip ELF binaries @@ -16,16 +20,16 @@ for f in `find $RPM_BUILD_ROOT -type f \( -perm -0100 -or -perm -0010 -or -perm mkdir -p ${OUTPUTDIR} echo extracting debug info from $f #save old mode - chmod --reference=$f .debug_saved_mode + chmod --reference=$f $BUILDDIR/.debug_saved_mode #make sure we have write perms chmod u+w $f /usr/lib/rpm/debugedit -b $RPM_BUILD_DIR -d /usr/src/debug -l $SOURCEFILE $f - chmod --reference=.debug_saved_mode $f + chmod --reference=$BUILDDIR/.debug_saved_mode $f /usr/lib/rpm/striptofile -g -u -o $OUTPUTDIR $f || : done mkdir -p ${RPM_BUILD_ROOT}/usr/src/debug -(DIR=`pwd`; cd $RPM_BUILD_DIR; LANG=C sort $DIR/$SOURCEFILE -z -u | cpio -pd0m ${RPM_BUILD_ROOT}/usr/src/debug) +cat $SOURCEFILE | (cd $RPM_BUILD_DIR; LANG=C sort -z -u | cpio -pd0m ${RPM_BUILD_ROOT}/usr/src/debug) # stupid cpio creates new directories in mode 0700, fixup find ${RPM_BUILD_ROOT}/usr/src/debug -type d -print0 | xargs -0 chmod a+rx diff --git a/tools/debugedit.c b/tools/debugedit.c index 3bc1b1584..9d0c2e15b 100644 --- a/tools/debugedit.c +++ b/tools/debugedit.c @@ -16,6 +16,9 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* Needed for libelf */ +#define _FILE_OFFSET_BITS 64 + #include <assert.h> #include <byteswap.h> #include <endian.h> diff --git a/tools/sections.c b/tools/sections.c index c58393253..1b2e46e05 100644 --- a/tools/sections.c +++ b/tools/sections.c @@ -1,3 +1,6 @@ +/* Needed for libelf */ +#define _FILE_OFFSET_BITS 64 + #include "system.h" #include "sections.h" diff --git a/tools/striptofile.c b/tools/striptofile.c index d40748748..580d34213 100644 --- a/tools/striptofile.c +++ b/tools/striptofile.c @@ -1,3 +1,6 @@ +/* Needed for libelf */ +#define _FILE_OFFSET_BITS 64 + #include "system.h" #include <elf.h> @@ -32,16 +35,8 @@ copy_to_file(Elf *elf, Elf *out_elf) /* copy elf header: */ gelf_newehdr(out_elf, ehdr.e_ident[EI_CLASS]); - gelf_update_ehdr(out_elf, &ehdr); - - /* Copy program headers: */ - gelf_newphdr(out_elf, ehdr.e_phnum); - - for (i = 0; i < ehdr.e_phnum; i++) - { - gelf_getphdr (elf, i, &phdr); - gelf_update_phdr(out_elf, i, &phdr); - } + ehdr.e_phnum = 0; + gelf_update_ehdr (out_elf, &ehdr); section = NULL; while ((section = elf_nextscn(elf, section)) != NULL) @@ -108,7 +103,7 @@ strip_to_file(Elf *elf, Elf *out_elf, DebugLink *debuglink) for (i = 0; i < ehdr.e_phnum; i++) { gelf_getphdr (elf, i, &phdr); - gelf_update_phdr(out_elf, i, &phdr); + gelf_update_phdr (out_elf, i, &phdr); } /* Copy section headers */ @@ -156,7 +151,7 @@ strip_to_file(Elf *elf, Elf *out_elf, DebugLink *debuglink) memcpy (out_data->d_buf, data->d_buf, data->d_size); strcpy (out_data->d_buf + data->d_size, DEBUGLINKNAME); - section_header.sh_size += out_data->d_size; + section_header.sh_size = MAX (section_header.sh_size, out_data->d_off + out_data->d_size); changed_offsets = 1; debuglink_name = data->d_size; } @@ -231,10 +226,12 @@ copy_debuginfo_to_file(Elf *elf, Elf *out_elf) GElf_Shdr section_header; GElf_Shdr out_section_header; Elf_Data *data, *out_data; + GElf_Phdr phdr; unsigned char *section_strtab; int keep_section; UnstripInfo *info; int unstripinfo_name = 0; + int i; info = malloc (sizeof (UnstripInfo)); @@ -308,25 +305,25 @@ copy_debuginfo_to_file(Elf *elf, Elf *out_elf) { out_data = elf_newdata(out_section); - out_data->d_buf = data->d_buf; - out_data->d_type = data->d_type; - out_data->d_size = data->d_size; + if (ehdr.e_shstrndx == elf_ndxscn(section)) + { + out_data->d_size = data->d_size + strlen (UNSTRIPINFONAME) + 1; + out_data->d_buf = malloc (out_data->d_size); + memcpy (out_data->d_buf, data->d_buf, data->d_size); + strcpy (out_data->d_buf + data->d_size, UNSTRIPINFONAME); + + unstripinfo_name = data->d_size; + } + else + { + out_data->d_buf = data->d_buf; + out_data->d_size = data->d_size; + } out_data->d_off = data->d_off; + out_data->d_type = data->d_type; out_data->d_align = section_header.sh_addralign; out_data->d_version = data->d_version; - last_offset = out_data->d_off + out_data->d_size; - } - /* Add ".debuglink" to section header strtab */ - if (ehdr.e_shstrndx == elf_ndxscn(section)) - { - out_data = elf_newdata(out_section); - - out_data->d_size = strlen (UNSTRIPINFONAME) + 1; - out_data->d_buf = UNSTRIPINFONAME; - out_data->d_off = last_offset; - out_data->d_align = 0; - unstripinfo_name = out_data->d_off; } } else if (keep_all_section_headers) @@ -476,7 +473,7 @@ main (int argc, char *argv[]) exit (1); } - out_elf = elf_begin (out, ELF_C_WRITE, NULL); + out_elf = elf_begin (out, ELF_C_WRITE_MMAP, NULL); if (out_elf == NULL) { fprintf (stderr, "Failed to elf_begin output file: %s\n", debugname); @@ -485,7 +482,11 @@ main (int argc, char *argv[]) copy_debuginfo_to_file (elf, out_elf); - elf_update (out_elf, ELF_C_WRITE); + if (elf_update (out_elf, ELF_C_WRITE) < 0) + { + fprintf (stderr, "Failed to write debug file: %s\n", elf_errmsg (elf_errno())); + exit (1); + } elf_end (out_elf); close (out); @@ -514,7 +515,11 @@ main (int argc, char *argv[]) strip_to_file (elf, out_elf, debuglink); - elf_update (out_elf, ELF_C_WRITE); + if (elf_update (out_elf, ELF_C_WRITE) < 0) + { + fprintf (stderr, "Failed to write stripped file: %s\n", elf_errmsg (elf_errno())); + exit (1); + } elf_end (out_elf); close (out); diff --git a/tools/unstripfile.c b/tools/unstripfile.c index bf780cef9..069adb3bc 100644 --- a/tools/unstripfile.c +++ b/tools/unstripfile.c @@ -1,3 +1,6 @@ +/* Needed for libelf */ +#define _FILE_OFFSET_BITS 64 + #include "system.h" #include <elf.h> diff --git a/tools/utils.c b/tools/utils.c index 914aab641..47f042810 100644 --- a/tools/utils.c +++ b/tools/utils.c @@ -1,3 +1,6 @@ +/* Needed for libelf */ +#define _FILE_OFFSET_BITS 64 + #include "system.h" #include <stdarg.h> |