Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerPC: i2pd fails with Bus error if built using GCC atomics #1726

Open
barracuda156 opened this issue Feb 10, 2022 · 143 comments
Open

PowerPC: i2pd fails with Bus error if built using GCC atomics #1726

barracuda156 opened this issue Feb 10, 2022 · 143 comments

Comments

@barracuda156
Copy link
Contributor

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

@r4sas
Copy link
Member

r4sas commented Feb 10, 2022

Do you know any defines, which compilator adds when building with OSX SDK? I've tested build with Homebrew and never seen such error here.

@barracuda156
Copy link
Contributor Author

Do you know any defines, which compilator adds when building with OSX SDK? I've tested build with Homebrew and never seen such error here.

Which compiler has you used? If it is some version of gcc, I can try that.

P. S. I will update soon on what happens on 10.5.8 and 10.6 PPC. Currently running some other stuff, need to wait until it builds.

@r4sas
Copy link
Member

r4sas commented Feb 10, 2022

Homebrew using same gcc, but I don't know which version now. I'll try to run my VM with it (I don't have any real Mac here ;D) and try to check

@r4sas
Copy link
Member

r4sas commented Feb 10, 2022

Try latest commit.

@barracuda156
Copy link
Contributor Author

@r4sas I tried to build on 10.5.8 now with gcc11, and it still fails on:

/Users/svacchanda/Dev/i2pd/libi2pd/util.cpp: In function ‘void i2p::util::SetThreadName(const char*)’:
/Users/svacchanda/Dev/i2pd/libi2pd/util.cpp:127:17: error: ‘pthread_setname_np’ was not declared in this scope; did you mean ‘pthread_setugid_np’?
  127 |                 pthread_setname_np((char*)name);
      |                 ^~~~~~~~~~~~~~~~~~
      |                 pthread_setugid_np
make[2]: *** [CMakeFiles/libi2pd.dir/Users/svacchanda/Dev/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

gcc11:

36-47:~ svacchanda$ /opt/svacchanda/gcc11/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/opt/svacchanda/gcc11/bin/g++
COLLECT_LTO_WRAPPER=/opt/svacchanda/gcc11/libexec/gcc/powerpc-apple-darwin9/11.2.1/lto-wrapper
Target: powerpc-apple-darwin9
Configured with: ../configure --prefix=/opt/svacchanda/gcc11 --build=powerpc-apple-darwin9 --with-as=/usr/bin/as --with-ld=/usr/bin/ld --enable-languages=all CC=/opt/iains/powerpc-apple-darwin9/gcc-10-3-ppc/bin/gcc CXX=/opt/iains/powerpc-apple-darwin9/gcc-10-3-ppc/bin/g++
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.1 20211013 (GCC)

I will with other compiler, but gcc11 should have been fine, it's the latest one.

@barracuda156
Copy link
Contributor Author

@r4sas Ok, so it fails with stock macports-gcc-7 too, which is thoroughly tested and 100% works (I have just built boost176 with it).

So I cloned current i2pd repo, then:

36-47:~ svacchanda$ cd /Users/svacchanda/Dev/i2pd\ copy\ 2/build 
36-47:build svacchanda$ cmake -DCMAKE_C_COMPILER=/opt/local/bin/gcc-mp-7 -DCMAKE_CXX_COMPILER=/opt/local/bin/g++-mp-7 -DBoost_INCLUDE_DIR=/opt/local/libexec/boost/1.76/include
CMake Warning:
  No source or binary directory provided.  Both will be assumed to be the
  same as the current working directory, but note that this warning will
  become a fatal error in future CMake releases.


-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/local/bin/gcc-mp-7 - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/local/bin/g++-mp-7 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CXX17_SUPPORTED
-- Performing Test CXX17_SUPPORTED - Success
-- Performing Test CXX11_SUPPORTED
-- Performing Test CXX11_SUPPORTED - Success
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Found Boost: /opt/local/libexec/boost/1.76/include (found version "1.76.0") found components: system filesystem program_options date_time 
-- Found OpenSSL: /opt/local/libexec/openssl3/lib/libcrypto.dylib (found version "3.0.1")  
-- Found ZLIB: /opt/local/lib/libz.dylib (found version "1.2.11") 
-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB
-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB - Failed
-- Looking for __atomic_load_8 in atomic
-- Looking for __atomic_load_8 in atomic - found
-- Performing Test HAVE_CXX_ATOMICS64_WITH_LIB
-- Performing Test HAVE_CXX_ATOMICS64_WITH_LIB - Success
-- Performing Test LLVM_HAS_ATOMICS
-- Performing Test LLVM_HAS_ATOMICS - Success
-- ---------------------------------------
-- Build type         : 
-- Compiler vendor    : GNU
-- Compiler version   : 7.5.0
-- Compiler path      : /opt/local/bin/g++-mp-7
-- Architecture       : unknown
-- Install prefix:    : /usr/local
-- Options:
--   AESNI            : ON
--   HARDENING        : OFF
--   LIBRARY          : ON
--   BINARY           : ON
--   STATIC BUILD     : OFF
--   UPnP             : OFF
--   PCH              : OFF
--   MESHNET          : OFF
--   ADDRSANITIZER    : OFF
--   THREADSANITIZER  : OFF
-- ---------------------------------------
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/svacchanda/Dev/i2pd copy 2/build
36-47:build svacchanda$ make -j 4 > b.txt 2>e.txt

Same failure:

/Users/svacchanda/Dev/i2pd copy 2/libi2pd/util.cpp: In function 'void i2p::util::SetThreadName(const char*)':
/Users/svacchanda/Dev/i2pd copy 2/libi2pd/util.cpp:127:3: error: 'pthread_setname_np' was not declared in this scope
   pthread_setname_np((char*)name);
   ^~~~~~~~~~~~~~~~~~
/Users/svacchanda/Dev/i2pd copy 2/libi2pd/util.cpp:127:3: note: suggested alternative: 'pthread_setugid_np'
   pthread_setname_np((char*)name);
   ^~~~~~~~~~~~~~~~~~
   pthread_setugid_np
make[2]: *** [CMakeFiles/libi2pd.dir/Users/svacchanda/Dev/i2pd_copy_2/libi2pd/util.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/libi2pd.dir/all] Error 2
make: *** [all] Error 2

@barracuda156
Copy link
Contributor Author

Here is the complete log (10.5.8, Macports gcc7):

e.txt
b.txt

@r4sas
Copy link
Member

r4sas commented Feb 11, 2022

That's why I'm asking you about determining in code that we use MacPorts GCC with custom pthreads which not supports pthread_setname_np. At least on MacOSX10.6.sdk it must work now.

Maybe check header file pthread.h?

@r4sas
Copy link
Member

r4sas commented Feb 11, 2022

@barracuda156 can you test by changing check here:

#if defined(__APPLE__)

to
#if defined(__APPLE__) && defined(CONFIG_PTHREAD_SETNAME_NP_W_TID) ?

@barracuda156
Copy link
Contributor Author

That's why I'm asking you about determining in code that we use MacPorts GCC with custom pthreads which not supports pthread_setname_np. At least on MacOSX10.6.sdk it must work now.
Maybe check header file pthread.h?

Please excuse me, I didn’t know how to check that specifically. But I tried with non-Macports compilers initially (gcc11 does not build for ppc in Macports) and only then with Macports version of gcc7.
It appears that Mac OS has some specifics with implementation of pthreads: https://help.autodesk.com/view/MAYAUL/2016/ENU/?guid=__files_GUID_EE052898_C59C_438A_9A77_798F5BEB7A77_htm

@barracuda156
Copy link
Contributor Author

@r4sas I have tried building with gcc10 after making suggested change:

Last login: Fri Feb 11 12:01:59 on ttys000
36-47:~ svacchanda$ export CC=/opt/iains/powerpc-apple-darwin9/gcc-10-3-ppc/bin/gcc
36-47:~ svacchanda$ export CXX=/opt/iains/powerpc-apple-darwin9/gcc-10-3-ppc/bin/g++
36-47:~ svacchanda$ export CFLAGS="-arch ppc -m32"
36-47:~ svacchanda$ export CXXFLAGS="-arch ppc -m32"
36-47:~ svacchanda$ cd /Users/svacchanda/Dev/i2pd\ copy\ 2/build 
36-47:build svacchanda$ cmake -DCMAKE_C_COMPILER=/opt/iains/powerpc-apple-darwin9/gcc-10-3-ppc/bin/gcc -DCMAKE_CXX_COMPILER=/opt/iains/powerpc-apple-darwin9/gcc-10-3-ppc/bin/g++ -DCMAKE_SYSTEM_PROCESSOR="ppc" -DBoost_INCLUDE_DIR=/opt/local/libexec/boost/1.76/include
CMake Warning:
  No source or binary directory provided.  Both will be assumed to be the
  same as the current working directory, but note that this warning will
  become a fatal error in future CMake releases.


-- The C compiler identification is GNU 10.3.0
-- The CXX compiler identification is GNU 10.3.0
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/iains/powerpc-apple-darwin9/gcc-10-3-ppc/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/iains/powerpc-apple-darwin9/gcc-10-3-ppc/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CXX17_SUPPORTED
-- Performing Test CXX17_SUPPORTED - Success
-- Performing Test CXX11_SUPPORTED
-- Performing Test CXX11_SUPPORTED - Success
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Found Boost: /opt/local/libexec/boost/1.76/include (found version "1.76.0") found components: system filesystem program_options date_time 
-- Found OpenSSL: /opt/local/libexec/openssl3/lib/libcrypto.dylib (found version "3.0.1")  
-- Found ZLIB: /opt/local/lib/libz.dylib (found version "1.2.11") 
-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB
-- Performing Test HAVE_CXX_ATOMICS64_WITHOUT_LIB - Failed
-- Looking for __atomic_load_8 in atomic
-- Looking for __atomic_load_8 in atomic - found
-- Performing Test HAVE_CXX_ATOMICS64_WITH_LIB
-- Performing Test HAVE_CXX_ATOMICS64_WITH_LIB - Success
-- Performing Test LLVM_HAS_ATOMICS
-- Performing Test LLVM_HAS_ATOMICS - Success
-- ---------------------------------------
-- Build type         : 
-- Compiler vendor    : GNU
-- Compiler version   : 10.3.0
-- Compiler path      : /opt/iains/powerpc-apple-darwin9/gcc-10-3-ppc/bin/g++
-- Architecture       : unknown
-- Install prefix:    : /usr/local
-- Options:
--   AESNI            : ON
--   HARDENING        : OFF
--   LIBRARY          : ON
--   BINARY           : ON
--   STATIC BUILD     : OFF
--   UPnP             : OFF
--   PCH              : OFF
--   MESHNET          : OFF
--   ADDRSANITIZER    : OFF
--   THREADSANITIZER  : OFF
-- ---------------------------------------
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/svacchanda/Dev/i2pd copy 2/build
36-47:build svacchanda$ make -j 4 >b.txt 2>e.txt

Unfortunately, no change:

/Users/svacchanda/Dev/i2pd copy 2/libi2pd/util.cpp: In function ‘void i2p::util::SetThreadName(const char*)’:
/Users/svacchanda/Dev/i2pd copy 2/libi2pd/util.cpp:133:3: error: ‘pthread_setname_np’ was not declared in this scope; did you mean ‘pthread_setugid_np’?
  133 |   pthread_setname_np(pthread_self(), name);
      |   ^~~~~~~~~~~~~~~~~~
      |   pthread_setugid_np
make[2]: *** [CMakeFiles/libi2pd.dir/Users/svacchanda/Dev/i2pd_copy_2/libi2pd/util.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/libi2pd.dir/all] Error 2
make: *** [all] Error 2

@r4sas
Copy link
Member

r4sas commented Feb 11, 2022

Can you find pthread.h header and send it here?

@r4sas
Copy link
Member

r4sas commented Feb 11, 2022

Currently trying to test with cmake -DCMAKE_C_COMPILER=/opt/local/bin/gcc-mp-11 -DCMAKE_CXX_COMPILER=/opt/local/bin/g++-mp-11 -DBOOST_ROOT=/opt/local/libexec/boost/1.76 -DBoost_NO_SYSTEM_PATHS=TRUE -DZLIB_ROOT=/opt/local -Wno-dev .

add: failing to link binary... idk why, but boost can't find some symbols.

add2: that's why I hate cmake:
/opt/local/bin/g++-mp-11 -Wall -Wextra -Winvalid-pch -Wno-unused-parameter -std=c++17 -pipe -fPIC -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk -mmacosx-version-min=11.4 -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/i2pd.dir/Users/r4sas/dev/i2pd/daemon/Daemon.cpp.o CMakeFiles/i2pd.dir/Users/r4sas/dev/i2pd/daemon/HTTPServer.cpp.o CMakeFiles/i2pd.dir/Users/r4sas/dev/i2pd/daemon/I2PControl.cpp.o CMakeFiles/i2pd.dir/Users/r4sas/dev/i2pd/daemon/i2pd.cpp.o CMakeFiles/i2pd.dir/Users/r4sas/dev/i2pd/daemon/UPnP.cpp.o CMakeFiles/i2pd.dir/Users/r4sas/dev/i2pd/daemon/UnixDaemon.cpp.o -o i2pd -L/opt/local/lib -Wl,-rpath,/opt/local/lib libi2pd.a libi2pdclient.a libi2pdlang.a /opt/local/libexec/boost/1.76/lib/libboost_system-mt.dylib /opt/local/libexec/boost/1.76/lib/libboost_filesystem-mt.dylib /opt/local/libexec/boost/1.76/lib/libboost_program_options-mt.dylib /opt/local/libexec/boost/1.76/lib/libboost_date_time-mt.dylib /opt/local/libexec/openssl11/lib/libssl.dylib /opt/local/libexec/openssl11/lib/libcrypto.dylib /opt/local/lib/libz.dylib libi2pd.a /opt/local/libexec/boost/1.76/lib/libboost_system-mt.dylib /opt/local/libexec/boost/1.76/lib/libboost_filesystem-mt.dylib /opt/local/libexec/boost/1.76/lib/libboost_program_options-mt.dylib /opt/local/libexec/boost/1.76/lib/libboost_date_time-mt.dylib /opt/local/lib/libz.dylib
It is linking libi2pd.a twice.

add3: I'm able to build binary only with clang.

@barracuda156
Copy link
Contributor Author

barracuda156 commented Feb 11, 2022

@r4sas Cmake is a disaster, I agree.

Do you have an idea how we can fix it to build with some version of gcc? Clang is broken for ppc.

P. S. I just got Boost 1.78 built. Though it probably won't solve the problem.

36-47% port -v installed boost178
The following ports are currently installed:
  boost178 @1.78.0_1+no_single+no_static+python310 (active) requested_variants='' platform='darwin 10' archs='ppc' date='2022-02-11T16:59:21+0800'

P. P. S. If it does not build due to compiler bug, I can open Bugzilla ticket for gcc.

@barracuda156
Copy link
Contributor Author

Can you find pthread.h header and send it here?

Yes, sure.
Archive.zip

@r4sas
Copy link
Member

r4sas commented Feb 11, 2022

Hm. 10.6 header has option, using same type as we used (const char*), but why compiler tells that "char*" is needed - idk. Maybe wrong header? Difference with 10.5.8 only in 2 lines, where pthread_setname_np is not exists.

Let's do it other way, just remove calling for __powerpc__. I'll push commit.

r4sas added a commit that referenced this issue Feb 11, 2022
@barracuda156
Copy link
Contributor Author

@r4sas Thank you! Now files are built with a single warning:

ranlib: file: libi2pd.a(I2PEndian.cpp.o) has no symbols
/usr/bin/ranlib: file: libi2pd.a(I2PEndian.cpp.o) has no symbols

However linking stage fails:

[100%] Linking CXX executable i2pd
ld warning: duplicate dylib /opt/local/libexec/boost/1.76/lib/libboost_system-mt.dylib
ld warning: duplicate dylib /opt/local/libexec/boost/1.76/lib/libboost_filesystem-mt.dylib
ld warning: duplicate dylib /opt/local/libexec/boost/1.76/lib/libboost_program_options-mt.dylib
ld warning: duplicate dylib /opt/local/libexec/boost/1.76/lib/libboost_date_time-mt.dylib
Undefined symbols:
  "__ZN5boost15program_options11to_internalERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", referenced from:
      __ZN5boost15program_options11to_internalINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEESt6vectorIS7_SaIS7_EERKS8_IT_SaISB_EE in libi2pd.a(Config.cpp.o)
  "__ZN5boost15program_options22error_with_option_nameC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES9_S9_i", referenced from:
      __ZN5boost15program_options16validation_errorC1ENS1_6kind_tERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_i in libi2pd.a(Config.cpp.o)
  "__ZN5boost15program_options6detail7cmdlineC2ERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EE", referenced from:
      __ZN5boost15program_options25basic_command_line_parserIcEC1EiPKPKc in libi2pd.a(Config.cpp.o)
  "__ZN5boost15program_options19options_descriptionC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEjj", referenced from:
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
      __ZN3i2p6config4InitEv in libi2pd.a(Config.cpp.o)
  "__ZN5boost15program_options8validateERNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EEPS9_i", referenced from:
      __ZNK5boost15program_options11typed_valueINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcE6xparseERNS_3anyERKSt6vectorIS7_SaIS7_EE in libi2pd.a(Config.cpp.o)
  "__ZNK5boost15program_options22abstract_variables_mapixERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", referenced from:
      __ZNK5boost15program_options13variables_mapixERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in Daemon.cpp.o
      __ZNK5boost15program_options13variables_mapixERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in HTTPServer.cpp.o
      __ZNK5boost15program_options13variables_mapixERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in I2PControl.cpp.o
      __ZNK5boost15program_options13variables_mapixERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in UnixDaemon.cpp.o
      __ZNK5boost15program_options13variables_mapixERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in libi2pd.a(Config.cpp.o)
      __ZNK5boost15program_options13variables_mapixERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in libi2pd.a(Transports.cpp.o)
      __ZNK5boost15program_options13variables_mapixERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in libi2pd.a(NetDb.cpp.o)
      __ZNK5boost15program_options13variables_mapixERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in libi2pd.a(RouterContext.cpp.o)
      __ZNK5boost15program_options13variables_mapixERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in libi2pd.a(Destination.cpp.o)
      __ZNK5boost15program_options13variables_mapixERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in libi2pd.a(Tunnel.cpp.o)
      __ZNK5boost15program_options13variables_mapixERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in libi2pdclient.a(ClientContext.cpp.o)
      __ZNK5boost15program_options13variables_mapixERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in libi2pd.a(Timestamp.cpp.o)
      __ZNK5boost15program_options13variables_mapixERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in libi2pdclient.a(AddressBook.cpp.o)
      __ZNK5boost15program_options13variables_mapixERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in libi2pd.a(SSU.cpp.o)
      __ZNK5boost15program_options13variables_mapixERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in libi2pd.a(Reseed.cpp.o)
  "__ZN5boost15program_options8validateERNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EEPbi", referenced from:
      __ZNK5boost15program_options11typed_valueIbcE6xparseERNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EE in libi2pd.a(Config.cpp.o)
  "__ZNK5boost15program_options22error_with_option_name23substitute_placeholdersERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", referenced from:
      __ZTVN5boost15program_options20invalid_option_valueE in libi2pd.a(Config.cpp.o)
      __ZTVN5boost15program_options16validation_errorE in libi2pd.a(Config.cpp.o)
      __ZTVN5boost10wrapexceptINS_15program_options16validation_errorEEE in libi2pd.a(Config.cpp.o)
      __ZTVN5boost10wrapexceptINS_15program_options20invalid_option_valueEEE in libi2pd.a(Config.cpp.o)
  "__ZN5boost15program_options20invalid_option_valueC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", referenced from:
      __ZN5boost15program_options8validateIjcEEvRNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIT0_St11char_traitsIS7_ESaIS7_EEESaISB_EEPT_l in libi2pd.a(Config.cpp.o)
      __ZN5boost15program_options8validateIicEEvRNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIT0_St11char_traitsIS7_ESaIS7_EEESaISB_EEPT_l in libi2pd.a(Config.cpp.o)
      __ZN5boost15program_options8validateItcEEvRNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIT0_St11char_traitsIS7_ESaIS7_EEESaISB_EEPT_l in libi2pd.a(Config.cpp.o)
  "__ZN5boost15program_options16validation_error12get_templateB5cxx11ENS1_6kind_tE", referenced from:
      __ZN5boost15program_options16validation_errorC1ENS1_6kind_tERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_i in libi2pd.a(Config.cpp.o)
  "__ZN5boost15program_options6detail7cmdline21set_additional_parserENS_9function1ISt4pairINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_ERKSA_EE", referenced from:
      __ZN5boost15program_options25basic_command_line_parserIcE12extra_parserENS_9function1ISt4pairINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_ERKSA_EE in libi2pd.a(Config.cpp.o)
  "__ZN5boost15program_options3argB5cxx11E", referenced from:
      __ZN5boost15program_options3argB5cxx11E$non_lazy_ptr in libi2pd.a(Config.cpp.o)
  "__ZNK5boost15program_options29value_semantic_codecvt_helperIcE5parseERNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EEb", referenced from:
      __ZTVN5boost15program_options11typed_valueIjcEE in libi2pd.a(Config.cpp.o)
      __ZTVN5boost15program_options11typed_valueIicEE in libi2pd.a(Config.cpp.o)
      __ZTVN5boost15program_options11typed_valueItcEE in libi2pd.a(Config.cpp.o)
      __ZTVN5boost15program_options11typed_valueIbcEE in libi2pd.a(Config.cpp.o)
      __ZTVN5boost15program_options11typed_valueINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEE in libi2pd.a(Config.cpp.o)
ld: symbol(s) not found
collect2: error: ld returned 1 exit status
make[2]: *** [i2pd] Error 1
make[1]: *** [CMakeFiles/i2pd.dir/all] Error 2
make: *** [all] Error 2

@barracuda156
Copy link
Contributor Author

@r4sas Above was on 10.6 PPC (10A190).

On a stock 10.5.8 however the build fails as before with:

/Users/svacchanda/i2pd/libi2pd/util.cpp: In function ‘void i2p::util::SetThreadName(const char*)’:
/Users/svacchanda/i2pd/libi2pd/util.cpp:127:17: error: ‘pthread_setname_np’ was not declared in this scope; did you mean ‘pthread_setugid_np’?
  127 |                 pthread_setname_np((char*)name);
      |                 ^~~~~~~~~~~~~~~~~~
      |                 pthread_setugid_np
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

In either case gcc11 was used and Boost 1.76.

@r4sas
Copy link
Member

r4sas commented Feb 13, 2022

I found how to get all predefined macros: https://stackoverflow.com/a/10905013.
Let's see what returns 10.5.8,

@r4sas
Copy link
Member

r4sas commented Feb 13, 2022

@r4sas Thank you! Now files are built with a single warning:

That's not problem, because code generated only when required

However linking stage fails:

Same for me with gcc. I really don't know why, but looks like libraries built by clang in latest versions, because only with it I built i2pd succesfully.

@barracuda156
Copy link
Contributor Author

@r4sas Interesting. Firstly, this seems to be a rather unique case when building something has more success on 10.6 PPC (which is a developer build lacking many features of 10.6 release and therefore it may be tricky to build stuff for it) than on a vanilla 10.5.8 which has been tested and polished. Unless I am doing something wrong.

Secondly, unclear why the latest gcc11 fails here. Do you think it is a compiler fault or what?
The difficulty is that I cannot really file any bugzilla reports for 10.6 PPC (well, technically I may, but no one will test it). If we find a way to reach same linking stage errors on 10.5.8, I will try asking gcc developers what's going on.

@r4sas
Copy link
Member

r4sas commented Feb 13, 2022

No, there is no linking problem, there is library itself diffirence, because you trying to link clang built libraries with applicaton built by gcc and using gcc linker.
So solution can be in rebuilding libraries from scratch with gcc and using them for linking with app.

@barracuda156
Copy link
Contributor Author

No, there is no linking problem, there is library itself diffirence, because you trying to link clang built libraries with applicaton built by gcc and using gcc linker.

So solution can be in rebuilding libraries from scratch with gcc and using them for linking with app.

I have no libraries built with Clang. Everything that is not a part of OS itself is built with gcc.

@r4sas
Copy link
Member

r4sas commented Feb 14, 2022

I have no libraries built with Clang. Everything that is not a part of OS itself is built with gcc.

Are they built with gcc?

ld warning: duplicate dylib /opt/local/libexec/boost/1.76/lib/libboost_system-mt.dylib

That prefix used by macports as I know.

@r4sas
Copy link
Member

r4sas commented Feb 14, 2022

@herbygillot, can you say to us, is libraries provided by macports are built with clang?

@barracuda156
Copy link
Contributor Author

@herbygillot, can you say to us, is libraries provided by macports are built with clang?

clang is broken for PowerPC. Everything that is currently built with Macports on PowerPC systems is built with gcc. At the moment macports-gcc-7 is the default version on 10.5.8 (and on 10.6 PPC, though the latter one is unofficial).

@barracuda156
Copy link
Contributor Author

@r4sas So yes, boost is built with gcc7 for PowerPC.

It does't show in port -v installed:

36-47:~ svacchanda$ port -v installed boost176
The following ports are currently installed:
  boost176 @1.76.0_3+no_single+no_static+python310 (active) requested_variants='-universal' platform='darwin 9' archs='ppc' date='2022-02-11T07:22:32+0800'

But trust me, it's the case. Anyone on Macports can confirm that.

I don't even have clang installed. @kencu has been able to get clang-5.0 installed on PowerPC, but it produced broken code.
https://trac.macports.org/ticket/53184

36-47:~ svacchanda$ port -v installed | grep clang
  clang_select @2.2_0 (active) requested_variants='' platform='darwin 9' archs='ppc ppc64' date='2022-01-18T18:52:49+0800'
36-47:~ svacchanda$ port -v installed | grep gcc
  floppy @7.0_0+gcc7 (active) requested_variants='' platform='darwin 9' archs='ppc' date='2022-01-31T19:22:03+0800'
  ftidy @7.2_2+gcc7 (active) requested_variants='' platform='darwin 9' archs='ppc' date='2022-01-31T18:26:52+0800'
  gcc6 @6.5.0_6+universal requested_variants='+universal' platform='darwin 9' archs='ppc ppc64' date='2021-12-25T01:25:21+0800'
  gcc6 @6.5.0_7+universal (active) requested_variants='+universal' platform='darwin 9' archs='ppc ppc64' date='2022-01-03T00:20:22+0800'
  gcc7 @7.5.0_2+universal requested_variants='+universal' platform='darwin 9' archs='ppc ppc64' date='2021-12-22T07:30:13+0800'
  gcc7 @7.5.0_3+universal (active) requested_variants='+universal' platform='darwin 9' archs='ppc ppc64' date='2022-01-04T17:43:56+0800'
  gcc10 @10.3.0_1+universal (active) requested_variants='+universal' platform='darwin 9' archs='ppc ppc64' date='2022-02-03T01:56:41+0800'
  gcc_select @0.1_9 (active) requested_variants='' platform='darwin 9' archs='noarch' date='2021-12-21T10:29:35+0800'
  libgcc @5.0_0+universal (active) requested_variants='+universal' platform='darwin 9' archs='ppc ppc64' date='2022-02-03T04:24:12+0800'
  libgcc6 @6.5.0_4+universal (active) requested_variants='+universal' platform='darwin 9' archs='ppc ppc64' date='2021-12-22T21:21:01+0800'
  libgcc7 @7.5.0_1+universal (active) requested_variants='+universal' platform='darwin 9' archs='ppc ppc64' date='2021-12-22T03:49:53+0800'
  libgcc10 @10.3.0_2+universal (active) requested_variants='+universal' platform='darwin 9' archs='ppc ppc64' date='2022-02-03T04:30:07+0800'
  libxc4 @4.3.4_0+gcc7 (active) requested_variants='' platform='darwin 9' archs='ppc' date='2022-01-31T18:06:30+0800'
  mpich-gcc10 @3.4.2_0 requested_variants='-universal' platform='darwin 9' archs='ppc' date='2022-02-03T03:40:23+0800'
  mpich-gcc10 @3.4.2_0+fortran (active) requested_variants='+fortran-universal' platform='darwin 9' archs='ppc' date='2022-02-03T05:44:13+0800'
  pgplot @5.2.2_13+gcc7+x11 (active) requested_variants='' platform='darwin 9' archs='ppc' date='2022-02-03T02:30:32+0800'
  slatec @4.1_2+gcc7 (active) requested_variants='' platform='darwin 9' archs='ppc' date='2022-01-31T18:35:37+0800'

@r4sas
Copy link
Member

r4sas commented Feb 14, 2022

Hm... In that case I can't say anything. Can you try rebuild boost locally?

@barracuda156
Copy link
Contributor Author

barracuda156 commented Nov 7, 2022

@pdimov So yeah, we have a broken Boost on PPC. Every binary compiled fails with Bus error and EXC_BAD_ACCESS.

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 259 at address: 0x00003109
0x000023fc in boost::detail::spinlock::try_lock ()
(gdb) where
#0  0x000023fc in boost::detail::spinlock::try_lock ()
#1  0x00001fd8 in main ()

It appears that something is fundamentally broken (not with one module). A fibonacci test for context fails with Bus error too.

Where to look? We definitely want this fixed.

@barracuda156
Copy link
Contributor Author

barracuda156 commented Nov 7, 2022

@pdimov Out of those tests 1 passes (spinlock_mt_test), all the rest fail with Bus error:

sergey-fedorovs-power-mac-g5:boost svacchanda$ /opt/local/bin/g++-mp-11 spinlock_test.cpp -I/opt/local/libexec/boost/1.76/include -L/opt/local/libexec/boost/1.76/lib -o spinlock_test
sergey-fedorovs-power-mac-g5:boost svacchanda$ /opt/local/bin/g++-mp-11 spinlock_try_test.cpp -I/opt/local/libexec/boost/1.76/include -L/opt/local/libexec/boost/1.76/lib -o spinlock_try_test
sergey-fedorovs-power-mac-g5:boost svacchanda$ /opt/local/bin/g++-mp-11 spinlock_mt_test.cpp -I/opt/local/libexec/boost/1.76/include -L/opt/local/libexec/boost/1.76/lib -o spinlock_mt_test
sergey-fedorovs-power-mac-g5:boost svacchanda$ /opt/local/bin/g++-mp-11 spinlock_pool_test.cpp -I/opt/local/libexec/boost/1.76/include -L/opt/local/libexec/boost/1.76/lib -o spinlock_pool_test
sergey-fedorovs-power-mac-g5:boost svacchanda$ /opt/local/bin/g++-mp-11 spinlock_pool_mt_test.cpp -I/opt/local/libexec/boost/1.76/include -L/opt/local/libexec/boost/1.76/lib -o spinlock_pool_mt_test
sergey-fedorovs-power-mac-g5:boost svacchanda$ ./spinlock_test
Bus error
sergey-fedorovs-power-mac-g5:boost svacchanda$ ./spinlock_try_test
Bus error
sergey-fedorovs-power-mac-g5:boost svacchanda$ ./spinlock_mt_test
No errors detected.
sergey-fedorovs-power-mac-g5:boost svacchanda$ ./spinlock_pool_test
Bus error
sergey-fedorovs-power-mac-g5:boost svacchanda$ ./spinlock_pool_mt_test
Bus error

Implementation used looks correct:

sergey-fedorovs-power-mac-g5:boost svacchanda$ /opt/local/bin/g++-mp-11 -DBOOST_SP_REPORT_IMPLEMENTATION spinlock_mt_test.cpp -I/opt/local/libexec/boost/1.76/include -L/opt/local/libexec/boost/1.76/lib -o spinlock_mt_test2
In file included from /opt/local/libexec/boost/1.76/include/boost/smart_ptr/detail/sp_thread_sleep.hpp:22,
                 from /opt/local/libexec/boost/1.76/include/boost/smart_ptr/detail/yield_k.hpp:23,
                 from /opt/local/libexec/boost/1.76/include/boost/smart_ptr/detail/spinlock_gcc_atomic.hpp:14,
                 from /opt/local/libexec/boost/1.76/include/boost/smart_ptr/detail/spinlock.hpp:42,
                 from spinlock_mt_test.cpp:5:
/opt/local/libexec/boost/1.76/include/boost/config/pragma_message.hpp:24:34: note: '#pragma message: Using nanosleep() in sp_thread_sleep'
   24 | # define BOOST_PRAGMA_MESSAGE(x) _Pragma(BOOST_STRINGIZE(message(x)))
      |                                  ^~~~~~~
/opt/local/libexec/boost/1.76/include/boost/smart_ptr/detail/sp_thread_sleep.hpp:50:3: note: in expansion of macro 'BOOST_PRAGMA_MESSAG'
   50 |   BOOST_PRAGMA_MESSAGE("Using nanosleep() in sp_thread_sleep")
      |   ^~~~~~~~~~~~~~~~~~~~
/opt/local/libexec/boost/1.76/include/boost/config/pragma_message.hpp:24:34: note: '#pragma message: Using __atomic spinlock'
   24 | # define BOOST_PRAGMA_MESSAGE(x) _Pragma(BOOST_STRINGIZE(message(x)))
      |                                  ^~~~~~~
/opt/local/libexec/boost/1.76/include/boost/smart_ptr/detail/spinlock_gcc_atomic.hpp:19:1: note: in expansion of macro 'BOOST_PRAGMA_MESSAGE'
   19 | BOOST_PRAGMA_MESSAGE("Using __atomic spinlock")
      | ^~~~~~~~~~~~~~~~~~~~

@pdimov
Copy link

pdimov commented Nov 7, 2022

It's pretty odd that spinlock_mt_test succeeds, while the simple single threaded tests such as spinlock_test do not.

spinlock_test is a very simple program that just locks and unlocks two spinlocks. You should be able to disassemble it and see at which address it causes the bus error.

At the moment I'd think that the __atomic_test_and_set GCC builtin is broken for some reason on this PPC. But I have no idea why. When I put spinlock_test on Godbolt (https://godbolt.org/z/cb73eTzos) I see nothing wrong with it, but I'm not very good at reading PPC assembly.

You can define BOOST_SP_USE_STD_ATOMIC to force smart_ptr to use std::atomic instead of the GCC intrinsics that it prefers by default. If this fixes things, then it's the GCC builtins that are broken on this platform for some reason. And if that fails as well, then std::atomic_flag is also broken. :-)

@barracuda156
Copy link
Contributor Author

@pdimov Oh wow, this indeed seems to be the case. I managed to get a more meaningful GDB output, here the test was compiled with:

spinlock_test.cpp -I/opt/local/libexec/boost/1.76/include -std=c++17 -L/opt/local/libexec/boost/1.76/lib -g -O0

GDB:

(gdb) run
Starting program: /Users/svacchanda/Dev/boost/a.out 
Reading symbols for shared libraries +++..... done

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 259 at address: 0x0000208d
0x00001b2c in boost::detail::spinlock::try_lock (this=0x208d) at spinlock_gcc_atomic.hpp:39
39	        return __atomic_test_and_set( &v_, __ATOMIC_ACQUIRE ) == 0;
(gdb) quit

Then I recompile the test with a definition you recommended to try:

g++-mp-11 spinlock_test.cpp -DBOOST_SP_USE_STD_ATOMIC -I/opt/local/libexec/boost/1.76/include -std=c++17 -L/opt/local/libexec/boost/1.76/lib -g -O0

And all is good:

(gdb) run
Starting program: /Users/svacchanda/Dev/boost/a.out 
Reading symbols for shared libraries ++++.. done

Program exited normally.

Maybe @iains could shed some light on __atomic_test_and_set GCC builtin.

@pdimov
Copy link

pdimov commented Nov 7, 2022

@orignal
Copy link
Contributor

orignal commented Nov 7, 2022

Also you should try std::atomic_load instead boost::atomic_load. I remember I had to use boost's because it was not supported by older g++.

@pdimov
Copy link

pdimov commented Nov 7, 2022

std::atomic_load should work, but it's deprecated in C++20 in favor of std::atomic<std::shared_ptr>.

@orignal
Copy link
Contributor

orignal commented Nov 7, 2022

Try it on PPC if it crashes

@barracuda156
Copy link
Contributor Author

@pdimov @orignal I recompiled i2pd adding -DBOOST_SP_USE_STD_ATOMIC as cxxflag – and it is working:

sergey-fedorovs-power-mac-g5:~ svacchanda$ /opt/local/bin/i2pd
06:49:58@273/none - i2pd v2.43.0 (0.9.55) starting...
06:49:58@273/warn - Family: Can't load family certificates from /Users/svacchanda/Library/Application Support/i2pd/certificates/family
06:49:59@273/warn - Reseed: Can't load reseed certificates from /Users/svacchanda/Library/Application Support/i2pd/certificates/reseed
06:49:59@273/error - RouterInfo: Can't open file 
06:50:01@623/warn - SSU: Can't connect to unreachable router and no compatibe non-expired introducers presented
06:50:01@244/warn - Transports: 15 ephemeral keys generated at the time
06:50:01@273/warn - Addressbook: Can't open /Users/svacchanda/Library/Application Support/i2pd/addressbook/addresses.csv
06:50:01@273/error - Addressbook: Resetting eTags
06:50:01@273/warn - Clients: Can't read /Users/svacchanda/Library/Application Support/i2pd/tunnels.conf: /Users/svacchanda/Library/Application Support/i2pd/tunnels.conf: cannot open file
06:50:02@623/warn - SSU: Missing fragments from 0 to 0 of message 853773660
06:50:02@311/warn - NTCP2: SessionCreated read error: Connection reset by peer
06:50:02@311/warn - NTCP2: SessionCreated read error: End of file
06:50:04@311/warn - NTCP2: SessionCreated read error: Connection reset by peer
06:50:04@623/warn - SSU: Missing fragments from 0 to 1 of message 2877927017

(Nothing is set up yet, so it does not connect, but it runs, no Bus error anymore.)

@barracuda156 barracuda156 changed the title PowerPC: build succeeds, but i2pd fails with Bus error PowerPC: i2pd fails with Bus error if built using GCC atomics Nov 7, 2022
@orignal
Copy link
Contributor

orignal commented Nov 7, 2022

Then add it to Makefile.osx

@barracuda156
Copy link
Contributor Author

Then add it to Makefile.osx

@orignal Existing Makefile.osx is unusable on PPC – and Intel, FWIU, does not need to switch to Boost atomics. If we want to support macOS PPC via Makefiles, there should be GCC-based version, not hardcoded Clang (which is wrong in any case IMO).
What do you think?

P. S. I was using Cmake myself to build + a portfile (I wanna bring i2pd to Macports, broken PPC was the stopper until now).

@orignal
Copy link
Contributor

orignal commented Nov 7, 2022

Create Makefile.ppc then.
But I remember I used that Makefile.osx for PPC build long time ago. Well, it was written for PPC initially.

@yhaenggi
Copy link
Member

yhaenggi commented Nov 7, 2022

Why name it .ppc? Its not a PPC arch issue (bsd/linux are fine). It only applies to osx and the backported toolchains for it.

@barracuda156
Copy link
Contributor Author

@orignal Well, either someone modified it since that time or you have fixed Clang for Darwin PPC :)
This won’t work: CXX = clang++. No publicly available version of Clang works on macOS PPC.
Flags in Makefile are fine, just GCC must be used (g++).

@yhaenggi Yes, of course makefiles are to be OS-based and then arch-specific if necessary. I am well aware that Darwin, AIX and BeOS need different implementation for PPC :)

