From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nozomu Ando Newsgroups: gmane.emacs.devel Subject: Re: Cannot bootstrap on NetBSD/cobalt Date: Thu, 16 Mar 2006 21:13:33 +0900 Message-ID: <863bhiegeq.fsf@panel.jk.homeunix.org> References: <86k6b6wq88.fsf@panel.jk.homeunix.org> <86irqppovk.fsf@panel.jk.homeunix.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1142511261 1894 80.91.229.2 (16 Mar 2006 12:14:21 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 16 Mar 2006 12:14:21 +0000 (UTC) Cc: nakaji@takamatsu-nct.ac.jp Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Mar 16 13:14:16 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FJrMs-00074c-0R for ged-emacs-devel@m.gmane.org; Thu, 16 Mar 2006 13:14:14 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FJrMr-0000s2-CL for ged-emacs-devel@m.gmane.org; Thu, 16 Mar 2006 07:14:13 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FJrMO-0000oQ-4y for emacs-devel@gnu.org; Thu, 16 Mar 2006 07:13:44 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FJrMM-0000lz-ND for emacs-devel@gnu.org; Thu, 16 Mar 2006 07:13:43 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FJrMM-0000ll-FS for emacs-devel@gnu.org; Thu, 16 Mar 2006 07:13:42 -0500 Original-Received: from [17.250.248.70] (helo=smtpout.mac.com) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FJrR0-0006sb-8D for emacs-devel@gnu.org; Thu, 16 Mar 2006 07:18:30 -0500 Original-Received: from mac.com (smtpin01-en2 [10.13.10.146]) by smtpout.mac.com (Xserve/8.12.11/smtpout13/MantshX 4.0) with ESMTP id k2GCDemn016365; Thu, 16 Mar 2006 04:13:40 -0800 (PST) Original-Received: from panel.jk.homeunix.org (khp059134236077.ppp-bb.dion.ne.jp [59.134.236.77]) (authenticated bits=0) by mac.com (Xserve/smtpin01/MantshX 4.0) with ESMTP id k2GCDYYb001430 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 16 Mar 2006 04:13:37 -0800 (PST) Original-To: emacs-devel@gnu.org In-Reply-To: <86irqppovk.fsf@panel.jk.homeunix.org> (Nozomu Ando's message of "Wed, 08 Mar 2006 13:00:15 +0900") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:51701 Archived-At: Nozomu Ando 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 /* for HDRR declaration */ #endif /* __sgi */ + #ifdef BROKEN_NOCOMBRELOC + #include + #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