OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 11:14 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: undefined reference to `__umoddi3'?
PostPosted: Thu May 05, 2022 5:18 am 
Offline
Member
Member

Joined: Tue Aug 31, 2021 7:25 am
Posts: 67
I have a kernel which was built on top of the barebones setup (with the exception of using C++) and have recently tried to incorporate LAI (ACPI AML interpreter) because AML is $#!* into my OS but during compilation, I am having a few problems.

I believe the issues are due to libgcc not being linked properly?

Firstly, I am running a 32-bit kernel hence I do not have native support for 64-bit numbers (which LAI sometimes makes use of) and so g++ tries to make calls to __divmod which should solve my problem, except I am getting import errors:
Quote:
undefined reference to `__udivmoddi4'

Quote:
undefined reference to `__umoddi3'

I have followed the cross compiler build guide here which should also include libgcc.

How I compile my files (with make):
Quote:
i686-elf-g++ -lgcc -O2 -ffreestanding -Wall -Wextra -fno-exceptions -fno-rtti -fno-use-cxa-atexit -g -Wno-unused-variable -Wno-write-strings -Wno-unused-parameter -o $@ -c $<


How I link my object files (with make):
Quote:
i686-elf-g++ -T $< -o ./dist/$@ -ffreestanding -O2 -nostdlib -lgcc -g $(objects)


i686-elf-g++ -v:
Quote:
Using built-in specs.
COLLECT_GCC=i686-elf-g++
COLLECT_LTO_WRAPPER=/home/speedy/opt/cross/libexec/gcc/i686-elf/11.2.0/lto-wrapper
Target: i686-elf
Configured with: ../gcc/configure --target=i686-elf --prefix=/home/speedy/opt/cross --disable-nls --enable-languages=c,c++ --without-headers : (reconfigured) ../gcc/configure --target=i686-elf --prefix=/home/speedy/opt/cross --disable-nls --enable-languages=c,c++ --without-headers
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 11.2.0 (GCC)


I should also note I "ported" the LAI library to C++ (by changing extension to cpp & making void*-int casts explicit) which may be part of the problem? (I reckon it'd be easier to port it to C++ and compile it together with everything else than make exceptions for C).


Top
 Profile  
 
 Post subject: Re: undefined reference to `__umoddi3'?
PostPosted: Thu May 05, 2022 6:38 am 
Offline
Member
Member

Joined: Mon Jul 05, 2021 6:57 pm
Posts: 118
There's no point adding -lgcc to the compilation step; you can remove it.

For linking, you need -lgcc at the end - after the object files and any other libraries. This is due to how static linking works. A library is only pulled in if it contains definitions for undefined symbols that have been encountered from previous objects / libraries.


Top
 Profile  
 
 Post subject: Re: undefined reference to `__umoddi3'?
PostPosted: Thu May 05, 2022 7:01 am 
Offline
Member
Member

Joined: Tue Aug 31, 2021 7:25 am
Posts: 67
davmac314 wrote:
There's no point adding -lgcc to the compilation step; you can remove it.

For linking, you need -lgcc at the end - after the object files and any other libraries. This is due to how static linking works. A library is only pulled in if it contains definitions for undefined symbols that have been encountered from previous objects / libraries.

That worked wonders. Thank you very much! I will remember that from now on.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 61 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group