Skip to content

Commit

Permalink
Do not link libm dynamically when building the static musl binary
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <dl6er@dl6er.de>
  • Loading branch information
DL6ER committed Jul 22, 2020
1 parent fa259ae commit 59e9254
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .circleci/build-CI.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
rm -rf cmake/ && \
mkdir cmake && \
cd cmake && \
cmake "${1}" .. && \
cmake ${1} .. && \
cmake --build . -- GIT_BRANCH="${2}" GIT_TAG="${3}" CIRCLE_JOB="${4}" -j 4 && \
mv pihole-FTL ../
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ version: 2
command: |
BRANCH=$([ -z "$CIRCLE_TAG" ] && echo "$CIRCLE_BRANCH" || echo "master")
[[ $CIRCLE_JOB == *"qemu"* ]] && DOCKERIFNEEDED="docker run --rm -v $(pwd):/workspace -w /workspace pihole/ftl-build:arm-qemu "
$DOCKERIFNEEDED bash .circleci/build-CI.sh "-DSTATIC=${STATIC}" "${BRANCH}" "${CIRCLE_TAG}" "${CIRCLE_JOB} -DLUA_READLINE=true"
$DOCKERIFNEEDED bash .circleci/build-CI.sh "-DSTATIC=${STATIC} -DLUA_READLINE=true" "${BRANCH}" "${CIRCLE_TAG}" "${CIRCLE_JOB}"
- run:
name: "Binary checks"
command: bash test/arch_test.sh
Expand Down
8 changes: 5 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ if(STATIC STREQUAL "true")
set_target_properties(pihole-FTL PROPERTIES LINK_SEARCH_START_STATIC ON)
set_target_properties(pihole-FTL PROPERTIES LINK_SEARCH_END_STATIC ON)
target_link_libraries(pihole-FTL -static-libgcc -static -static-pie)
else()
find_library(LIBMATH m${CMAKE_STATIC_LIBRARY_SUFFIX})
target_link_libraries(pihole-FTL ${LIBMATH})
endif()

target_compile_options(pihole-FTL PRIVATE ${EXTRAWARN})
target_compile_definitions(pihole-FTL PRIVATE DNSMASQ_VERSION=\"${DNSMASQ_VERSION}\")
target_include_directories(pihole-FTL PRIVATE ${PROJECT_SOURCE_DIR}/src)
Expand All @@ -180,10 +184,8 @@ find_library(LIBHOGWEED libhogweed${CMAKE_STATIC_LIBRARY_SUFFIX})
find_library(LIBGMP libgmp${CMAKE_STATIC_LIBRARY_SUFFIX})
find_library(LIBNETTLE libnettle${CMAKE_STATIC_LIBRARY_SUFFIX})
find_library(LIBIDN libidn${CMAKE_STATIC_LIBRARY_SUFFIX})
# for LUA we need libdl (lookforfunc) and libm (linking libm and libdl statically is discouraged)
find_library(LIBMATH m)

target_link_libraries(pihole-FTL rt Threads::Threads ${LIBHOGWEED} ${LIBGMP} ${LIBNETTLE} ${LIBIDN} ${LIBMATH})
target_link_libraries(pihole-FTL rt Threads::Threads ${LIBHOGWEED} ${LIBGMP} ${LIBNETTLE} ${LIBIDN})

if(LUA_DL STREQUAL "true")
find_library(LIBDL dl)
Expand Down
12 changes: 6 additions & 6 deletions test/arch_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ check_file() {
if [[ "${CIRCLE_JOB}" == "x86_64" ]]; then

check_machine "ELF64" "Advanced Micro Devices X86-64"
check_libs "[librt.so.1] [libpthread.so.0] [libc.so.6]"
check_libs "[librt.so.1] [libm.so.6] [libpthread.so.0] [libc.so.6]"
check_file "ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, not stripped"

elif [[ "${CIRCLE_JOB}" == "x86_64-musl" ]]; then
Expand All @@ -79,19 +79,19 @@ elif [[ "${CIRCLE_JOB}" == "x86_64-musl" ]]; then
elif [[ "${CIRCLE_JOB}" == "x86_32" ]]; then

check_machine "ELF32" "Intel 80386"
check_libs "[librt.so.1] [libpthread.so.0] [libc.so.6]"
check_libs "[librt.so.1] [libm.so.6] [libpthread.so.0] [libc.so.6]"
check_file "ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, not stripped"

elif [[ "${CIRCLE_JOB}" == "aarch64" ]]; then

check_machine "ELF64" "AArch64"
check_libs "[librt.so.1] [libpthread.so.0] [libc.so.6] [ld-linux-aarch64.so.1]"
check_libs "[librt.so.1] [libm.so.6] [libpthread.so.0] [libc.so.6] [ld-linux-aarch64.so.1]"
check_file "ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, not stripped"

elif [[ "${CIRCLE_JOB}" == "arm" ]]; then

check_machine "ELF32" "ARM"
check_libs "[librt.so.1] [libgcc_s.so.1] [libpthread.so.0] [libc.so.6] [ld-linux-armhf.so.3]"
check_libs "[librt.so.1] [libm.so.6] [libgcc_s.so.1] [libpthread.so.0] [libc.so.6] [ld-linux-armhf.so.3]"
check_file "ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32, not stripped"

check_CPU_arch "v6"
Expand All @@ -100,7 +100,7 @@ elif [[ "${CIRCLE_JOB}" == "arm" ]]; then
elif [[ "${CIRCLE_JOB}" == "armhf" ]]; then

check_machine "ELF32" "ARM"
check_libs "[librt.so.1] [libgcc_s.so.1] [libpthread.so.0] [libc.so.6] [ld-linux-armhf.so.3]"
check_libs "[librt.so.1] [libm.so.6] [libgcc_s.so.1] [libpthread.so.0] [libc.so.6] [ld-linux-armhf.so.3]"
check_file "ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, not stripped"

check_CPU_arch "v7"
Expand All @@ -109,7 +109,7 @@ elif [[ "${CIRCLE_JOB}" == "armhf" ]]; then
elif [[ "${CIRCLE_JOB}" == "arm-qemu" ]]; then

check_machine "ELF32" "ARM"
check_libs "[librt.so.1] [libgcc_s.so.1] [libpthread.so.0] [libc.so.6] [ld-linux.so.3]"
check_libs "[librt.so.1] [libm.so.6] [libgcc_s.so.1] [libpthread.so.0] [libc.so.6] [ld-linux.so.3]"
check_file "ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.2.0, not stripped"

check_CPU_arch "v6"
Expand Down

0 comments on commit 59e9254

Please sign in to comment.