summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1994-08-20 00:48:16 +0000
committerRichard M. Stallman <rms@gnu.org>1994-08-20 00:48:16 +0000
commit50d0aca73ad8056d24cfa7a901e360b2369d3579 (patch)
tree51318a19d5810cd9fa3cdcbd76d61dfaf87a8737
parent2e86eec3bd16158425590332c3fd560797ea9346 (diff)
downloademacs-50d0aca73ad8056d24cfa7a901e360b2369d3579.tar.gz
Eliminate local var bss_end.
Update the symbol values of _edata and _end.
-rw-r--r--src/unexelf.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/unexelf.c b/src/unexelf.c
index 32f39c7d2b6..a7f607e3de8 100644
--- a/src/unexelf.c
+++ b/src/unexelf.c
@@ -475,7 +475,6 @@ unexec (new_name, old_name, data_start, bss_start, entry_address)
char *new_name, *old_name;
unsigned data_start, bss_start, entry_address;
{
- extern unsigned int bss_end;
int new_file, old_file, new_file_size;
/* Pointers to the base of the image of the two files. */
@@ -548,8 +547,7 @@ unexec (new_name, old_name, data_start, bss_start, entry_address)
old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr;
old_bss_size = OLD_SECTION_H (old_bss_index).sh_size;
#if defined(emacs) || !defined(DEBUG)
- bss_end = (unsigned int) sbrk (0);
- new_bss_addr = (Elf32_Addr) bss_end;
+ new_bss_addr = (Elf32_Addr) sbrk (0);
#else
new_bss_addr = old_bss_addr + old_bss_size + 0x1234;
#endif
@@ -771,6 +769,26 @@ unexec (new_name, old_name, data_start, bss_start, entry_address)
}
}
+ /* Update the symbol values of _edata and _end. */
+ for (n = new_file_h->e_shnum - 1; n; n--)
+ {
+ byte *symnames;
+ Elf32_Sym *symp, *symendp;
+
+ if (NEW_SECTION_H (n).sh_type != SHT_DYNSYM
+ && NEW_SECTION_H (n).sh_type != SHT_SYMTAB)
+ continue;
+
+ symnames = NEW_SECTION_H (NEW_SECTION_H (n).sh_link).sh_offset + new_base;
+ symp = (Elf32_Sym *) (NEW_SECTION_H (n).sh_offset + new_base);
+ symendp = (Elf32_Sym *) ((byte *)symp + NEW_SECTION_H (n).sh_size);
+
+ for (; symp < symendp; symp ++)
+ if (strcmp ((char *) (symnames + symp->st_name), "_end") == 0
+ || strcmp ((char *) (symnames + symp->st_name), "_edata") == 0)
+ memcpy (&symp->st_value, &new_bss_addr, sizeof (new_bss_addr));
+ }
+
/* Close the files and make the new file executable */
if (close (old_file))