X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Funexelf.c;h=9fdc974f673162c5acdb2805187ffa2f91944121;hb=c96beb83b1051bf0d1cd1a060f75ffd38c4edc9a;hp=d91ae33487d9b334804959d960ddb1085a6a421b;hpb=3e447015251ce6dcde843cbed10d9033d5538622;p=chise%2Fxemacs-chise.git diff --git a/src/unexelf.c b/src/unexelf.c index d91ae33..9fdc974 100644 --- a/src/unexelf.c +++ b/src/unexelf.c @@ -424,7 +424,7 @@ extern void fatal (const char *, ...); #include #include #include -#if !defined (__NetBSD__) && !defined (__OpenBSD__) +#ifdef HAVE_ELF_H #include #endif #include @@ -471,48 +471,16 @@ typedef struct { #define hdrNil ((pHDRR)0) #endif -#ifdef __NetBSD__ -/* - * NetBSD does not have normal-looking user-land ELF support. - */ -# ifdef __alpha__ -# define ELFSIZE 64 -# else -# define ELFSIZE 32 -# endif +#ifdef __OpenBSD__ # include +#endif -# define PT_LOAD Elf_pt_load -# define SHT_SYMTAB Elf_sht_symtab -# define SHT_DYNSYM Elf_sht_dynsym -# define SHT_NULL Elf_sht_null -# define SHT_NOBITS Elf_sht_nobits -# define SHT_REL Elf_sht_rel -# define SHT_RELA Elf_sht_rela - -# define SHN_UNDEF Elf_eshn_undefined -# define SHN_ABS Elf_eshn_absolute -# define SHN_COMMON Elf_eshn_common - -/* - * The magic of picking the right size types is handled by the ELFSIZE - * definition above. - */ +#if defined(__FreeBSD__) && (defined(__alpha__) || defined(__amd64__)) # ifdef __STDC__ -# define ElfW(type) Elf_##type +# define ElfW(type) Elf64_##type # else -# define ElfW(type) Elf_/**/type -# endif - -# ifdef __alpha__ -# include -# define HDRR struct ecoff_symhdr -# define pHDRR HDRR * +# define ElfW(type) Elf64_/**/type # endif -#endif /* __NetBSD__ */ - -#ifdef __OpenBSD__ -# include #endif #if __GNU_LIBRARY__ - 0 >= 6 @@ -521,10 +489,20 @@ typedef struct { #ifndef ElfW # ifdef __STDC__ -# define ElfW(type) Elf32_##type +# define ElfBitsW(bits, type) Elf##bits##_##type # else -# define ElfW(type) Elf32_/**/type +# define ElfBitsW(bits, type) Elf/**/bits/**/_/**/type # endif +# ifndef ELFSIZE +# ifdef _LP64 +# define ELFSIZE 64 +# else +# define ELFSIZE 32 +# endif +# endif + /* This macro expands `bits' before invoking ElfBitsW. */ +# define ElfExpandBitsW(bits, type) ElfBitsW (bits, type) +# define ElfW(type) ElfExpandBitsW (ELFSIZE, type) #endif #ifndef ELF_BSS_SECTION_NAME @@ -685,7 +663,6 @@ unexec (char *new_name, char *old_name, unsigned int data_start, old_sbss_index = -1; old_bss_addr = OLD_SECTION_H(old_bss_index).sh_addr; old_bss_size = OLD_SECTION_H(old_bss_index).sh_size; - new_data2_offset = OLD_SECTION_H(old_bss_index).sh_offset; new_data2_index = old_bss_index; } else @@ -693,7 +670,6 @@ unexec (char *new_name, char *old_name, unsigned int data_start, old_bss_addr = OLD_SECTION_H(old_sbss_index).sh_addr; old_bss_size = OLD_SECTION_H(old_bss_index).sh_size + OLD_SECTION_H(old_sbss_index).sh_size; - new_data2_offset = OLD_SECTION_H(old_sbss_index).sh_offset; new_data2_index = old_sbss_index; } @@ -711,6 +687,20 @@ unexec (char *new_name, char *old_name, unsigned int data_start, if (old_mdebug_index == old_file_h->e_shnum) old_mdebug_index = 0; + for (old_data_index = 1; old_data_index < (int) old_file_h->e_shnum; + old_data_index++) + { +#ifdef DEBUG + fprintf (stderr, "Looking for .data - found %s\n", + old_section_names + OLD_SECTION_H (old_data_index).sh_name); +#endif + if (!strcmp (old_section_names + OLD_SECTION_H (old_data_index).sh_name, + ".data")) + break; + } + if (old_data_index == old_file_h->e_shnum) + old_data_index = 0; + #if defined (emacs) || !defined (DEBUG) new_bss_addr = (ElfW(Addr)) sbrk (0); #else @@ -718,6 +708,8 @@ unexec (char *new_name, char *old_name, unsigned int data_start, #endif new_data2_addr = old_bss_addr; new_data2_size = new_bss_addr - old_bss_addr; + new_data2_offset = OLD_SECTION_H (old_data_index).sh_offset + + (new_data2_addr - OLD_SECTION_H (old_data_index).sh_addr); #ifdef DEBUG fprintf (stderr, "old_bss_index %d\n", old_bss_index);