/* Copyright (C) 1985, 1986, 1987, 1988, 1990, 1992, 1999, 2000, 2001,
- 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+ 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
Free Software Foundation, Inc.
This file is part of GNU Emacs.
gets its value adjusted. .bss size becomes zero and new address
is set. data2 section header gets added by copying the existing
.data header and modifying the offset, address and size. */
- for (old_data_index = 1; old_data_index < (int) old_file_h->e_shnum;
- old_data_index++)
- if (!strcmp (old_section_names + OLD_SECTION_H (old_data_index).sh_name,
- ".data"))
- break;
- if (old_data_index == old_file_h->e_shnum)
- fatal ("Can't find .data in %s.\n", old_name, 0);
/* Walk through all section headers, insert the new data2 section right
before the new bss section. */
placed after the .bss section. Overlap can occur if the
section just before .bss has less-strict alignment; this
was observed between .symtab and .bss on Solaris 2.5.1
- (sparc) with GCC snapshot 960602. */
+ (sparc) with GCC snapshot 960602.
- if (NEW_SECTION_H (nn).sh_offset >= old_bss_offset)
+> dump -h temacs
+
+temacs:
+
+ **** SECTION HEADER TABLE ****
+[No] Type Flags Addr Offset Size Name
+ Link Info Adralgn Entsize
+
+[22] 1 3 0x335150 0x315150 0x4 .data.rel.local
+ 0 0 0x4 0
+
+[23] 8 3 0x335158 0x315158 0x42720 .bss
+ 0 0 0x8 0
+
+[24] 2 0 0 0x315154 0x1c9d0 .symtab
+ 25 1709 0x4 0x10
+ */
+
+ if (NEW_SECTION_H (nn).sh_offset >= old_bss_offset
+ || (NEW_SECTION_H (nn).sh_offset + NEW_SECTION_H (nn).sh_size
+ > new_data2_offset))
NEW_SECTION_H (nn).sh_offset += new_data2_incr;
/* Any section that was originally placed after the section
symendp = (ElfW(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), "end") == 0
- || strcmp ((char *) (symnames + symp->st_name), "_edata") == 0
- || strcmp ((char *) (symnames + symp->st_name), "edata") == 0)
- memcpy (&symp->st_value, &new_bss_addr, sizeof (new_bss_addr));
+ {
+ if (strcmp ((char *) (symnames + symp->st_name), "_end") == 0
+ || strcmp ((char *) (symnames + symp->st_name), "end") == 0
+ || strcmp ((char *) (symnames + symp->st_name), "_edata") == 0
+ || strcmp ((char *) (symnames + symp->st_name), "edata") == 0)
+ memcpy (&symp->st_value, &new_bss_addr, sizeof (new_bss_addr));
+
+ /* Strictly speaking, #ifdef below is not necessary. But we
+ keep it to indicate that this kind of change may also be
+ necessary for other unexecs to support GNUstep. */
+#ifdef NS_IMPL_GNUSTEP
+ /* ObjC runtime modifies the values of some data structures
+ such as classes and selectors in the .data section after
+ loading. As the dump process copies the .data section
+ from the current process, that causes problems when the
+ modified classes are reinitialized in the dumped
+ executable. We copy such data from the old file, not
+ from the current process. */
+ if (strncmp ((char *) (symnames + symp->st_name),
+ "_OBJC_", sizeof ("_OBJC_") - 1) == 0)
+ {
+ caddr_t old, new;
+
+ new = ((symp->st_value - NEW_SECTION_H (symp->st_shndx).sh_addr)
+ + NEW_SECTION_H (symp->st_shndx).sh_offset + new_base);
+ /* "Unpatch" index. */
+ nn = symp->st_shndx;
+ if (nn > old_bss_index)
+ nn--;
+ old = ((symp->st_value - NEW_SECTION_H (symp->st_shndx).sh_addr)
+ + OLD_SECTION_H (nn).sh_offset + old_base);
+ memcpy (new, old, symp->st_size);
+ }
+#endif
+ }
}
/* This loop seeks out relocation sections for the data section, so
new_file_size, errno);
#else
fatal ("Didn't write %d bytes to %s: errno %d\n",
- new_file_size, new_base, errno);
+ new_file_size, new_name, errno);
#endif
munmap (old_base, old_file_size);
munmap (new_base, new_file_size);