Subject: Re: unable to build libc with gcc from source tree
To: Tom Yu <tlyu@mit.edu>
From: Jonathan Stone <jonathan@DSG.Stanford.EDU>
List: port-pmax
Date: 11/10/1996 18:59:02
In message <9610290147.AA24939@tesla-coil.MIT.EDU>,  Tom Yu writes

>What happened: I compiled and built the entire source distribution
>(SUP from a day or two ago), starting from the 1.2alpha binary
>distribution.  This required some minor Makefile tweaking.  I
>installed it.  So far, so good.
>
>I then supped today's sources and tried to build them.  They failed
>because the __warn_references macro uses the __attribute__ keyword of
>gcc applied to a section... and the gcc that ships in the source tree
>doesn't define ASM_OUPUT_SECTION_NAME for mips, and thus fails
>miserably to compile the backwards-compatibility files of libc.
>
>Why is there a compiler in the source tree that cannot compile the
>libc in the same source tree?

Short anwser: because the FSF hasn't ever doen anything with the
patches that add __warn_references support, and the person who
wrote the perl script that pulls  FSF gcc distributions into the tree
never folded  the relevant patches into the perl script.

>  Is there any good reason for this?

None whatsoever. I'm embarrassed.   (The relevant fixes are two
years old.)  

The changes are now in the NetBSD tree, though they may break if
and when 2.7.2.1 is pulled into the tree.

 >
>And also, the same old question that has been raised many times, how
>do I get shared library support for the pmax?  Should I pick up a
>recent FSF copy of gcc and binutils and hope they work?

No, not quite.

The shared-lib changes to the _libraries_ are all folded into the NetBSD/mips
source tree. My thanks to Manuel Bouyer for providing an initial port,
based I beleive on the OpenBSD code.

You'll still need:

	- a patch to the GCC mips config to produce SGI-style
	  SVR4 mips ABI .o files.
	  The patch I use is appended below.


	- binutils 2.7 as, ld to assemble and link the output
	  of the above gcc.
	  NOTE: the new ld in binutils 2.7 _cannot_ link kernels.
	  you'll need to keep the old ld around (e.g,.as /usr/bin/ld.old)
	 and use that to link kernels.

	- Tweaked BSD makefiles in /usr/share/mk to use the above
	  shared-library compiler toolchain.

	- a crt0.c, ld.so,  ldconfig that work with the above
	  toolchain. (Recent OpenBSD binaries do _not_ work with NetBSD 1.2).
	  I have never seen source for these, though perhaps
	  Manuel Bouyer has them somewhere.

Last, if you're running a post-1.2 NetBSD/pmax kernel (e..g, 1.2A -current),
the MI elf32/elf64 changes have broken loading of mips ELF binaries.


Here's the patch to gcc to produce mips svr4 ABICALL .o files.
Note that, by default, this _won't_ work with .o files produced
by the existing toolchain. Compiling with
	-mno-half-pic -mno-abicalls

_may_ result in .o files compatible with the old assembler.



*** /usr/src/gnu/usr.bin/gcc/arch/mips/netbsd.h.DIST	Fri Apr  5 04:19:03 1996
--- /usr/src/gnu/usr.bin/gcc/arch/mips/netbsd.h	Tue Oct 15 20:27:17 1996
***************
*** 18,24 ****
  the Free Software Foundation, 59 Temple Place - Suite 330,
  Boston, MA 02111-1307, USA.  */
  
! #define DECSTATION
  
  /* Look for the include files in the system-defined places.  */
  
--- 18,27 ----
  the Free Software Foundation, 59 Temple Place - Suite 330,
  Boston, MA 02111-1307, USA.  */
  
! /* We settle for little endian for now */
! 
! #define TARGET_ENDIAN_DEFAULT 0
! 
  
  /* Look for the include files in the system-defined places.  */
  
***************
*** 50,56 ****
  #undef LINK_SPEC
  #define LINK_SPEC \
    "%{G*} %{EB} %{EL} %{mips1} %{mips2} %{mips3} \
!    %{!nostdlib:%{!r*:%{!e*:-e __start}}} -dc -dp %{static:-Bstatic} %{assert*}"
  
  /* We have atexit(3).  */
  
--- 53,64 ----
  #undef LINK_SPEC
  #define LINK_SPEC \
    "%{G*} %{EB} %{EL} %{mips1} %{mips2} %{mips3} \
!    %{bestGnum} %{shared} %{non_shared} \
!    %{call_shared} %{no_archive} %{exact_version} \
!    %{!shared: %{!non_shared: %{!call_shared: -non_shared}}} \
!    %{!dynamic-linker:-dynamic-linker /usr/libexec/ld.so} \
!    %{!nostdlib:%{!r*:%{!e*:-e __start}}} -dc -dp \
!    %{static:-Bstatic} %{!static:-Bdynamic} %{assert*}"
  
  /* We have atexit(3).  */
  
***************
*** 69,74 ****
--- 77,100 ----
  -Asystem(unix) -Asystem(NetBSD) -Amachine(mips)"
  #endif
  
+ #ifndef CC1_SPEC
+ #define CC1_SPEC "\
+ %{gline:%{!g:%{!g0:%{!g1:%{!g2: -g1}}}}} \
+ %{mips1:-mfp32 -mgp32}%{mips2:-mfp32 -mgp32}\
+ %{mips3:%{!msingle-float:%{!m4650:-mfp64}} -mgp64} \
+ %{mips4:%{!msingle-float:%{!m4650:-mfp64}} -mgp64} \
+ %{mfp64:%{msingle-float:%emay not use both -mfp64 and -msingle-float}} \
+ %{mfp64:%{m4650:%emay not use both -mfp64 and -m4650}} \
+ %{m4650:-mcpu=r4650} \
+ %{G*} %{EB:-meb} %{EL:-mel} %{EB:%{EL:%emay not use both -EB and -EL}} \
+ %{pic-none:   -mno-half-pic} \
+ %{pic-lib:    -mhalf-pic} \
+ %{pic-extern: -mhalf-pic} \
+ %{pic-calls:  -mhalf-pic} \
+ %{save-temps: } \
+ %{!mno-abicalls:    -mabicalls}"
+ #endif
+ 
  /* Always uses gas.  */
  #ifndef ASM_SPEC
  #define ASM_SPEC "\
