Subject: linking problems with i386 mips cross tools and embedded target
To: None <port-mips@netbsd.org>
From: Andrew M. Dyer <adyer@enteract.com>
List: port-mips
Date: 01/14/2001 21:42:52
Hi,
   I'm trying to build a port of micromonitor
(http://www.bell-labs.com/topic/swdist/) to a board using an NEC
Vr5000 using netbsd-1.5 on i386 and the cross-compilation tools in the
mipsel-netbsd package.  I know this a bit off-topic, but if anyone
could shed some light on this I would be very grateful.

I'm having a couple of problems with linking -

1) I get a large batch of messages like the following:

  /usr/pkg/cross/bin/mipsel-netbsd-ld: obj/start.o: linking PIC files with non-PIC files
  Bad value: failed to merge target specific data of file obj/start.o

One for each object file compiled from c - the assembled files don't
seem to have this error.  As far as I can tell nothing being passed to
the linker was compiled/assembled with -fpic or -fembedded-pic, and
I'm not pulling in any libraries.  (linker command line and link
script are included at the end of the message).  If I use
-noinhibit-exec I get an output file which seems to be correct.

Does anyone know how to debug this further and tell what the linker is
really complaining about?


2) In compiled C functions after linking I get a strange value being
loaded into $gp.  In my link map _gp ends up being at 0xa1fe2d50, but
the values being stuck into the $gp register from the linker
relocation are in a different memory region entirely (example below is
at 0xe23e2410) which causes an address exception on a store later on
in the code.


  adyer@locutus: 9> mipsel-netbsd-objdump -d -r obj/start.o
  
  obj/start.o:     file format elf32-littlemips
  
  Disassembly of section .text:
  
  0000000000000000 <init1>:
     0:   3c1c0000        lui     $gp,0x0
  			  0: R_MIPS_HI16  _gp_disp
     4:   279c0000        addiu   $gp,$gp,0
  			  4: R_MIPS_LO16  _gp_disp
     8:   0399e021        addu    $gp,$gp,$t9
     c:   27bdffc0        addiu   $sp,$sp,-64


  
  adyer@locutus: 11> mipsel-netbsd-objdump -d monmips | less
  
  00000000bfc00940 <init1>:
      bfc00940:   3c1ce23e        lui     $gp,0xe23e
      bfc00944:   279c2410        addiu   $gp,$gp,9232
      bfc00948:   0399e021        addu    $gp,$gp,$t9
      bfc0094c:   27bdffc0        addiu   $sp,$sp,-64



the linker command line is:

/usr/pkg/cross/bin/mipsel-netbsd-ld  -G0 -n -Bstatic -noinhibit-exec -T monmips.lnk -Map monmips.map --cref -warn-common -warn-constructors -warn-multiple-gp -warn-section-align -o monmips obj/reset.o     obj/nile4.o    obj/start.o     obj/chario.o obj/cpuio.o     obj/cache.o    obj/mprintf.o   obj/docmd.o obj/at.o        obj/fpgaload.o obj/ioasic1.o obj/cmdtbl.o    obj/genlib.o   obj/dld.o obj/env.o       obj/edit.o     obj/cast.o obj/flash.o     obj/flashdev.o obj/flashpic.o  obj/go.o obj/memcmds.o   obj/mstat.o obj/symtbl.o obj/unpack.o    obj/misccmds.o obj/sbrk.o obj/malloc.o    obj/xmodem.o   obj/ethernet.o  obj/etherdev.o obj/dhcpboot.o  obj/tftp.o     obj/tcpstuff.o  obj/if.o obj/arp.o       obj/moncom.o   obj/icmp.o      obj/lineedit.o obj/password.o  obj/gdb.o      obj/dhcp_00.o obj/main.o      obj/misc.o     obj/except.o obj/tfs.o obj/tfslog.o    obj/tfsloader.o obj/tfscli.o obj/tfsapi.o    obj/tfsclean.o obj/pio_mips.o obj/teacrypt.o obj/led.o libz.a


and the linker command script is:


OUTPUT_FORMAT("elf32-littlemips")
OUTPUT_ARCH(mips)

MEMORY
{
  RAM : ORIGIN = 0xa0000000, LENGTH = 32M
  ROM : ORIGIN = 0xbfc00000, LENGTH = 512K
}

SECTIONS
{
  /* Read-only sections, merged into text segment: */

  .text 0xbfc00000 :
  {
    _ftext = . ;
    *(.text)
  } > ROM =0
  _etext = .;
  PROVIDE (etext = .);
  .rodata    : { *(.rodata) *(.gnu.linkonce.r*)  } > ROM
  _erodata = .;
  .data 0xa1fe0000 : AT ( ADDR(.rodata) + SIZEOF(.rodata) )
  {
    _fdata = . ;
    *(.data)
    *(.gnu.linkonce.d*)
    CONSTRUCTORS
  }
  _gp = ALIGN(0x10) ;
  .got    . : AT ( LOADADDR(.data) + SIZEOF(.data))
              { *(.got.plt) *(.got) } > RAM
  .sdata  . : AT ( LOADADDR(.got) + SIZEOF(.got))       { *(.sdata) } > RAM
  .lit8   . : AT ( LOADADDR(.sdata) + SIZEOF(.sdata))   { *(.lit8) } > RAM
  .lit4   . : AT ( LOADADDR(.lit8) + SIZEOF(.lit8))     { *(.lit4) } > RAM
  _edata  =  .;
  PROVIDE (edata = .);
  __bss_start = .;
  _fbss = .;
  .sbss    . : { *(.sbss) *(.scommon) } > RAM
  .bss     .  :
  {
    *(.dynbss)
    *(.bss)
    *(COMMON)
  } > RAM
  . = ALIGN(4);
  _end = . ;
  PROVIDE (end = .);

  /* Debug sections.  These should never be loadable, but they must have
     zero addresses for the debuggers to work correctly.  */

  .line                 0 : { *(.line)                  }
  .debug                0 : { *(.debug)                 }
  .debug_sfnames        0 : { *(.debug_sfnames)         }
  .debug_srcinfo        0 : { *(.debug_srcinfo)         }
  .debug_macinfo        0 : { *(.debug_macinfo)         }
  .debug_pubnames       0 : { *(.debug_pubnames)        }
  .debug_aranges        0 : { *(.debug_aranges)         }
  .mdebug               0 : { *(.mdebug)                }
  .reginfo              0 : { *(.reginfo)               }
  .rel_dyn              0 : { *(.rel.dyn)               }
}