First time configuring/linking with newlib...

Dan Fowell
Tue Mar 11 15:18:00 GMT 2003

Hey Jeff, thanks so much for your help!  Per your suggestions I've now got
all the needed stubs in for the low-level system calls (write, close,
fstat,etc...) and after adding .fixup and .got2 sections in my linker file
the .bss error went away, and sprintf now actually works great from RAM.

Unfortunately it's too early to celebrate because I can't get it working
from my ROM.  I wonder if it has something to do with the relocation aspects
of .got2 and .fixup?  Maybe something is wrong with my ROM linker file?  The
code doesn't crash, but the sprintf just doesn't do anything although
everything compiles/links OK.  When I display the string after the sprintf
statement it's completely empty.  .got2 and .fixup should be located to RAM
space, right?  Is there anything special I need to do when using newlib in
ROM instead of RAM?

Thanks again,

Below is the pertinent section of the working RAM linker file and the not
yet working ROM linker file:

RAM Version:
.text : { *(.text) *(.rodata) *(.init) *(.fini) } > mem
.data ALIGN (4) : { *(.data) *(.sdata) *(.sdata2) } > mem
.bss ALIGN (4) : { *(.bss) *(.sbss) } > mem
.got2 ALIGN (4) : { *(.got2)} > mem
.fixup ALIGN (4) : { *(.fixup)} > mem

PROVIDE (__stack = .);
_end = .;

ROM Version:
.text : { *(.text) *(.rodata) *(.rdata) *(.init) *(.fini) *(.sec1) }  > rom
.data : AT(ADDR(.text)+SIZEOF(.text)) { *(.data) } > ram
.got2 : AT(ADDR(.text)+SIZEOF(.text)+SIZEOF(.data)) { *(.got2) } > ram
.fixup : AT(ADDR(.text)+SIZEOF(.text)+SIZEOF(.data)+SIZEOF(.got2)) {
*(.fixup) } > ram
.sdata :
AT(ADDR(.text)+SIZEOF(.text)+SIZEOF(.data)+SIZEOF(.got2)+SIZEOF(.fixup)) {
*(.sdata) *(.sdata2) } > ram
.bss ALIGN (4) : { *(.bss) *(.sbss)} > ram

_end =.;

-----Original Message-----
[]On Behalf Of J. Johnston
Sent: Monday, March 10, 2003 6:51 PM
Subject: Re: First time configuring/linking with newlib...

Dan Fowell wrote:
> Hi,
> I'm trying to link in libc.a that was configured for a powerpc-elf target,
> and I must be doing something wrong.  Everything seemed to configure/make
> correctly for the powerpc-elf target, but when I link in the library as
> follows:
> powerpc-elf-ld.exe -g -t -Tram.lnk -o main.elf crt0.o main.o -L. -lc
> I get the following Linking errors:
> ---------------------------LINKING OBJS--------------------------
> powerpc-elf-ld: warning: no memory region specified for section `.fixup'
> powerpc-elf-ld: warning: no memory region specified for section `.got2'
> powerpc-elf-ld: address 0x848 of main.elf section .bss is not within
> mem
> ./libc.a(makebuf.o): In function `__smakebuf':
> wlib-1.10.0/newlib/libc/stdio/makebuf.c:93: undefined reference to
> ./libc.a(sbrkr.o): In function `_sbrk_r':
> wlib-1.10.0/newlib/libc/reent/sbrkr.c:60: undefined reference to `sbrk'
> ./libc.a(writer.o): In function `_write_r':
> wlib-1.10.0/newlib/libc/reent/writer.c:58: undefined reference to `write'
> ./libc.a(closer.o): In function `_close_r':
> wlib-1.10.0/newlib/libc/reent/closer.c:53: undefined reference to `close'
> ./libc.a(fstatr.o): In function `_fstat_r':
> wlib-1.10.0/newlib/libc/reent/fstatr.c:62: undefined reference to `fstat'
> ./libc.a(lseekr.o): In function `_lseek_r':
> wlib-1.10.0/newlib/libc/reent/lseekr.c:58: undefined reference to `lseek'
> ./libc.a(readr.o): In function `_read_r':
> wlib-1.10.0/newlib/libc/reent/readr.c:58: undefined reference to `read'
> powerpc-elf-ld: link errors found, deleting executable `main.elf'
> --------------------------------------------------------------------------
> what are the "fixup" and "got2" sections for?  I don't have those sections
> defined in my linker script, but I don't think I want/need them, do I?

Those sections are used for relocation.  For powerpc-elf, newlib defaults to
compile all code with the -mrelocatable-lib option.

You can see what the default powerpc-elf linker script does by issuing:

   powerpc-elf-ld --verbose

> My linker script assigns where the .bss section should be put into region
> mem.  Is the .bss section of the library fixed?

It appears you have not allocated enough space in your mem region to
the size of .bss needed.

> The undefined reference notifications seem to be related to file handling
> related functions, which I don't want/need anyway. Any ideas on how to get
> libc.a linking in correctly?  All I really want is the sprintf function
> (part of stdio.h).

You are missing a libgloss library to supply the low-level syscalls.  Try
in -lnosys at the end.  You will have to provide some sort of _exit routine
if you have
not already.

-- Jeff J.

More information about the Newlib mailing list