X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/9629ced85f2ca2026aa6bdfbe425ee51cb821a0b..17cea80917206c92bd0029bd620bd718926eae9c:/src/unexsunos4.c?ds=sidebyside diff --git a/src/unexsunos4.c b/src/unexsunos4.c index c591fb07bd..bdc2033628 100644 --- a/src/unexsunos4.c +++ b/src/unexsunos4.c @@ -15,7 +15,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Emacs; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ /* Contributed by Viktor Dukhovni. */ /* @@ -56,7 +57,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #endif -#if defined (SUNOS4) || defined (__FreeBSD__) +#if defined (SUNOS4) || defined (__FreeBSD__) || defined (__NetBSD__) #define UNDO_RELOCATION #endif @@ -92,7 +93,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #endif extern char *getenv (); -static unsigned Brk; +static unsigned brk_value; static struct exec nhdr; static int rd_only_len; static long cookie; @@ -145,7 +146,8 @@ unexec (new_name, a_name, bndry, bss_start, entry) */ cookie = time (0); - Brk = sbrk (0); /* Save the break, it is reset to &_end (by ld.so?) */ + /* Save the break, it is reset to &_end (by ld.so?). */ + brk_value = (unsigned) sbrk (0); /* * Round up data start to a page boundary (Lose if not a 2 power!) @@ -163,15 +165,13 @@ unexec (new_name, a_name, bndry, bss_start, entry) initialized = 1; #endif - /* - * Handle new data and bss sizes and optional new entry point. - * No one actually uses bss_start and entry, but tradition compels - * one to support them. - * Could complain if bss_start > Brk, but the caller is *supposed* to know - * what she is doing. - */ - nhdr.a_data = (bss_start ? bss_start : Brk) - N_DATADDR (nhdr); - nhdr.a_bss = bss_start ? Brk - bss_start : 0; + /* Handle new data and bss sizes and optional new entry point. + No one actually uses bss_start and entry, but tradition compels + one to support them. + Could complain if bss_start > brk_value, + but the caller is *supposed* to know what she is doing. */ + nhdr.a_data = (bss_start ? bss_start : brk_value) - N_DATADDR (nhdr); + nhdr.a_bss = bss_start ? brk_value - bss_start : 0; if (entry) nhdr.a_entry = entry; @@ -216,10 +216,14 @@ unexec (new_name, a_name, bndry, bss_start, entry) unsigned long daddr = N_DATADDR (ohdr); unsigned long rel, erel; #ifdef SUNOS4 +#ifdef SUNOS4_SHARED_LIBRARIES extern struct link_dynamic _DYNAMIC; /* SunOS4.x's ld_rel is relative to N_TXTADDR. */ - if (_DYNAMIC.ld_version < 2) + if (!ohdr.a_dynamic) + /* This was statically linked. */ + rel = erel = 0; + else if (_DYNAMIC.ld_version < 2) { rel = _DYNAMIC.ld_un.ld_1->ld_rel + N_TXTADDR (ohdr); erel = _DYNAMIC.ld_un.ld_1->ld_hash + N_TXTADDR (ohdr); @@ -229,6 +233,9 @@ unexec (new_name, a_name, bndry, bss_start, entry) rel = _DYNAMIC.ld_un.ld_2->ld_rel + N_TXTADDR (ohdr); erel = _DYNAMIC.ld_un.ld_2->ld_hash + N_TXTADDR (ohdr); } +#else /* not SUNOS4_SHARED_LIBRARIES */ + rel = erel = 0; +#endif /* not SUNOS4_SHARED_LIBRARIES */ #ifdef sparc #define REL_INFO_TYPE struct reloc_info_sparc #else @@ -236,7 +243,7 @@ unexec (new_name, a_name, bndry, bss_start, entry) #endif /* sparc */ #define REL_TARGET_ADDRESS(r) (((REL_INFO_TYPE *)(r))->r_address) #endif /* SUNOS4 */ -#ifdef __FreeBSD__ +#if defined (__FreeBSD__) || defined (__NetBSD__) extern struct _dynamic _DYNAMIC; /* FreeBSD's LD_REL is a virtual address itself. */ @@ -279,7 +286,7 @@ run_time_remap (progname) return; /* Restore the break */ - brk (Brk); + brk ((char *) brk_value); /* If nothing to remap: we are done! */ if (rd_only_len == 0) @@ -358,7 +365,7 @@ is_it (filename) * should the shared library decide to indirect through * addresses in the data segment not part of __DYNAMIC */ - mmap (data_start, rd_only_len, PROT_READ | PROT_EXEC, + mmap ((char *) data_start, rd_only_len, PROT_READ | PROT_EXEC, MAP_FILE | MAP_SHARED | MAP_FIXED, fd, N_DATOFF (hdr) + data_start - N_DATADDR (hdr)); close (fd);