libatomic support

support for the powerpc toolchain
Post Reply
juvinious
Posts: 5
Joined: Thu Feb 22, 2024 4:55 pm

libatomic support

Post by juvinious » Thu Feb 22, 2024 5:19 pm

Hello,

Is it possible to get libatomic.a support for the gcc port?

Simple test to demonstrate:

Code: Select all

#include <atomic>
int main(){
        std::atomic<int> test;
        return 0;
}

Code: Select all

/opt/devkitpro/devkitPPC/bin/powerpc-eabi-g++ main.cpp -std=c++11 -o main -latomic
/opt/devkitpro/devkitPPC/bin/../lib/gcc/powerpc-eabi/13.2.0/../../../../powerpc-eabi/bin/ld: cannot find -latomic: No such file or directory
collect2: error: ld returned 1 exit status

Code: Select all

root@c5b726e60829:/opt# find -L /opt -name 'libatomic.a' 
root@c5b726e60829:/opt# find -L /usr/ -name 'libatomic.a' 
/usr/lib/gcc/x86_64-linux-gnu/10/libatomic.a
Any help would be much appreciated.

Thanks.

WinterMute
Site Admin
Posts: 1859
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: libatomic support

Post by WinterMute » Sat Feb 24, 2024 6:47 pm

You don't need to add -latomic to use atomics.
Help keep devkitPro toolchains free, Donate today

Personal Blog

juvinious
Posts: 5
Joined: Thu Feb 22, 2024 4:55 pm

Re: libatomic support

Post by juvinious » Sat Feb 24, 2024 8:14 pm

Ok I see, yeah it seems to work with some caveats.
I think the issue is with my inclusion of uint64_t types and additional libs.

Without including any of the libs I need it seems to be fine. When I add the libraries I need to link with it has undefined references to __atomic_*_8.
Now that I know a little more, I guess I can play around with it and see which library is causing the problem. I'll follow back up.

Test code:

Code: Select all

#include <atomic>

int main()
{
        std::atomic<uint64_t> test;
        std::atomic<bool> test2;
        test.store(3);
        test+= 2;
        test-=1;
        if (test != 1){
        }
        test2 = false;
        test2.store(true);
        int value = test.load();
        bool value2 = test.load();

        // Not defined / deleted
        //std::atomic<uint64_t> test3 = test;

        return 0;
}
No libraries compiles fine:

Code: Select all

root@4f0d20892574:/build# /opt/devkitpro/devkitPPC/bin/powerpc-eabi-g++ main.cpp -std=c++11 -mrvl -mcpu=750 -meabi -mhard-float -ffunction-sections -fdata-sections -O2 -o main 
/opt/devkitpro/devkitPPC/bin/../lib/gcc/powerpc-eabi/13.2.0/../../../../powerpc-eabi/bin/ld: warning: cannot find entry symbol _start; defaulting to 80004024
/opt/devkitpro/devkitPPC/bin/../lib/gcc/powerpc-eabi/13.2.0/../../../../powerpc-eabi/bin/ld: main: warning: allocated section `.data' not in segment
With needed libraries missing symbols:

Code: Select all

/opt/devkitpro/devkitPPC/bin/powerpc-eabi-g++ main.cpp -o main -L/opt/devkitpro/wut/lib -L/opt/devkitpro/portlibs/gamecube/lib -L/opt/devkitpro/portlibs/ppc/lib -Wl,--as-needed -Wl,--no-undefined -static -static-libgcc -static-libstdc++ -Wl,--start-group /opt/devkitpro/portlibs/ppc/lib/libharfbuzz.a -lm /opt/devkitpro/portlibs/ppc/lib/libfreetype.a /opt/devkitpro/portlibs/ppc/lib/libbz2.a /opt/devkitpro/portlibs/ppc/lib/libpng16.a /opt/devkitpro/portlibs/ppc/lib/libz.a /opt/devkitpro/portlibs/ppc/lib/libjpeg.a /opt/devkitpro/portlibs/gamecube/lib/libSDL2main.a /opt/devkitpro/portlibs/gamecube/lib/libSDL2.a -mogc -mcpu=750 -meabi -mhard-float /opt/devkitpro/libogc/lib/cube/libaesnd.a /opt/devkitpro/libogc/lib/cube/libfat.a /opt/devkitpro/libogc/lib/cube/libogc.a /opt/devkitpro/portlibs/gamecube/lib/libSDL2_ttf.a -mogc -mcpu=750 -meabi -mhard-float /opt/devkitpro/portlibs/gamecube/lib/libSDL2_mixer.a /opt/devkitpro/portlibs/ppc/lib/libvorbisidec.a /opt/devkitpro/portlibs/ppc/lib/libmodplug.a /opt/devkitpro/devkitPPC/bin/../lib/gcc/powerpc-eabi/13.2.0/../../../../powerpc-eabi/lib/libstdc++.a /opt/devkitpro/portlibs/ppc/lib/libmpg123.a /opt/devkitpro/portlibs/ppc/lib/libopusfile.a /opt/devkitpro/portlibs/ppc/lib/libopus.a /opt/devkitpro/portlibs/ppc/lib/libFLAC.a /opt/devkitpro/portlibs/ppc/lib/libogg.a -mogc -mcpu=750 -meabi -mhard-float /opt/devkitpro/portlibs/gamecube/lib/libSDL2_gfx.a -mogc -mcpu=750 -meabi -mhard-float /opt/devkitpro/portlibs/ppc/lib/libvorbis.a /opt/devkitpro/portlibs/ppc/lib/libvorbisfile.a -Wl,--end-group -mogc -mcpu=750 -meabi -mhard-float -mogc -mcpu=750 -meabi -mhard-float -mogc -mcpu=750 -meabi -mhard-float -mogc -mcpu=750 -meabi -mhard-float -mogc -DGEKKO -mcpu=750 -meabi -mhard-float
/opt/devkitpro/devkitPPC/bin/../lib/gcc/powerpc-eabi/13.2.0/../../../../powerpc-eabi/bin/ld: /tmp/ccVXHedv.o: in function `main':
main.cpp:(.text.main+0x94): undefined reference to `__atomic_store_8'
/opt/devkitpro/devkitPPC/bin/../lib/gcc/powerpc-eabi/13.2.0/../../../../powerpc-eabi/bin/ld: main.cpp:(.text.main+0x150): undefined reference to `__atomic_load_8'
/opt/devkitpro/devkitPPC/bin/../lib/gcc/powerpc-eabi/13.2.0/../../../../powerpc-eabi/bin/ld: main.cpp:(.text.main+0x1b0): undefined reference to `__atomic_load_8'
/opt/devkitpro/devkitPPC/bin/../lib/gcc/powerpc-eabi/13.2.0/../../../../powerpc-eabi/bin/ld: /tmp/ccVXHedv.o: in function `_ZNSt13__atomic_baseIyEpLEy':
main.cpp:(.text._ZNSt13__atomic_baseIyEpLEy[_ZNSt13__atomic_baseIyEpLEy]+0x3c): undefined reference to `__atomic_fetch_add_8'
/opt/devkitpro/devkitPPC/bin/../lib/gcc/powerpc-eabi/13.2.0/../../../../powerpc-eabi/bin/ld: /tmp/ccVXHedv.o: in function `_ZNSt13__atomic_baseIyEmIEy':
main.cpp:(.text._ZNSt13__atomic_baseIyEmIEy[_ZNSt13__atomic_baseIyEmIEy]+0x3c): undefined reference to `__atomic_fetch_sub_8'
/opt/devkitpro/devkitPPC/bin/../lib/gcc/powerpc-eabi/13.2.0/../../../../powerpc-eabi/bin/ld: /tmp/ccVXHedv.o: in function `_ZNKSt13__atomic_baseIyEcvyEv':
main.cpp:(.text._ZNKSt13__atomic_baseIyEcvyEv[_ZNKSt13__atomic_baseIyEcvyEv]+0x6c): undefined reference to `__atomic_load_8'
collect2: error: ld returned 1 exit status

juvinious
Posts: 5
Joined: Thu Feb 22, 2024 4:55 pm

Re: libatomic support

Post by juvinious » Sat Feb 24, 2024 8:21 pm

Found the culprit, when building against libogc. I removed it and now it's happy.

Code: Select all

root@4f0d20892574:/build# /opt/devkitpro/devkitPPC/bin/powerpc-eabi-g++ main.cpp -o main -L/opt/devkitpro/wut/lib -L/opt/devkitpro/portlibs/gamecube/lib -L/opt/devkitpro/portlibs/ppc/lib -Wl,--as-needed -Wl,--no-undefined -static -static-libgcc -static-libstdc++ -Wl,--start-group /opt/devkitpro/portlibs/ppc/lib/libharfbuzz.a -lm /opt/devkitpro/portlibs/ppc/lib/libfreetype.a /opt/devkitpro/portlibs/ppc/lib/libbz2.a /opt/devkitpro/portlibs/ppc/lib/libpng16.a /opt/devkitpro/portlibs/ppc/lib/libz.a /opt/devkitpro/portlibs/ppc/lib/libjpeg.a /opt/devkitpro/portlibs/gamecube/lib/libSDL2main.a /opt/devkitpro/portlibs/gamecube/lib/libSDL2.a -mogc -mcpu=750 -meabi -mhard-float /opt/devkitpro/libogc/lib/cube/libaesnd.a /opt/devkitpro/libogc/lib/cube/libfat.a /opt/devkitpro/portlibs/gamecube/lib/libSDL2_ttf.a -mogc -mcpu=750 -meabi -mhard-float /opt/devkitpro/portlibs/gamecube/lib/libSDL2_mixer.a /opt/devkitpro/portlibs/ppc/lib/libvorbisidec.a /opt/devkitpro/portlibs/ppc/lib/libmodplug.a /opt/devkitpro/devkitPPC/bin/../lib/gcc/powerpc-eabi/13.2.0/../../../../powerpc-eabi/lib/libstdc++.a /opt/devkitpro/portlibs/ppc/lib/libmpg123.a /opt/devkitpro/portlibs/ppc/lib/libopusfile.a /opt/devkitpro/portlibs/ppc/lib/libopus.a /opt/devkitpro/portlibs/ppc/lib/libFLAC.a /opt/devkitpro/portlibs/ppc/lib/libogg.a -mogc -mcpu=750 -meabi -mhard-float /opt/devkitpro/portlibs/gamecube/lib/libSDL2_gfx.a -mogc -mcpu=750 -meabi -mhard-float /opt/devkitpro/portlibs/ppc/lib/libvorbis.a /opt/devkitpro/portlibs/ppc/lib/libvorbisfile.a -Wl,--end-group -mogc -mcpu=750 -meabi -mhard-float -mogc -mcpu=750 -meabi -mhard-float -mogc -mcpu=750 -meabi -mhard-float -mogc -mcpu=750 -meabi -mhard-float -mogc -DGEKKO -mcpu=750 -meabi -mhard-float
/opt/devkitpro/devkitPPC/bin/../lib/gcc/powerpc-eabi/13.2.0/../../../../powerpc-eabi/bin/ld: warning: cannot find entry symbol _start; defaulting to 80003124
root@4f0d20892574:/build# 


juvinious
Posts: 5
Joined: Thu Feb 22, 2024 4:55 pm

Re: libatomic support

Post by juvinious » Sat Feb 24, 2024 8:42 pm

Ok I might have jumped the gun on that one, it might be related to order and all the included flags. Let me continue to test I'll eventually figure it out.
Thanks for your help, much appreciated!

Code: Select all

root@4f0d20892574:/build# /opt/devkitpro/devkitPPC/bin/powerpc-eabi-g++ main.cpp -std=c++11 -mrvl -mcpu=750 -meabi -mhard-float -ffunction-sections -fdata-sections -O2 -o main  -L/opt/devkitpro/libogc/lib/cube/libogc.a
/opt/devkitpro/devkitPPC/bin/../lib/gcc/powerpc-eabi/13.2.0/../../../../powerpc-eabi/bin/ld: warning: cannot find entry symbol _start; defaulting to 80004024
/opt/devkitpro/devkitPPC/bin/../lib/gcc/powerpc-eabi/13.2.0/../../../../powerpc-eabi/bin/ld: main: warning: allocated section `.data' not in segment
root@4f0d20892574:/build# 

juvinious
Posts: 5
Joined: Thu Feb 22, 2024 4:55 pm

Re: libatomic support

Post by juvinious » Sun Feb 25, 2024 10:35 pm

So I'm still kind of stuck. I threw the config into the template:

Code: Select all

#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS    :=      -lharfbuzz -lm -lfreetype -lbz2 -lpng16 -lz -ljpeg -lSDL2main -lSDL2 -laesnd -lfat -logc -lm -lSDL2_ttf -lSDL2_mixer -lvorbisidec -lmodplug -lstdc++ -lmpg123 -lopusfile -lopus -lFLAC -logg -lSDL2_gfx -lvorbis -lvorbisfile

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS :=      /opt/devkitpro/portlibs/ppc /opt/devkitpro/portlibs/gamecube /opt/devkitpro/libogc/lib/cube

Last edited by juvinious on Sun Feb 25, 2024 10:35 pm, edited 1 time in total.

WinterMute
Site Admin
Posts: 1859
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: libatomic support

Post by WinterMute » Mon Feb 26, 2024 2:19 am

juvinious wrote: Sun Feb 25, 2024 10:35 pm So I'm still kind of stuck. I threw the config into the template:
OK. It seems that libatomic is needed for 64bit atomics on 32bit processors. I'm told this is probably going to be slow so it might be worth considering whether or not you really need this. It's not a request I've had before anyway so, afaik, it's not a common issue. I can look at enabling libatomic but that's never been tested so no guarantees.

Code: Select all

LIBS    :=      -lharfbuzz -lm -lfreetype -lbz2 -lpng16 -lz -ljpeg -lSDL2main -lSDL2 -laesnd -lfat -logc -lm -lSDL2_ttf -lSDL2_mixer -lvorbisidec -lmodplug -lstdc++ -lmpg123 -lopusfile -lopus -lFLAC -logg -lSDL2_gfx -lvorbis -lvorbisfile
This part can largely be replaced with this line I think which has the added bonus of dealing with link order. This is off the top of my head so I might be missing a lib. /opt/devkitpro/portlibs/gamecube/bin/powerpc-eabi-pkg-config --list-all will tell you what libs this will understand.

Code: Select all

LIBS    := `$(PREFIX)pkg-config --libs SDL2_gfx SDL2_mixer SDL2_ttf`
also add `$(PREFIX)pkg-config --cflags SDL2_gfx SDL2_mixer SDL2_ttf` to CFLAGS
[/code]
LIBDIRS := /opt/devkitpro/portlibs/ppc /opt/devkitpro/portlibs/gamecube /opt/devkitpro/libogc/lib/cube
[/code]
LIBDIRS can just be left blank or add $(PORTLIBS) although the pkg-config incantation should take care of the needed -L options.
Help keep devkitPro toolchains free, Donate today

Personal Blog

WinterMute
Site Admin
Posts: 1859
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: libatomic support

Post by WinterMute » Mon Feb 26, 2024 2:50 am

libatomic configury currently says no

Code: Select all

configure: error: Configuration powerpc-unknown-eabi is unsupported.
There are some other dependencies we need to satisfy that aren't straightforward unfortunately. It's unlikely we'll get back to looking at this soon, sorry.
Help keep devkitPro toolchains free, Donate today

Personal Blog

juvinious
Posts: 5
Joined: Thu Feb 22, 2024 4:55 pm

Re: libatomic support

Post by juvinious » Mon Feb 26, 2024 5:13 am

WinterMute wrote: Mon Feb 26, 2024 2:50 am libatomic configury currently says no

Code: Select all

configure: error: Configuration powerpc-unknown-eabi is unsupported.
There are some other dependencies we need to satisfy that aren't straightforward unfortunately. It's unlikely we'll get back to looking at this soon, sorry.
Ok no problem. I'll figure out a workaround for these targets.
I appreciate your help. Thanks.

Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests