SChernykh / p2pool

Decentralized pool for Monero mining
GNU General Public License v3.0
1.03k stars 123 forks source link

build fail with either lto or static, aarch64 debian sid #301

Closed knuxyl closed 3 months ago

knuxyl commented 4 months ago

I am building on aarch64, rock 3a rk3568 with GNU 13.2.0, kernel 6.7-arm64. I cloned repo with --recursive so I have all external dependencies available, and my system also have libzmq3-dev installed (debian sid).

Setting manual C and CXX flags to LTO and static gives this (somewhat expected)

C_FLAGS:         -O3 -flto -static -march=native -pthread -mfix-cortex-a53-835769 -mfix-cortex-a53-843419 -Wall -Wextra -Wcast-qual -Wlogical-op -Wstrict-overflow=2 -Wundef -Wformat=2 -Wpointer-arith -Werror -Ofast -s -flto -fuse-linker-plugin
CXX_FLAGS:       -O3 -flto -static -march=native -pthread -mfix-cortex-a53-835769 -mfix-cortex-a53-843419 -Wall -Wextra -Wcast-qual -Wlogical-op -Wstrict-overflow=2 -Wundef -Wformat=2 -Wpointer-arith -Werror -Ofast -s -flto -fuse-linker-plugin

/usr/bin/ld: attempted static link of dynamic object `/usr/lib/aarch64-linux-gnu/libzmq.so' collect2: error: ld returned 1 exit status

I found the option in CMakeLists.txt for STATIC_BINARY and STATIC_LIBS so I then ran this

CFLAGS="-O3 -flto -march=native -static" CXXFLAGS="-O3 -flto -march=native -static" cmake ../ -DSTATIC_BINARY=ON -DSTATIC_LIBS=ON -DWITH_RANDOMX=ON -DWITH_LTO=ON -DWITH_UPNP=OFF

I don't think my flags are affecting anything because -Ofast and -flto are specified later in the build command, overwriting mine. The output of this gives

make[2]: *** No rule to make target '/home/knuxyl/p2pool/external/src/libzmq/build/lib/libzmq.a', needed by 'p2pool'. Stop.

So my first attempt tried to static link a dynamic library, and then the second attempt tried to include the static library but there was no rule to make it.

My third attempt I removed "-static" from the flags but kept the CMake defines and I still get the same error

make[2]: *** No rule to make target '/home/knuxyl/p2pool/external/src/libzmq/build/lib/libzmq.a', needed by 'p2pool'. Stop.

Also I should note that the C and CXX flags generated by CMake include fixes for cortex A53, but this cpu is a quad core A55. I'm not sure why these are being included, I'm guessing a GCC thing so not relevant here.

-mfix-cortex-a53-835769 -mfix-cortex-a53-843419

EDIT

Disabling LTO and Static will allow it to build, but no combination of lto and/or static will work. Either one of those options causes the build to fail.

SChernykh commented 4 months ago

If you want to build static binary, you need to follow the same steps as in CI builds: https://github.com/SChernykh/p2pool/blob/master/.github/workflows/c-cpp.yml#L13 for Alpine Linux https://github.com/SChernykh/p2pool/blob/master/.github/workflows/c-cpp.yml#L165 for Ubuntu

In short, you have to build dependencies (curl, libuv, libzmq) in external/src folder first, then build p2pool with -DSTATIC_LIBS=ON

SChernykh commented 4 months ago

For Ubuntu:

In external/src/curl directory:

cmake . -DCMAKE_C_FLAGS="-Os -flto=auto -fuse-linker-plugin -ffunction-sections -Wno-error=inline" -DBUILD_CURL_EXE=OFF -DBUILD_SHARED_LIBS=OFF -DCURL_DISABLE_INSTALL=ON -DCURL_ENABLE_EXPORT_TARGET=OFF -DCURL_DISABLE_HEADERS_API=ON -DCURL_DISABLE_BINDLOCAL=ON -DBUILD_LIBCURL_DOCS=OFF -DCURL_ZLIB=OFF -DCURL_DISABLE_ALTSVC=ON -DCURL_DISABLE_COOKIES=ON -DCURL_DISABLE_DOH=ON -DCURL_DISABLE_GETOPTIONS=ON -DCURL_DISABLE_HSTS=ON -DCURL_DISABLE_LIBCURL_OPTION=ON -DCURL_DISABLE_MIME=ON -DCURL_DISABLE_NETRC=ON -DCURL_DISABLE_NTLM=ON -DCURL_DISABLE_PARSEDATE=ON -DCURL_DISABLE_PROGRESS_METER=ON -DCURL_DISABLE_SHUFFLE_DNS=ON -DCURL_DISABLE_SOCKETPAIR=ON -DCURL_DISABLE_VERBOSE_STRINGS=ON -DHTTP_ONLY=ON -DCURL_ENABLE_SSL=OFF -DUSE_LIBIDN2=OFF -DCURL_USE_LIBPSL=OFF -DCURL_USE_LIBSSH2=OFF -DENABLE_UNIX_SOCKETS=OFF
make -j$(nproc)
cd lib && mkdir .libs && cp libcurl.a .libs

In external/src/libuv directory:

mkdir build
cd build
cmake .. -DCMAKE_C_FLAGS='-Os -flto=auto -fuse-linker-plugin -ffunction-sections -Wno-error=inline' -DBUILD_TESTING=OFF -DLIBUV_BUILD_SHARED=OFF
make -j$(nproc)

In external/src/libzmq directory:

mkdir build
cd build
cmake .. -DCMAKE_C_FLAGS='-Os -flto=auto -fuse-linker-plugin -ffunction-sections -Wno-error=inline' -DCMAKE_CXX_FLAGS='-Os -flto=auto -fuse-linker-plugin -ffunction-sections -Wno-error=inline' -DWITH_LIBSODIUM=OFF -DWITH_LIBBSD=OFF -DBUILD_TESTS=OFF -DWITH_DOCS=OFF -DENABLE_DRAFTS=OFF -DBUILD_SHARED=OFF
make -j$(nproc)

And finally in the main p2pool directory:

mkdir build
cd build
cmake ..  -DCMAKE_C_FLAGS='-fuse-linker-plugin -ffunction-sections -Wno-error=inline -Wl,-s -Wl,--gc-sections' -DCMAKE_CXX_FLAGS='-fuse-linker-plugin -ffunction-sections -Wno-error=inline -Wl,-s -Wl,--gc-sections' -DSTATIC_LIBS=ON
make -j$(nproc) p2pool
knuxyl commented 3 months ago

Thank you. I had to manually move libcurl.a from src/curl/build/lib/ to src/curl/lib/.libs and everything compiled smoothly.