[comp.sys.sgi] "Relocation out-of-range" errors

pwp@shamash.cdc.com ( HOUFAC) (10/06/89)

A few weeks back Steve Maurer asked what caused "jump relocation out of range"
errors, and someone explained it.  

Now, it's happening to me and the response has aged-away on my system.

Can someone please explain again?  (I promise to save it this time!)

Also, is this stuff archived somewhere on the net?  (vgr.brl.mil still isn't
responding.)

Thanks in advance:
--Pete
  pwp@shamash.cdc.com

davea@quasar.wpd.sgi.com (David B. Anderson) (10/08/89)

In article <14188@shamash.cdc.com> pwp@shamash.UUCP (Pete Poorman) writes:
>A few weeks back Steve Maurer asked what caused "jump relocation out of range"
>errors, and someone explained it.  
>
>Now, it's happening to me and the response has aged-away on my system.
>
>Can someone please explain again?  (I promise to save it this time!)

The question was answered by:

len@synthesis.Synthesis.COM (Len Lattanzi) in <28025@mips.mips.COM>
;;Typically this is caused by one importing module referencing a symbol as text
;;and trying to jump to it. And the exporting module defining the symbol
;;to be data. Text and Data are normally too far apart to jump between.
;;You could use -Wl,-yerror,-yasm on the link command to indicate all
;;modules referencing error and asm and make sure the uses are consistent.

Len was exactly right.

Some further information:

A call to a named function is generated as a JAL instruction.

In the MIPS R2/3000 a JAL gets 26 bits for the address.   It is a word
address by definition, so  the 2 least significant bits are implicit.
Shifting the 26 bits from the instruction left two bits and making the top
4 bits identical to the address of the jump instruction itself gives a
target address.
	(Wouldn't a picture be better than words? :-)

In the ZMAGIC format (the format used for executables in IRIX) code starts
at 0x400000 and data starts at 0x10000000.

When one does a call (JAL) and the name is resolved to a _data address_ one
gets ``jump relocation out of range'' since the linker can see that the top
4 bits are not the same in the JAL instruction address and the target
address.

Regards,
[ David B. Anderson  Silicon Graphics  (415)335-1548  davea@sgi.com ]

hultquis@orville.nas.nasa.gov (Jeff P.M. Hultquist) (10/09/89)

> From: davea@quasar.wpd.sgi.com (David B. Anderson)
> > In article <14188@shamash.cdc.com> pwp@shamash.UUCP (Pete Poorman) writes:
> > > A few weeks back Steve Maurer asked what caused 
> > > "jump relocation out of range" errors, ...
> > > Can someone please explain again?
> > 
> > The question was answered by:
> > len@synthesis.Synthesis.COM (Len Lattanzi) in <28025@mips.mips.COM>
> > > ;;Typically this is caused by one importing module referencing a 
> > >  symbol as text and trying to jump to it. And the exporting module
> > > defining the symbol to be data.  Text and Data are normally too 
> > > far apart to jump between.
> 
> In the ZMAGIC format (the format used for executables in IRIX) code starts
> at 0x400000 and data starts at 0x10000000.

I ran into this problem when implemented a simple dynamic loader for
the Personal Iris.  The newly compiled code would be loaded into a
malloc'ed chunk of memory, and the address of that block would then be
treated as a pointer to a function.  The way around this problem is to
place Data and Text more closely together when building the
application.  How does one do this?

	cc -Wl,-D,a000000 <files.o>

This instructs the linker to place the Data segment lower in the
address space.

bill@alta.stat.washington.edu (Bill Dunlap) (10/10/89)

I dealt with the 'jump out of range' linking errors by adding to LDFLAGS
	-T 10000000 -D 12000000
(or the equivalent -Wl,'...' if you link through cc).
to get text and data close enough.  Make sure your text segment is not
bigger than 0x2000000 bytes or bump up the difference a bit.
This got my dynamic linking code to run.