CVS patchset: 5847
CVS date: 2002/11/12 20:09:04
- 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. */
{
/* Allocate a new program header with the appropriate number of
elements. */
on the stack. */
#define MAX_TMPBUF 32768
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;
/* 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. */
{
/* 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;
== elf_typesize (LIBELFBITS, ELF_T_PHDR, 1));
/* Write out the program header table. */
== 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;
{
ElfW2(LIBELFBITS,Phdr) tmp_phdr;
ElfW2(LIBELFBITS,Phdr) *out_phdr = elf->state.ELFW(elf,LIBELFBITS).phdr;
}
while ((list = list->next) != NULL);
}
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
/* Write out the section header table. */
if (shdr_flags & ELF_F_DIRTY
result->elf = elf;
result->shdr_flags = ELF_F_DIRTY | ELF_F_MALLOCED;
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;
/* Initialize the data part. */
result->data_read = 1;
#/*! \page config_macros Default configuration: @RPMCONFIGDIR@/macros
# \verbatim
#
#/*! \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
#
# This is a global RPM configuration file. All changes made here will
# be lost when the rpm package is upgraded. Any per-system configuration
# Path to script that creates debug symbols in a /usr/lib/debug
# shadow tree.
%__debug_install_post \
# 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.
%{nil}
# Template for debug information sub-package.
#find-debuginfo.sh - automagically generate debug info and file list
#for inclusion in an rpm spec file.
#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
+LISTFILE=$BUILDDIR/debugfiles.list
+SOURCEFILE=$BUILDDIR/debugsources.list
+
+touch $BUILDDIR/.debug_saved_mode
echo -n > $SOURCEFILE
# Strip ELF binaries
echo -n > $SOURCEFILE
# Strip ELF binaries
mkdir -p ${OUTPUTDIR}
echo extracting debug info from $f
#save old mode
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
#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
/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
# stupid cpio creates new directories in mode 0700, fixup
find ${RPM_BUILD_ROOT}/usr/src/debug -type d -print0 | xargs -0 chmod a+rx
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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>
#include <assert.h>
#include <byteswap.h>
#include <endian.h>
+/* Needed for libelf */
+#define _FILE_OFFSET_BITS 64
+
#include "system.h"
#include "sections.h"
#include "system.h"
#include "sections.h"
+/* Needed for libelf */
+#define _FILE_OFFSET_BITS 64
+
#include "system.h"
#include <elf.h>
#include "system.h"
#include <elf.h>
/* copy elf header: */
gelf_newehdr(out_elf, ehdr.e_ident[EI_CLASS]);
/* 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)
section = NULL;
while ((section = elf_nextscn(elf, section)) != NULL)
for (i = 0; i < ehdr.e_phnum; i++)
{
gelf_getphdr (elf, i, &phdr);
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 */
}
/* Copy section headers */
memcpy (out_data->d_buf, data->d_buf, data->d_size);
strcpy (out_data->d_buf + data->d_size, DEBUGLINKNAME);
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;
}
changed_offsets = 1;
debuglink_name = data->d_size;
}
GElf_Shdr section_header;
GElf_Shdr out_section_header;
Elf_Data *data, *out_data;
GElf_Shdr section_header;
GElf_Shdr out_section_header;
Elf_Data *data, *out_data;
unsigned char *section_strtab;
int keep_section;
UnstripInfo *info;
int unstripinfo_name = 0;
unsigned char *section_strtab;
int keep_section;
UnstripInfo *info;
int unstripinfo_name = 0;
info = malloc (sizeof (UnstripInfo));
info = malloc (sizeof (UnstripInfo));
{
out_data = elf_newdata(out_section);
{
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_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;
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)
}
}
else if (keep_all_section_headers)
- 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);
if (out_elf == NULL)
{
fprintf (stderr, "Failed to elf_begin output file: %s\n", debugname);
copy_debuginfo_to_file (elf, out_elf);
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);
elf_end (out_elf);
close (out);
strip_to_file (elf, out_elf, debuglink);
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);
elf_end (out_elf);
close (out);
+/* Needed for libelf */
+#define _FILE_OFFSET_BITS 64
+
#include "system.h"
#include <elf.h>
#include "system.h"
#include <elf.h>
+/* Needed for libelf */
+#define _FILE_OFFSET_BITS 64
+
#include "system.h"
#include <stdarg.h>
#include "system.h"
#include <stdarg.h>