398 |
*/ |
*/ |
399 |
|
|
400 |
#ifndef emacs |
#ifndef emacs |
401 |
#define fatal(a, b, c...) fprintf (stderr, a, b, ##c), exit (1) |
#define fatal(a, b...) fprintf (stderr, a, ##b), exit (1) |
402 |
#else |
#else |
403 |
#include "config.h" |
#include "config.h" |
404 |
extern void fatal (char *, ...); |
extern void fatal (char *, ...); |
581 |
if NOERROR is 0; we return -1 if NOERROR is nonzero. */ |
if NOERROR is 0; we return -1 if NOERROR is nonzero. */ |
582 |
|
|
583 |
static int |
static int |
584 |
find_section (name, section_names, file_name, old_file_h, old_section_h, noerror) |
find_section (char *name, char *section_names, char *file_name, Elf32_Ehdr *old_file_h, Elf32_Shdr *old_section_h, int noerror) |
|
char *name; |
|
|
char *section_names; |
|
|
char *file_name; |
|
|
ElfW(Ehdr) *old_file_h; |
|
|
ElfW(Shdr) *old_section_h; |
|
|
int noerror; |
|
585 |
{ |
{ |
586 |
int idx; |
int idx; |
587 |
|
|
600 |
if (noerror) |
if (noerror) |
601 |
return -1; |
return -1; |
602 |
else |
else |
603 |
fatal ("Can't find %s in %s.\n", name, file_name, 0); |
fatal ("Can't find %s in %s.\n", name, file_name); |
604 |
} |
} |
605 |
|
|
606 |
return idx; |
return idx; |
616 |
* |
* |
617 |
*/ |
*/ |
618 |
void |
void |
619 |
unexec (new_name, old_name, data_start, bss_start, entry_address) |
unexec (char *new_name, char *old_name, unsigned int data_start, unsigned int bss_start, unsigned int entry_address) |
|
char *new_name, *old_name; |
|
|
unsigned data_start, bss_start, entry_address; |
|
620 |
{ |
{ |
621 |
int new_file, old_file, new_file_size; |
int new_file, old_file, new_file_size; |
622 |
|
|
732 |
#endif |
#endif |
733 |
|
|
734 |
if ((unsigned) new_bss_addr < (unsigned) old_bss_addr + old_bss_size) |
if ((unsigned) new_bss_addr < (unsigned) old_bss_addr + old_bss_size) |
735 |
fatal (".bss shrank when undumping???\n", 0, 0); |
fatal (".bss shrank when undumping???\n"); |
736 |
|
|
737 |
/* Set the output file to the right size and mmap it. Set |
/* Set the output file to the right size and mmap it. Set |
738 |
* pointers to various interesting objects. stat_buf still has |
* pointers to various interesting objects. stat_buf still has |
815 |
> (old_sbss_index == -1 |
> (old_sbss_index == -1 |
816 |
? old_bss_addr |
? old_bss_addr |
817 |
: round_up (old_bss_addr, alignment))) |
: round_up (old_bss_addr, alignment))) |
818 |
fatal ("Program segment above .bss in %s\n", old_name, 0); |
fatal ("Program segment above .bss in %s\n", old_name); |
819 |
|
|
820 |
if (NEW_PROGRAM_H (n).p_type == PT_LOAD |
if (NEW_PROGRAM_H (n).p_type == PT_LOAD |
821 |
&& (round_up ((NEW_PROGRAM_H (n)).p_vaddr |
&& (round_up ((NEW_PROGRAM_H (n)).p_vaddr |
825 |
break; |
break; |
826 |
} |
} |
827 |
if (n < 0) |
if (n < 0) |
828 |
fatal ("Couldn't find segment next to .bss in %s\n", old_name, 0); |
fatal ("Couldn't find segment next to .bss in %s\n", old_name); |
829 |
|
|
830 |
/* Make sure that the size includes any padding before the old .bss |
/* Make sure that the size includes any padding before the old .bss |
831 |
section. */ |
section. */ |
856 |
".data")) |
".data")) |
857 |
break; |
break; |
858 |
if (old_data_index == old_file_h->e_shnum) |
if (old_data_index == old_file_h->e_shnum) |
859 |
fatal ("Can't find .data in %s.\n", old_name, 0); |
fatal ("Can't find .data in %s.\n", old_name); |
860 |
|
|
861 |
/* Walk through all section headers, insert the new data2 section right |
/* Walk through all section headers, insert the new data2 section right |
862 |
before the new bss section. */ |
before the new bss section. */ |