Link error about sbrk

loody miloody@gmail.com
Tue Nov 24 16:44:00 GMT 2009


Hi:
thanks for your kind reply ^^
2009/11/17 Jeff Johnston <jjohnstn@redhat.com>:
> On 15/11/09 10:53 AM, loody wrote:
>>
>> Dear all:
>> I cross-compile newlib as mips target, but when I link the libraries I
>> build in libgloss, I get the error as below:
>>
>> # make TOOLCHAIN=mipsel-unknown-elf-
>> mipsel-unknown-elf-ld -T ./link.xn -o TestCode.elf -Map TestCode.map
>> --oformat elf32-littlemips  init.o reset.o atexit.o -static -nostdlib
>> -L/media/sdb1/newlib-1.17.0/mipsel/libgloss/libnosys
>> -L/media/sdb1/newlib-1.17.0/mipsel/libgloss/mips/libidt.a
>> -L/media/sdb1/newlib-1.17.0/mipsel/newlib -lnosys -lc
>> /media/sdb1/newlib-1.17.0/mipsel/newlib/libc.a(lib_a-sbrkr.o): In
>> function `_sbrk_r':
>> (.text+0x14): undefined reference to `sbrk'
>> /media/sdb1/newlib-1.17.0/mipsel/newlib/libc.a(lib_a-sbrkr.o): In
>> function `_sbrk_r':
>> (.text+0x14): relocation truncated to fit: R_MIPS_26 against `sbrk'
>> make: *** [TestCode.elf] Error 1
>> #
>>
>> My questions are:
>> 1. take mips for example, why we have to build some many different
>> libraries  as
>> libcfe.a
>> libidt.a
>> liblsi.a
>> libnullmon.a
>> libpmon.a
>> instead of build a bare one?
>> ( all of them are just different combinations of the .o files)
>> if we ar all .o files as one library, linker will link what we need
>> automatically, right?
>
> No, they are different libraries and there is functional overlap.  For
> example, libnullmon.a is a stub library.  libcfe is for MIPS boards running
> cfe.  libpmon.a is for boards running the PMON monitor.  For example, how do
> you expect the linker to magically know which version of the read syscall
> you actually mean?  From libnullmon.a read is a stub which does nothing
> whereas from libpmon.a it will access a magic slot in the PMON vector.  The
> latter choice expects that you are running the PMON monitor on your board.
Would you please tell me what PMON, idt  and cfe used for?
are they bootloader as http://www.linux-mips.org/wiki/Firmware shows?
if so, why the document say PMON can monitor something?
in my opinion, the loader is do something like dram setting, load kernel, etc.
After kernel executes, it is useless, am i right?

>
>>
>> 2. the files I need to modify, system calls that act as 'glue' between
>> newlib and my OS, are all located at libgloss/mips, right? If so, I
>> have checked that sbrk is located at syscalls.c and it is ared at
>> libidt.a, but why linker still complain he cannot find the sbrk? did I
>> miss something?
>>
>
> Your -L option should specify a directory path, not the library itself (you
> have libidt.a at the end).  You should then specify -Tidt.ld or -Tidt32.ld
> as your linker script and it will bring in libidt.a for you.
> It is highly recommended that you use gcc to do your linking and specify
> -Tidt.ld or -Tidt32.ld.  This simplifies things when you build/install
> newlib and gcc in the same source tree because you don't need to specify -L
> statements and you automatically pick up the correct C library for your
> compiler options.  For example, the little-endian vs the big-endian version
> of the newlib library.  When you use gcc to link, it knows which options you
> specify and maps them to the directories which contain the appropriate
> library built with the same options.  If you use ld, you have to manually
> specify the library locations yourself and you might get them wrong.

I modify my command and get the errors at the end of this letter.
the first error comes from my not implement "outbyte" in systemcalls.
but why I use ld it will complain "undefined reference to `_fini'".
After checking the source code, it seems a function that define externally.