@orignal
Copy link
Contributor

orignal commented Nov 8, 2022

I used g++ initially, built it manually using old Xcode.

@r4sas
Copy link
Member

r4sas commented Nov 8, 2022

@barracuda156 so, are you currently using cmake or make for MacPorts?

@barracuda156
Copy link
Contributor Author

@barracuda156 so, are you currently using cmake or make for MacPorts?

@r4sas Cmake. We can use only one build system in Macports for a given port, and since we have established for sure that it was not Cmake causing a problem, I will stick with it.
(Portfile is there in my tree, but I did not finalize symlinking. Hope to do that in a day or two.)

If you and others wish, we can also include the portfile with i2pd distribution.

@r4sas
Copy link
Member

r4sas commented Nov 9, 2022

In that case adding of -DBOOST_SP_USE_STD_ATOMIC won't be problem at all. FindArch.cmake can be used to do same check for __POWERPC__ as it has been done for pthread_setname_np and setting of this define for PPC only.

@barracuda156
Copy link
Contributor Author

In that case adding of -DBOOST_SP_USE_STD_ATOMIC won't be problem at all. FindArch.cmake can be used to do same check for __POWERPC__ as it has been done for pthread_setname_np and setting of this define for PPC only.

Fair enough, it is preferable to add that into CMakeLists rather than having a custom fix in Macports (it is easily done via portfile, but then it is limited to Macports).