***************
*** 79,85 ****
  %{ggdb:-g} %{ggdb0:-g0} %{ggdb1:-g1} %{ggdb2:-g2} %{ggdb3:-g3} \
  %{gstabs:-g} %{gstabs0:-g0} %{gstabs1:-g1} %{gstabs2:-g2} %{gstabs3:-g3} \
  %{gstabs+:-g} %{gstabs+0:-g0} %{gstabs+1:-g1} %{gstabs+2:-g2} %{gstabs+3:-g3} \
! %{gcoff:-g} %{gcoff0:-g0} %{gcoff1:-g1} %{gcoff2:-g2} %{gcoff3:-g3}"
  #endif
  
  #ifndef CPP_SPEC
--- 105,112 ----
  %{ggdb:-g} %{ggdb0:-g0} %{ggdb1:-g1} %{ggdb2:-g2} %{ggdb3:-g3} \
  %{gstabs:-g} %{gstabs0:-g0} %{gstabs1:-g1} %{gstabs2:-g2} %{gstabs3:-g3} \
  %{gstabs+:-g} %{gstabs+0:-g0} %{gstabs+1:-g1} %{gstabs+2:-g2} %{gstabs+3:-g3} \
! %{gcoff:-g} %{gcoff0:-g0} %{gcoff1:-g1} %{gcoff2:-g2} %{gcoff3:-g3} \
! %{membedded-pic} %{fPIC:-KPIC}"
  #endif
  
  #ifndef CPP_SPEC
***************
*** 92,101 ****
  #endif
  
  #define LIB_SPEC "%{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}"
! #define STARTFILE_SPEC ""
  
  #ifndef MACHINE_TYPE
! #define MACHINE_TYPE "NetBSD/pmax"
  #endif
  
  #define TARGET_DEFAULT MASK_GAS
--- 119,132 ----
  #endif
  
  #define LIB_SPEC "%{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}"
! 
! #undef LIB_SPEC
! #define LIB_SPEC "%{p:-lprof1} %{pg:-lprof1} -lc /usr/lib/crtn.o%s"
! #define STARTFILE_SPEC \
!    "%{!shared:%{pg:gcrt1.o%s}%{!pg:%{p:mcrt1.o%s libprof1.a%s}%{!p:crt1.o%s}}}"
  
  #ifndef MACHINE_TYPE
! #define MACHINE_TYPE "NetBSD/mips"
  #endif
  
  #define TARGET_DEFAULT MASK_GAS
***************
*** 103,108 ****
--- 134,144 ----
  
  #define LOCAL_LABEL_PREFIX	"."
  
+ /* -G is incompatible with -KPIC which is the default, so only allow objects
+    in the small data section if the user explicitly asks for it.  */
+ #undef MIPS_DEFAULT_GVALUE
+ #define MIPS_DEFAULT_GVALUE 0
+ 
  #include "mips/mips.h"
  
  /*
***************
*** 150,165 ****
     function's return value.  We allow for that here.  */
  
  #undef ASM_DECLARE_FUNCTION_NAME
! #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)			\
    do {									\
!     fprintf (FILE, "\t%s\t ", TYPE_ASM_OP);				\
!     assemble_name (FILE, NAME);						\
!     putc (',', FILE);							\
!     fprintf (FILE, TYPE_OPERAND_FMT, "function");			\
!     putc ('\n', FILE);							\
!     ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL));			\
    } while (0)
  
  /* Write the extra assembler code needed to declare an object properly.  */
  
  #undef ASM_DECLARE_OBJECT_NAME
--- 186,219 ----
     function's return value.  We allow for that here.  */
  
  #undef ASM_DECLARE_FUNCTION_NAME
! #define ASM_DECLARE_FUNCTION_NAME(STREAM, NAME, DECL)			\
    do {									\
!     extern FILE *asm_out_text_file;                                   \
!                                                                       \
!     if (TARGET_GP_OPT)                                                \
!       {                                                               \
!       int align;                                                      \
!       STREAM = asm_out_text_file;                                     \
!       /* Output ALIGN again to the new stream. XXX  */                \
!       align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);         \
!       if (align > 0)                                                  \
!         {                                                             \
!           if (output_bytecode)                                        \
!             BC_OUTPUT_ALIGN (STREAM, align);                          \
!           else                                                        \
!             ASM_OUTPUT_ALIGN (STREAM, align);                         \
!         }                                                             \
!       }                                                               \
!     fprintf (STREAM, "\t%s\t ", TYPE_ASM_OP);                         \
!     assemble_name (STREAM, NAME);                                     \
!     putc (',', STREAM);                                               \
!     fprintf (STREAM, TYPE_OPERAND_FMT, "function");                   \
!     putc ('\n', STREAM);                                              \
!     ASM_DECLARE_RESULT (STREAM, DECL_RESULT (DECL));                  \
!     HALF_PIC_DECLARE (NAME);                                          \
    } while (0)
  
+ /* Assemble generic sections.
  /* Write the extra assembler code needed to declare an object properly.  */
  
  #undef ASM_DECLARE_OBJECT_NAME