gcc -pthread option support

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
Hurricane
Posts: 4
Joined: Sun Mar 17, 2019 9:34 am

gcc -pthread option support

Post by Hurricane »

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.
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: gcc -pthread option support

Post by Korona »

Do you have

Code: Select all

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].
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: gcc -pthread option support

Post by kzinti »

Make sure to configure your cross-compiler with:

Code: Select all

-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: Select all

#if defined(__rainbow__)
#define _POSIX_THREADS 1
#define _UNIX98_THREAD_MUTEX_ATTRIBUTES 1
#endif
Hurricane
Posts: 4
Joined: Sun Mar 17, 2019 9:34 am

Re: gcc -pthread option support

Post by Hurricane »

Korona wrote:Do you have

Code: Select all

thread_file='posix'
in your config.gcc?
kzinti wrote:Make sure to configure your cross-compiler with:

Code: Select all

-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: Select all

#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.
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: gcc -pthread option support

Post by Korona »

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].
Hurricane
Posts: 4
Joined: Sun Mar 17, 2019 9:34 am

Re: gcc -pthread option support

Post by Hurricane »

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.
Hurricane
Posts: 4
Joined: Sun Mar 17, 2019 9:34 am

Re: gcc -pthread option support

Post by Hurricane »

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.
Post Reply