undefined reference to `__umoddi3'

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
CocaCola
Member
Member
Posts: 36
Joined: Fri Sep 07, 2012 9:11 am

undefined reference to `__umoddi3'

Post by CocaCola »

Hello.
I'm working on a 32-bit kernel. Some functions, for example vsprintf() need to be able to print 64-bit integers.

However, when I try to use uintmax_t or uint64_t in the helper functions for vsprintf() I get a linker error:

Code: Select all

libc/stdio/vsnprintf.o: In function `uint2cstr.part.0':
vsnprintf.c:(.text+0x40): undefined reference to `__umoddi3'
vsnprintf.c:(.text+0x66): undefined reference to `__udivdi3'
Adding -lgcc -lc to the linker options does not work either:

Code: Select all

LDFLAGS := -T linker.ld -m elf_i386 -nostdlib -lgcc -lc

ld: cannot find -lgcc
ld: cannot find -lc
Should I try and write custom versions of these functions, or can they somehow be included still?
Thanks.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: undefined reference to `__umoddi3'

Post by bluemoon »

did you build libgcc yet?
Check the wiki: GCC_Cross-Compiler

In some case, you may as well tell gcc the path of libgcc with -L
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: undefined reference to `__umoddi3'

Post by Griwes »

-lc in kernel linker invocation is usually a sign you didn't RTFM.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: undefined reference to `__umoddi3'

Post by sortie »

Note that due to the stupid way traditional Unix linking works, you have to put -lgcc after all libraries that could possibly use it (including libc).

The solution is, as previously pointed out, to build a full cross-compiler and use libgcc. The wiki has some information on transitioning to a cross-compiler at http://wiki.osdev.org/Why_do_I_need_a_Cross_Compiler%3F
AbstractYouShudNow
Member
Member
Posts: 92
Joined: Tue Aug 14, 2012 8:51 am

Re: undefined reference to `__umoddi3'

Post by AbstractYouShudNow »

These are functions from libgcc that allow it to perform 64-bit operations on a 32-bit processor.
This doesn't matter for addition or subtraction, because it can use the CARRY flag (ADD/ADC) on two 32-bit registers.
However, there is no hardware support for performing multiplication or division.

Typically, what you want to do is link to libgcc. For doing so, when building your GCC cross-compiler, once you have your target binutils instealled and target GCC configured, execute 'make all-target-libgcc' and 'make install-target-libgcc' to install it. After that, you should be able to use -lgcc option without getting errors.

More information on that on The wiki article

Alternatively, if you don't want to use libgcc, you can implement them very simply using incremental calculation (e.g. 4*3 = 4+4+4) and simple loops. As an example, MikeOS uses that way to perform 32-bit operations on processors that are 16-bit (or more recent processors operating in real mode.
Post Reply