[uClinux-dev] C++, IOStreams, relocation truncated to fit

David McCullough davidm at snapgear.com
Wed Nov 21 18:42:15 EST 2001


Jivin Ken Treis lays it down ...
[...]
> Okay, here's some more info.  Bear with me, I'm new to the lower levels 
> of C compilers.
> 
> The program wouldn't link when I used either "-fPIC -msep-data" or just 
> "-fPIC" in my CFLAGS.  It successfully built the test.elf, but it seemed 


Just in case you misinterpreted what I said,  you never need -fPIC.
-fPIC break things,  for pick use -msep-data and only -msep-data, otherwise
you may leave out that option and get non-pic code that will also work.


> to be having trouble flattening it out.  I ran elf2flt myself and got a 
> whole bunch of warnings, but ultimately it built a flat executable. 


Don't even try it,  add the -Wl,-elf2flt flag to the link line and it will
take care of it for you.  It can dectect msep-data code or not and run as
required.


>  That executable never ran -- perhaps because I didn't give elf2flt the 
> right arguments or perhaps because I couldn't figure out how to drive 
> elf2flt correctly.
> 
> However, when I removed the -lgcc, it linked and ran on my eval board.
>
> So some further questions:
> 
> - When do I really need libgcc.a?  Does the compiler automagically 
> figure out when I need it?  I have vague recollections that colilo 
> wouldn't build without it.

Usually you do not need to add it,  but for C++ the library cross
references can get a bit wild and you may need to mess with some library
order/add multiples to pull it off.

Only add it when it fails to link.  Sometimes you need something like

	-lgcc -lc -lgcc

Can't remember why ;-)

> - Does link order matter here?  If I do turn out to need libgcc, should 
> I put it "closer" in the link order to the .o files that call its functions?


As a rule -lgcc should always be last,  but occasionally it refers back to
libc functions that may not have been included,  and you need the above to
fix it.

You can fix the order problems by using the gcc/ld link groups,  but I
can't remember the actual option,  something like --start-group, --end-group


> - How is it that I was able to build and run without linking the 
> libstdc++.a?

You do not need libstdc++ for C++,  you only need it if you use functions
from the libstdc++.  Actually,  g++ does include these libraries for
you,  I just checked.  But it doesn't add '-lc'.

> - By removing libgcc.a, am I just buying myself a little bit of space 
> that may quickly be used up (and therefore cause this problem again in a 
> few days / weeks / months)?

It only links in what it needs,  so you can add any library you want to the
link line (within reason ;-) and not have any code bloat.

> - What is XIP?  I don't even dare hazard a guess.


eXecute In Place,  this is what the -msep-data option was created to
achieve.  It allows the text section of programs to reside in ROM and be
shared by multiple invocations of the same program.  A big saving on an
embedded system ;-)

Cheers,
Davidm

-- 
David McCullough:    Ph: +61 7 3435 2815  http://www.SnapGear.com
davidm at snapgear.com  Fx: +61 7 3891 3630  825 Stanley St., W'gabba QLD 4102, Oz
This message resent by the uclinux-dev at uclinux.org list server http://www.uClinux.org/



More information about the uClinux-dev mailing list