[coldfire-gnu-discuss] Override printf

Corrin Meyer Corrin.Meyer at dornerworks.com
Fri Jul 11 14:48:11 UTC 2008


>> It looks like this is part of the CS3 library so I am guessing that  
>> Newlib is getting linked in which then makes calls to the functions  
>> above and that CS3 is complaining that they don't exist since I
haven't  
>> provided them for my hardware.  Is this correct?  How can I get rid
of  
>> these warnings?  If Newlib is being linked in (which I think it is  
>> because my final binary is MUCH bigger than before), how do I get it
not 
>> to link in and instead use my provided printf?
>
> You are most likely correct that newlib is still being linked in.  You
can 
> track this down by using the -v option on your final link, to see how
the 
> linker is being invoked.  The -Wl,-Map,a.map option may also be useful
to 
> determine what is pulling in newlib.

At a guess, it is referenced by the linker script (the INPUT
directive).

-- 
Daniel Jacobowitz
CodeSourcery



I took a quick look at the linker script.  I am using one of the default
ones: m52235evb-rom.ld.  Our board is modeled after the 52235EVB so it
seemed like it would work quite nicely.  Looking at this script I don't
see any references to Newlib.  Also, since when I compile a simple empty
main() the resultant image is very small I don't think the linker script
is trying to include Newlib be default; only if it thinks it is being
referenced.

I ran the link step with "-Wl,-v" so that I could see how the linker was
being invoked.  I got the following.

cd /home/CorrinMeyer/versimation/sw/1.1/build/firmware &&
/usr/bin/cmake.exe -E cmake_link_script
CMakeFiles/firmware.elf.dir/link.txt --verbose=1
"/cygdrive/c/Program Files/CodeSourcery/Sourcery G++
Lite/bin/m68k-elf-gcc.exe"    -fPIC -nodefaultlibs
-Wl,-v,-Map,firmware.map -T m52235evb-ram.ld -mcpu=52235
CMakeFiles/firmware.elf.dir/src/init.c.o
CMakeFiles/firmware.elf.dir/src/flash.c.o
CMakeFiles/firmware.elf.dir/src/crc.c.o
CMakeFiles/firmware.elf.dir/src/irq.c.o
CMakeFiles/firmware.elf.dir/src/main.c.o  -o firmware.elf
../arch/mcf52235/libarch.a ../libc/libdwc.a ../libio/libio.a
../libdw/libdw.a

collect2 version 4.2.3 (68k, Motorola syntax)
c:/program files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/bin/ld.exe
--sysroot=c:\program files\codesourcery\sourcery g++
lite\bin\../m68k-elf -o firmware.elf c:/program
files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/m5208/crtbegin.o -Lc:/program
files/codesourcery/sourcery g++ lite/bin/../lib/gcc/m68k-elf/4.2.3/m5208
-Lc:/program files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib/m5208
-Lc:/program files/codesourcery/sourcery g++
lite/bin/../m68k-elf/lib/m5208 -Lc:/program files/codesourcery/sourcery
g++ lite/bin/../lib/gcc/m68k-elf/4.2.3 -Lc:/program
files/codesourcery/sourcery g++ lite/bin/../lib/gcc -Lc:/program
files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib -Lc:/program
files/codesourcery/sourcery g++ lite/bin/../m68k-elf/lib -v -Map
firmware.map CMakeFiles/firmware.elf.dir/src/init.c.o
CMakeFiles/firmware.elf.dir/src/flash.c.o
CMakeFiles/firmware.elf.dir/src/crc.c.o
CMakeFiles/firmware.elf.dir/src/irq.c.o
CMakeFiles/firmware.elf.dir/src/main.c.o ../arch/mcf52235/libarch.a
../libc/libdwc.a ../libio/libio.a ../libdw/libdw.a c:/program
files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/m5208/crtend.o -T m52235evb-ram.ld

GNU ld (Sourcery G++ Lite 4.2-125) 2.18.50.20080215c:/program
files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib/m5208\libcs3
unhosted.a(unhosted-close.o): warning: IO function 'close' used
c:/program files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib/m5208\libcs3
unhosted.a(unhosted-fstat.o): warning: IO function 'fstat' used
c:/program files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib/m5208\libcs3
unhosted.a(unhosted-isatty.o): warning: IO function 'isatty' used
c:/program files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib/m5208\libcs3
unhosted.a(unhosted-lseek.o): warning: IO function 'lseek' used
c:/program files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib/m5208\libcs3
unhosted.a(unhosted-read.o): warning: IO function 'read' used
c:/program files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib/m5208\libcs3
unhosted.a(unhosted-write.o): warning: IO function 'write' used

>From this I am seeing that gcc is being invoked as the front end to the
linker.  I am using CMake to manage the build process and this is just
how it does it.  I have passed in "-nodefaultlibs".  My understanding is
that this should stop the C library (Newlib) from being linked in but
keep the Startup code (CS3?) which is what I want.  Does indeed seem
that the C library is not being included (no -lc on the linker command)

I also generated a Map file to see what was being included and where.
Here is a snippet.

c:/program files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib/m5208\libc.a
(lib_a-fclose.o)
                              c:/program files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib/m5208\libc.a
(lib_a-findfp.o) (fclose)
c:/program files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib/m5208\libc.a
(lib_a-fstatr.o)
                              c:/program files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib/m5208\libc.a
(lib_a-makebuf.o) (_fstat_r)
c:/program files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib/m5208\libc.a
(lib_a-isattyr.o)
                              c:/program files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib/m5208\libc.a
(lib_a-makebuf.o) (_isatty_r)
c:/program files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib/m5208\libc.a
(lib_a-lseekr.o)
                              c:/program files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib/m5208\libc.a
(lib_a-stdio.o) (_lseek_r)
c:/program files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib/m5208\libc.a
(lib_a-readr.o)
                              c:/program files/codesourcery/sourcery g++
lite/bin/../lib/gcc/m68k-elf/4.2.3/../../../../m68k-elf/lib/m5208\libc.a
(lib_a-stdio.o) (_read_r)

So even though the linker is being told not to include the C library (as
far as I can tell), it is.

Corrin Meyer



More information about the coldfire-gnu-discuss mailing list