@barracuda156
Copy link
Contributor Author

@pdimov @orignal Re __atomic_test_and_set: GCC developers suggest “exploring the possibility that someone has assumed that either the spinlock or a bool is 8-bits”. Both are 32-bit on Darwin PPC.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107590

@pdimov
Copy link

pdimov commented Nov 10, 2022

Thanks, this will help.

@pdimov
Copy link

pdimov commented Nov 10, 2022

Can you please test whether this change:

boostorg/smart_ptr@97c9204

fixes the issue?

@barracuda156
Copy link
Contributor Author

@pdimov A quick check suggests that it does. I have modified the header in Boost 1.76, while leaving 1.79 as it was:

36-172% /opt/local/bin/g++-mp-11 spinlock_test.cpp -I/opt/local/libexec/boost/1.76/include -L/opt/local/libexec/boost/1.76/lib -o spinlock_test
36-172% /Users/svacchanda/Dev/boost/spinlock_test 
36-172% /opt/local/bin/g++-mp-11 spinlock_test.cpp -I/opt/local/libexec/boost/1.79/include -L/opt/local/libexec/boost/1.79/lib -o spinlock_test2
36-172% /Users/svacchanda/Dev/boost/spinlock_test2
zsh: bus error  /Users/svacchanda/Dev/boost/spinlock_test2

No error with modified header.

@pdimov
Copy link

pdimov commented Nov 10, 2022

Good! Will you be trying the real thing with the patch?

@barracuda156
Copy link
Contributor Author

barracuda156 commented Nov 10, 2022

Good! Will you be trying the real thing with the patch?

@pdimov Sure, will try rebuilding now. (But we rather wait for GCC devs reply too before making any changes to the code.)

UPD. Rebuilt i2pd using Boost 1.76 with patched header, no Bus error, starts normally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants