OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: gcc -pthread option support
PostPosted: Mon Jun 07, 2021 8:40 am 
Offline

Joined: Sun Mar 17, 2019 9:34 am
Posts: 4
I'm trying to get a cross-compiler toolchain for my OS.
I'm using gcc and newlib.
I've implemented the required syscalls as well as pthread.
I can't get the -pthread option to be recognized by gcc though. I'm not sure if it's a ./configure issue or if my modding of the sources (following the OSDev Wiki) needs more work.

When I search about '-pthread' I get mostly what it does but not how to include it in the compiler.

I hope someone can point me in the right direction.

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: gcc -pthread option support
PostPosted: Mon Jun 07, 2021 3:16 pm 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 999
Do you have
Code:
thread_file='posix'

in your config.gcc?

_________________
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].


Top
 Profile  
 
 Post subject: Re: gcc -pthread option support
PostPosted: Mon Jun 07, 2021 6:46 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
Make sure to configure your cross-compiler with:
Code:
-enable-threads=posix


You might also have to configure newlib for your target. I needed to add the following to newlib/libc/include/sys/features.h:
Code:
#if defined(__rainbow__)
#define _POSIX_THREADS 1
#define _UNIX98_THREAD_MUTEX_ATTRIBUTES 1
#endif

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: gcc -pthread option support
PostPosted: Tue Jun 08, 2021 11:21 pm 
Offline

Joined: Sun Mar 17, 2019 9:34 am
Posts: 4
Korona wrote:
Do you have
Code:
thread_file='posix'

in your config.gcc?


kzinti wrote:
Make sure to configure your cross-compiler with:
Code:
-enable-threads=posix


You might also have to configure newlib for your target. I needed to add the following to newlib/libc/include/sys/features.h:
Code:
#if defined(__rainbow__)
#define _POSIX_THREADS 1
#define _UNIX98_THREAD_MUTEX_ATTRIBUTES 1
#endif


Thank you both. Now I only have to find out why I'm getting errors from gthr-default.h
Hopefully it's the last snag on that front.


Top
 Profile  
 
 Post subject: Re: gcc -pthread option support
PostPosted: Wed Jun 09, 2021 3:29 am 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 999
Passing the configuration option should not be necessary if the config is set up correctly.

_________________
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].


Top
 Profile  
 
 Post subject: Re: gcc -pthread option support
PostPosted: Wed Jun 09, 2021 8:38 am 
Offline

Joined: Sun Mar 17, 2019 9:34 am
Posts: 4
I've just finished the build.
Alas "gcc -pthread" prints:

gcc: error: unrecognized command-line option '-pthread'

However, "gcc -v" prints:

Configured with: /home/builder/Projects/experimental-cross/.build/armv6-rpi-experimental-eabihf/src/gcc/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu --target=armv6-rpi-experimental-eabihf --prefix=/home/builder/x-tools/armv6-rpi-experimental-eabihf --exec_prefix=/home/builder/x-tools/armv6-rpi-experimental-eabihf --with-sysroot=/home/builder/x-tools/armv6-rpi-experimental-eabihf/armv6-rpi-experimental-eabihf/sysroot --enable-languages=c,c++ --with-cpu=arm1176jzf-s --with-fpu=vfp --with-float=hard --disable-shared --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --disable-libmpx --with-gmp=/home/builder/Projects/experimental-cross/.build/armv6-rpi-experimental-eabihf/buildtools --with-mpfr=/home/builder/Projects/experimental-cross/.build/armv6-rpi-experimental-eabihf/buildtools --with-mpc=/home/builder/Projects/experimental-cross/.build/armv6-rpi-experimental-eabihf/buildtools --with-isl=/home/builder/Projects/experimental-cross/.build/armv6-rpi-experimental-eabihf/buildtools --enable-lto --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --enable-threads=posix --enable-target-optspace --disable-libstdcxx-pch --enable-linker-build-id --with-linker-hash-style=both --enable-plugin --enable-gold --disable-nls --disable-multilib --with-local-prefix=/home/builder/x-tools/armv6-rpi-experimental-eabihf/armv6-rpi-experimental-eabihf/sysroot --enable-long-long
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.3.0

edit: I believe I know what's wrong (I think I'm getting a better understanding of gcc's internals). I'll be able to test that in a few hours.


Top
 Profile  
 
 Post subject: Re: gcc -pthread option support
PostPosted: Fri Jun 11, 2021 8:01 am 
Offline

Joined: Sun Mar 17, 2019 9:34 am
Posts: 4
The last issue was a switch match in gcc/config.gcc that was hitting before my own ...
I've moved my more specific block above it and it finally worked.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 60 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