i2pd: PowerPC: i2pd fails with Bus error if built using GCC atomics
I have tried building i2pd for ppc on 10.6.8 with gcc11, and it failed on this:
[ 75%] Building CXX object CMakeFiles/libi2pd.dir/Users/svacchanda/i2pd/libi2pd/util.cpp.o
/Users/svacchanda/i2pd/libi2pd/util.cpp: In function ‘void i2p::util::SetThreadName(const char*)’:
/Users/svacchanda/i2pd/libi2pd/util.cpp:127:36: error: invalid conversion from const char*’ to ‘char*’ [-fpermissive]
127 | pthread_setname_np(name);
| ^~~~
| |
| const char*
In file included from /opt/svacchanda/gcc11ppc/include/c++/11.2.1/powerpc-apple-darwin10/bits/gthr-default.h:35,
from /opt/svacchanda/gcc11ppc/include/c++/11.2.1/powerpc-apple-darwin10/bits/gthr.h:148,
from /opt/svacchanda/gcc11ppc/include/c++/11.2.1/ext/atomicity.h:35,
from /opt/svacchanda/gcc11ppc/include/c++/11.2.1/bits/basic_string.h:39,
from /opt/svacchanda/gcc11ppc/include/c++/11.2.1/string:55,
from /Users/svacchanda/i2pd/libi2pd/util.cpp:10:
/Developer/SDKs/MacOSX10.6.sdk/usr/include/pthread.h:361:36: note: initializing argument 1 of ‘int pthread_setname_np(char*)’
361 | int pthread_setname_np(char*);
| ^~~~~
make[2]: *** [CMakeFiles/libi2pd.dir/Users/svacchanda/i2pd/libi2pd/util.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/libi2pd.dir/all] Error 2
make: *** [all] Error 2
I used this line to configure: cmake -DCMAKE_C_COMPILER=/opt/svacchanda/gcc11ppc/bin/gcc -DCMAKE_CXX_COMPILER=/opt/svacchanda/gcc11ppc/bin/g++ -DLLVM_DEFAULT_TARGET_TRIPLE=powerpc-apple-darwin10 -DBoost_INCLUDE_DIR=/opt/local/libexec/boost/1.76/include
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 143 (108 by maintainers)
Commits related to this issue
- disable thread naming for PowerPC (#1726) Signed-off-by: R4SAS <r4sas@i2pmail.org> — committed to PurpleI2P/i2pd by r4sas 2 years ago
- [cmake] Use std::atomic on PowerPC inside boost (#1726) Signed-off-by: R4SAS <r4sas@i2pmail.org> — committed to PurpleI2P/i2pd by r4sas 2 years ago
Thanks, this will help.
In that case adding of
-DBOOST_SP_USE_STD_ATOMICwon’t be problem at all.FindArch.cmakecan be used to do same check for__POWERPC__as it has been done forpthread_setname_npand setting of this define for PPC only.I used g++ initially, built it manually using old Xcode.
I don’t think these old threads have anything to do with the problem. It looks like the spinlock doesn’t work for some reason, but it’s hard to tell why. The first thing to do would probably be to run the Boost.SmartPtr tests, in particular these testing the spinlock:
https://github.com/boostorg/smart_ptr/blob/develop/test/spinlock_test.cpp https://github.com/boostorg/smart_ptr/blob/develop/test/spinlock_try_test.cpp https://github.com/boostorg/smart_ptr/blob/develop/test/spinlock_mt_test.cpp https://github.com/boostorg/smart_ptr/blob/develop/test/spinlock_pool_test.cpp https://github.com/boostorg/smart_ptr/blob/develop/test/spinlock_pool_mt_test.cpp
Defining the macro BOOST_SP_REPORT_IMPLEMENTATION before compiling any of these should print which spinlock implementation is being used; under a recent GCC it should be this one:
https://github.com/boostorg/smart_ptr/blob/develop/include/boost/smart_ptr/detail/spinlock_gcc_atomic.hpp
I don’t see anything that could be wrong about it specifically on PowerPC.
Definitely boost::atomic is wrong on PPC. Try to write some test example reproducing the problem. No, you can’t disable boost in i2pd, because it’s everywhere.
Most likely #0 0x000c2304 in boost::detail::spinlock::lock ()
comes from this line boost::atomic_store (&m_Addresses, addresses);
try to replace it by m_Addresses = addresses;
If it helps than it’s a boost’s issue
most folks reading this do not understand Russian 😉 … if possible, please use English
I think you have to remember that Rosetta (1) is not “10.6 PPC” it is a way to run 10.5 ppc exes on intel 10.6 (and 10.5) … so AFAICT it only supports the same interfaces as 10.5.
So I would say that the configuration should expect no pthread_threadid_np() on < 10.6 intel and <= 10.6 ppc.
FWIW, I did patch GDB-7.3.1 (upstream) to work at least on Darwin9 - but it seems that was before I was on github, so it has never been pushed anywhere …
… after GCC-12 branches, I’ll look into finding the patches and pushing them - although TBH the debug experience is still “poor at best” with GDB 7 and modern C++ (although it can help to build the dsymutil from the llvm-7.1.1 branch since that’s more stable with modern DWARF).
It is Yet Another Time Soaking Project to improve native debug on powerpc-darwin 😉
I personally tested only on 10.4 and 10.6. It’s possible that it doesn’t compile on 10.5. For your use case, try changing to
1070in that line or in the corresponding patch here:https://github.com/macports/macports-ports/blob/master/devel/gdb-apple/files/patch-gdb-availability.diff#L66
My work was merged into the
gdb-appleport. Works fine on Tiger but possible missing some newer C++ stuff.Edit: here’s the PR from last year: https://github.com/macports/macports-ports/pull/11690
Note that TenFourFox GDB is not based on GDB 7. Rather it’s based on GDB 6.3.50 Apple revision 768. The MacPorts
gdb-appleis based on GDB 6.3.50 Apple revision 1824. Enjoy.that symbol comes from libgcc{_s} - so maybe you do not have the right version of libgcc installed?
Cameron built gdb7 for PPC Tiger and put it here, so that can work
https://sourceforge.net/projects/tenfourfox/files/tools/
@evanmiller was working on gdb for PPC last year and got something going. I forget just now where he got to, or how to get it. Perhaps he’ll remind us if we ask.
I would suggest to use the GDB from Xcode - trying to build and install a new GDB for powerpc-darwin is creating a second set of problems to solve, it is likely to be a deep rabbit hole 😉
it is not a compiler bug, but the problem we have with 10.5’s dyld not dealing with two copies of libstdc++.dylib …
… I have a solution in mind - but not going to be available this weekend.
I would suggest you try using the boost Portgroup:
https://github.com/macports/macports-ports/blob/master/_resources/port1.0/group/boost-1.0.tcl
@barracuda156 – can you sort out how to fix that, and perhaps provide this nice fellow with a PR?
I suggest you consider using something like this:
but up to you!
The powerpc test will usually work by coincidence – but the way this is usually done is different.
The best way to do this is to test for the function during configure and use it if it exists, of course.
Barring that, compilers including gcc on Apple comes with preset compiler defines that are often used for this, for example:
That assumes that there has been no work done to provide that function on such systems, which may not be the case, but anyway is close enough for government work, as we say.
There are also fancier ways of testing and falling back, which have changed over the years and I won’t go into them here now.
I have already added commit to skip pthread naming when
__powerpc__defined (see https://github.com/PurpleI2P/i2pd/commit/73e572b66bd5b233dbbf15cadf3256a8bb98f733), because gcc can’t check OS version, and trying to get it using calls to system isn’t good idea.pthread_setname_np() is not available until 10.6.x where x might == 8 (I have only that to check). So you would need to find an alternative or omit the functionality for earlier OS versions. (nothing to do with the compiler here - although perhaps the configuration).
…