public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* How to properly link libgcc in -ffreestanding mode?
@ 2021-01-27 11:54 Josef Wolf
  2021-01-27 12:07 ` Alexander Monakov
  0 siblings, 1 reply; 4+ messages in thread
From: Josef Wolf @ 2021-01-27 11:54 UTC (permalink / raw)
  To: gcc-help

Hello,

I am trying to follow the steps described in
http://cs107e.github.io/guides/gcc/
to build a freestanding application which is using functions from libgcc

The code I am trying to compile can be found at
https://github.com/ESultanik/mtwister

I guess the problem comes from the usage of the "double" type in thise code.

This is how I invoke compileer and linker:

$ m68k-unknown-elf-gcc -ansi -std=c89 -pedantic -Wall -Wcast-align \
                       -Wstrict-prototypes \
                       -Wmissing-prototypes -Wnull-dereference \
                       -O2 -g -fno-toplevel-reorder -mcpu32 \
                       -ffreestanding -static-libgcc -lgcc \
                       -c -o mtwister.o mtwister.c

$ m68k-unknown-elf-gcc -ansi -std=c89 -pedantic -Wall -Wcast-align \
                       -Wstrict-prototypes \
                       -Wmissing-prototypes -Wnull-dereference \
                       -O2 -g -fno-toplevel-reorder -mcpu32 \
                       -ffreestanding -static-libgcc -lgcc \
                       -Wl,--cref,--section-start=vectors=0 \
                       -nostdlib -Wl,-Ttext=0x400,--entry=entry \
                       -Wl,--oformat,elf32-m68k \
                       -Wl,--cref,-Map,bestd.map \
                       -Wl,-T,ldscript.ld \
                       -o output.elf `cat file.objs`

The linker complains that it can't find __floatunsidf and __divdf3

I have tried to use -Wl,-lgcc instead, but this did not help.

The map file says that libgcc is loaded:

$ grep libgcc *.map
LOAD /m68k-unknown-elf/lib/gcc/m68k-unknown-elf/9.3.0/mcpu32/libgcc.a
LOAD /m68k-unknown-elf/lib/gcc/m68k-unknown-elf/9.3.0/mcpu32/libgcc.a


And I can see that those functions are provided by libgcc:

$ nm /m68k-unknown-elf/lib/gcc/m68k-unknown-elf/9.3.0/mcpu32/libgcc.a|egrep '(__divdf3|__floatunsidf)'
000005a4 T __divdf3
         U __divdf3
         U __divdf3
         U __floatunsidf
         U __floatunsidf
         U __floatunsidf
         U __floatunsidf
         U __floatunsidf
         U __floatunsidf
000000ba T __floatunsidf
         U __divdf3
         U __floatunsidf

What am I missinghere? Any help?

BTW: This is gcc-9.3.0 and binutils-2.34

-- 
Josef Wolf
jw@raven.inka.de

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-27 12:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-27 11:54 How to properly link libgcc in -ffreestanding mode? Josef Wolf
2021-01-27 12:07 ` Alexander Monakov
2021-01-27 12:42   ` Jonathan Wakely
2021-01-27 12:43   ` Josef Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).