libgloss/mips/crt0.S:184:	.type	_fini,@function
libgloss/mips/crt0.S:202:	LA (a0, _fini)

But i cannot find out where it is defined.
What makes me curious is the fist one can find it.
Is there any setting I miss in the second command?

BTW, why we need -lgcc in ld scripts under libgloss?
is there any gcc libraries we need in newlib when linking?

appreciate your help,
miloody

/newlib-1.17.0/libgloss/mips# mipsel-unknown-elf-gcc
-I../../build/mipsel/include/ -T../../build/mipsel/lib/nullmon.mips.ld
-L../../build/mipsel/lib/
-L/root/bare_metal/x-tools/mipsel-unknown-elf/lib/gcc/mipsel-unknown-elf/4.2.4
test.c -static -g -o test
/tmp/ccYNVMOZ.o: In function `main':
(.text+0x14): undefined reference to `outbyte'
/tmp/ccYNVMOZ.o: In function `main':
(.text+0x14): relocation truncated to fit: R_MIPS_26 against `outbyte'
/tmp/ccYNVMOZ.o: In function `main':
(.text+0x20): undefined reference to `outbyte'
/tmp/ccYNVMOZ.o: In function `main':
(.text+0x20): relocation truncated to fit: R_MIPS_26 against `outbyte'
/tmp/ccYNVMOZ.o: In function `main':
(.text+0x2c): undefined reference to `outbyte'
/tmp/ccYNVMOZ.o: In function `main':
(.text+0x2c): relocation truncated to fit: R_MIPS_26 against `outbyte'
/tmp/ccYNVMOZ.o: In function `main':
(.text+0x38): undefined reference to `outbyte'
/tmp/ccYNVMOZ.o: In function `main':
(.text+0x38): relocation truncated to fit: R_MIPS_26 against `outbyte'
../../build/mipsel/lib//libnullmon.a(print.o): In function `print':
(.text+0x20): undefined reference to `outbyte'
../../build/mipsel/lib//libnullmon.a(print.o): In function `print':
(.text+0x20): relocation truncated to fit: R_MIPS_26 against `outbyte'
collect2: ld returned 1 exit status
/newlib-1.17.0/libgloss/mips#



mipsel-unknown-elf-ld -EL -T../../build/mipsel/lib/nullmon.mips.ld
-L../../build/mipsel/lib/
-L/root/bare_metal/x-tools/mipsel-unknown-elf/lib/gcc/mipsel-unknown-elf/4.2.4
-static test.o -o test ../../build/mipsel/lib//crt0.o: In function
`init':
../../.././libgloss/mips/crt0.S:(.text+0x100): undefined reference to `_fini'
../../.././libgloss/mips/crt0.S:(.text+0x104): undefined reference to `_fini'
../../.././libgloss/mips/crt0.S:(.text+0x110): undefined reference to `_init'
../../.././libgloss/mips/crt0.S:(.text+0x110): relocation truncated to
fit: R_MIPS_26 against `_init'
test.o: In function `main':
(.text+0x14): undefined reference to `outbyte'
test.o: In function `main':
(.text+0x14): relocation truncated to fit: R_MIPS_26 against `outbyte'
test.o: In function `main':
(.text+0x20): undefined reference to `outbyte'
test.o: In function `main':
(.text+0x20): relocation truncated to fit: R_MIPS_26 against `outbyte'
test.o: In function `main':
(.text+0x2c): undefined reference to `outbyte'
test.o: In function `main':
(.text+0x2c): relocation truncated to fit: R_MIPS_26 against `outbyte'
test.o: In function `main':
(.text+0x38): undefined reference to `outbyte'
test.o: In function `main':
(.text+0x38): relocation truncated to fit: R_MIPS_26 against `outbyte'
test.o: In function `main':
(.text+0x48): undefined reference to `print'
test.o: In function `main':
(.text+0x48): relocation truncated to fit: R_MIPS_26 against `print'



More information about the Newlib mailing list