[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Cannot bootstrap on NetBSD/cobalt
From: |
Nozomu Ando |
Subject: |
Re: Cannot bootstrap on NetBSD/cobalt |
Date: |
Thu, 16 Mar 2006 21:13:33 +0900 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin) |
Nozomu Ando <address@hidden> writes:
> It seems that ld for elf32-tradlittlemips igonores "-z nocombreloc"
> option or there are some restrictions of binutils around MIPS elf.
>
> And unexelf.c cannot unexec correctly without "-z nocombreloc" with
> X11 dynamic-link libraries, because "undo relocations" at
> unexelf.c:1221 does not work.
The attached patch is for the two issue previously reported:
* We cannot build GNU Emacs CVS HEAD on NetBSD on MIPS processor.
* We cannot execute emacs with X11-related dinamic-link libraries.
For the latter issue, I wrote some code for unexelf.c so that
temacs can unexec without "-z nocombreloc" linker option
(if unexelf.c compiled with -DBROKEN_NOCOMBRELOC).
NAKAJI-san and I tested this patch on several platform:
NetBSD-3.0 release on hpcmips (MIPS little endian)
NetBSD-3.99.11 (binutils 2.15) on NetBSD/hpcmips
NetBSD-3.99.7 (binutils 2.15) on NetBSD/newsmips (MIPS big endian)
Thanks,
---
Nozomu Ando
P.S.
We found also another problem on NetBSD-current with binutils 2.16.1.
Its start address of the data segment is changed.
We have a workaround for this, but I am not sure what is correct fix.
---
Index: src/unexelf.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/unexelf.c,v
retrieving revision 1.61
diff -u -c -r1.61 unexelf.c
*** src/unexelf.c 6 Feb 2006 15:23:21 -0000 1.61
--- src/unexelf.c 9 Mar 2006 15:18:19 -0000
***************
*** 433,438 ****
--- 433,441 ----
#if __sgi
#include <syms.h> /* for HDRR declaration */
#endif /* __sgi */
+ #ifdef BROKEN_NOCOMBRELOC
+ #include <assert.h>
+ #endif
#ifndef MAP_ANON
#ifdef MAP_ANONYMOUS
***************
*** 687,692 ****
--- 690,698 ----
int old_mdebug_index;
struct stat stat_buf;
int old_file_size;
+ #ifdef BROKEN_NOCOMBRELOC
+ int unreloc_sections[10], n_unreloc_sections;
+ #endif
/* Open the old file, allocate a buffer of the right size, and read
in the file contents. */
***************
*** 1218,1223 ****
--- 1224,1230 ----
/* This loop seeks out relocation sections for the data section, so
that it can undo relocations performed by the runtime linker. */
+ #ifndef BROKEN_NOCOMBRELOC
for (n = new_file_h->e_shnum - 1; n; n--)
{
ElfW(Shdr) section = NEW_SECTION_H (n);
***************
*** 1272,1277 ****
--- 1279,1359 ----
break;
}
}
+ #else /* BROKEN_NOCOMBRELOC */
+ for (n = 1, n_unreloc_sections = 0; n < new_file_h->e_shnum; n++)
+ if (!strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data")
+ || !strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".sdata")
+ || !strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".lit4")
+ || !strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".lit8")
+ #ifdef IRIX6_5 /* see above */
+ || !strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".got")
+ #endif
+ || !strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".sdata1")
+ || !strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data1"))
+ {
+ assert (n_unreloc_sections
+ < (sizeof (unreloc_sections) / sizeof (unreloc_sections[0])));
+ unreloc_sections[n_unreloc_sections++] = n;
+ #ifdef DEBUG
+ fprintf (stderr, "section %d: %s\n", n,
+ old_section_names + NEW_SECTION_H (n).sh_name);
+ #endif
+ }
+
+ for (n = new_file_h->e_shnum - 1; n; n--)
+ {
+ ElfW(Shdr) section = NEW_SECTION_H (n);
+ caddr_t reloc, end;
+ ElfW(Addr) addr, offset;
+ int target;
+
+ switch (section.sh_type)
+ {
+ default:
+ break;
+ case SHT_REL:
+ case SHT_RELA:
+ /* This code handles two different size structs, but there should
+ be no harm in that provided that r_offset is always the first
+ member. */
+ for (reloc = old_base + section.sh_offset,
+ end = reloc + section.sh_size;
+ reloc < end;
+ reloc += section.sh_entsize)
+ {
+ addr = ((ElfW(Rel) *) reloc)->r_offset;
+ #ifdef __alpha__
+ /* The Alpha ELF binutils currently have a bug that
+ sometimes results in relocs that contain all
+ zeroes. Work around this for now... */
+ if (addr == 0)
+ continue;
+ #endif
+ for (nn = 0; nn < n_unreloc_sections; nn++)
+ {
+ target = unreloc_sections[nn];
+ if (NEW_SECTION_H (target).sh_addr <= addr
+ && addr < (NEW_SECTION_H (target).sh_addr +
+ NEW_SECTION_H (target).sh_size))
+ {
+ offset = (NEW_SECTION_H (target).sh_addr -
+ NEW_SECTION_H (target).sh_offset);
+ memcpy (new_base + addr - offset,
+ old_base + addr - offset,
+ sizeof (ElfW(Addr)));
+ #ifdef DEBUG
+ fprintf (stderr, "unrelocate: [%08lx] <= %08lx\n",
+ (long) addr,
+ (long) *((long *) (new_base + addr - offset)));
+ #endif
+ break;
+ }
+ }
+ }
+ break;
+ }
+ }
+ #endif /* BROKEN_NOCOMBRELOC */
/* Write out new_file, and free the buffers. */
Index: src/m/mips.h
===================================================================
RCS file: /cvsroot/emacs/emacs/src/m/mips.h,v
retrieving revision 1.27
diff -u -c -r1.27 mips.h
*** src/m/mips.h 6 Feb 2006 15:23:23 -0000 1.27
--- src/m/mips.h 9 Mar 2006 15:18:19 -0000
***************
*** 112,118 ****
/* This machine requires completely different unexec code
which lives in a separate file. Specify the file name. */
! #ifndef __linux__
#undef UNEXEC
#define UNEXEC unexmips.o
#endif /* not __linux__ */
--- 112,118 ----
/* This machine requires completely different unexec code
which lives in a separate file. Specify the file name. */
! #if !defined(__linux__) && !defined(__NetBSD__)
#undef UNEXEC
#define UNEXEC unexmips.o
#endif /* not __linux__ */
***************
*** 142,155 ****
#if defined (__NetBSD__) || defined (__OpenBSD__)
#else /* bsd with elf */
#define LINKER /bsd43/bin/ld
- #endif /* bsd with elf */
- #else /* not BSD_SYSTEM */
-
- #if defined(__GNUC__) && defined(_ABIN32)
- #define LIBS_MACHINE
- #else
- #define LIBS_MACHINE -lmld
- #endif
#define LD_SWITCH_MACHINE -D 800000 -g3
#define START_FILES pre-crt0.o /usr/lib/crt1.o
--- 142,147 ----
***************
*** 159,164 ****
--- 151,165 ----
#define C_SWITCH_MACHINE -I/usr/include/bsd
#define C_DEBUG_SWITCH -O -g3
+ #endif /* bsd with elf */
+ #else /* not BSD_SYSTEM */
+
+ #if defined(__GNUC__) && defined(_ABIN32)
+ #define LIBS_MACHINE
+ #else
+ #define LIBS_MACHINE -lmld
+ #endif
+
#endif /* not BSD_SYSTEM */
#endif /* not NEWSOS5 && not __linux__ */
Index: src/m/pmax.h
===================================================================
RCS file: /cvsroot/emacs/emacs/src/m/pmax.h,v
retrieving revision 1.23
diff -u -c -r1.23 pmax.h
*** src/m/pmax.h 1 Sep 2003 15:45:58 -0000 1.23
--- src/m/pmax.h 9 Mar 2006 15:18:19 -0000
***************
*** 13,20 ****
--- 13,24 ----
#ifndef __MIPSEB__
#undef WORDS_BIG_ENDIAN
#endif
+ #if defined (__NetBSD__)
+ #define BROKEN_NOCOMBRELOC
+ #else
#undef LIB_STANDARD
#undef START_FILES
+ #endif
#undef COFF
#undef TERMINFO
#define MAIL_USE_FLOCK
***************
*** 24,41 ****
#ifdef MACH
#define START_FILES pre-crt0.o /usr/lib/crt0.o
#else
/* This line starts being needed with ultrix 4.0. */
/* You must delete it for version 3.1. */
#define START_FILES pre-crt0.o /usr/lib/cmplrs/cc/crt0.o
#endif
!
! #if defined (__NetBSD__) || defined (__OpenBSD__)
! #undef START_FILES
! #define START_FILES pre-crt0.o /usr/lib/crt0.o
! #undef RUN_TIME_REMAP
! #undef UNEXEC
! #define UNEXEC unexelf.o
! #endif /* NetBSD || OpenBSD */
/* Supposedly the following will overcome a kernel bug. */
#undef LD_SWITCH_MACHINE
--- 28,39 ----
#ifdef MACH
#define START_FILES pre-crt0.o /usr/lib/crt0.o
#else
+ #if !defined (__NetBSD__)
/* This line starts being needed with ultrix 4.0. */
/* You must delete it for version 3.1. */
#define START_FILES pre-crt0.o /usr/lib/cmplrs/cc/crt0.o
#endif
! #endif
/* Supposedly the following will overcome a kernel bug. */
#undef LD_SWITCH_MACHINE