# include <sym.h> /* get COFF debugging symbol table declaration */
#endif
-#ifdef __GNU_LIBRARY__
-# include <link.h> /* get definition of ElfW */
+#if __GNU_LIBRARY__ - 0 >= 6
+# include <link.h> /* get ElfW etc */
#endif
#ifndef ElfW
char *old_section_names;
ElfW(Addr) old_bss_addr, new_bss_addr;
- ElfW(Addr) old_bss_size, new_data2_size;
+ ElfW(Word) old_bss_size, new_data2_size;
ElfW(Off) new_data2_offset;
ElfW(Addr) new_data2_addr;
- int n, nn, old_bss_index, old_data_index;
+ int n, nn, old_bss_index, old_data_index, new_data2_index;
struct stat stat_buf;
/* Open the old file & map it into the address space. */
fatal ("Can't mmap (%s): errno %d\n", old_name, errno);
#ifdef DEBUG
- fprintf (stderr, "mmap (%s, %lx) -> %lx\n", old_name, stat_buf.st_size,
- (unsigned long) old_base);
+ fprintf (stderr, "mmap (%s, %x) -> %x\n", old_name, stat_buf.st_size,
+ old_base);
#endif
/* Get pointers to headers & section names */
#ifdef DEBUG
fprintf (stderr, "old_bss_index %d\n", old_bss_index);
- fprintf (stderr, "old_bss_addr %lx\n", old_bss_addr);
- fprintf (stderr, "old_bss_size %lx\n", old_bss_size);
- fprintf (stderr, "new_bss_addr %lx\n", new_bss_addr);
- fprintf (stderr, "new_data2_addr %lx\n", new_data2_addr);
- fprintf (stderr, "new_data2_size %lx\n", new_data2_size);
- fprintf (stderr, "new_data2_offset %lx\n", new_data2_offset);
+ fprintf (stderr, "old_bss_addr %x\n", old_bss_addr);
+ fprintf (stderr, "old_bss_size %x\n", old_bss_size);
+ fprintf (stderr, "new_bss_addr %x\n", new_bss_addr);
+ fprintf (stderr, "new_data2_addr %x\n", new_data2_addr);
+ fprintf (stderr, "new_data2_size %x\n", new_data2_size);
+ fprintf (stderr, "new_data2_offset %x\n", new_data2_offset);
#endif
- if ((unsigned long) new_bss_addr
- < (unsigned long) old_bss_addr + old_bss_size)
+ if ((unsigned) new_bss_addr < (unsigned) old_bss_addr + old_bss_size)
fatal (".bss shrank when undumping???\n", 0, 0);
/* Set the output file to the right size and mmap it. Set
new_file_h->e_shnum += 1;
#ifdef DEBUG
- fprintf (stderr, "Old section offset %lx\n", old_file_h->e_shoff);
+ fprintf (stderr, "Old section offset %x\n", old_file_h->e_shoff);
fprintf (stderr, "Old section count %d\n", old_file_h->e_shnum);
- fprintf (stderr, "New section offset %lx\n", new_file_h->e_shoff);
+ fprintf (stderr, "New section offset %x\n", new_file_h->e_shoff);
fprintf (stderr, "New section count %d\n", new_file_h->e_shnum);
#endif
for (n = new_file_h->e_phnum - 1; n >= 0; n--)
{
/* Compute maximum of all requirements for alignment of section. */
- unsigned int alignment = (NEW_PROGRAM_H (n)).p_align;
+ int alignment = (NEW_PROGRAM_H (n)).p_align;
if ((OLD_SECTION_H (old_bss_index)).sh_addralign > alignment)
alignment = OLD_SECTION_H (old_bss_index).sh_addralign;
for (end = reloc + section.sh_size; reloc < end;
reloc += section.sh_entsize)
{
- ElfW(Addr) addr;
+ ElfW(Addr) addr = ((ElfW(Rel) *) reloc)->r_offset - offset;
#ifdef __alpha__
/* The Alpha ELF binutils currently have a bug that
sometimes results in relocs that contain all
if (((ElfW(Rel) *) reloc)->r_offset == 0)
continue;
#endif
- addr = ((ElfW(Rel) *) reloc)->r_offset - offset;
memcpy (new_base + addr, old_base + addr, sizeof(ElfW(Addr)));
}
}