Skip to content

Commit

Permalink
guix: build x86_64-linux bitcoind fully statically
Browse files Browse the repository at this point in the history
-static-pie
Produce a static position independent executable on targets that support it.
A static position independent executable is similar to a static executable,
but can be loaded at any address without a dynamic linker.

See https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

GCC 12 is needed to avoid issues with std::thread and static linking.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104852
  • Loading branch information
fanquake committed Apr 15, 2024
1 parent 9c54a3b commit d73587b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion contrib/devtools/symbol-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
# https://sourceware.org/glibc/wiki/ABIList?action=recall&rev=16
ELF_INTERPRETER_NAMES: dict[lief.ELF.ARCH, dict[lief.ENDIANNESS, str]] = {
lief.ELF.ARCH.x86_64: {
lief.ENDIANNESS.LITTLE: "/lib64/ld-linux-x86-64.so.2",
lief.ENDIANNESS.LITTLE: "",
},
lief.ELF.ARCH.ARM: {
lief.ENDIANNESS.LITTLE: "/lib/ld-linux-armhf.so.3",
Expand Down Expand Up @@ -214,6 +214,10 @@ def check_exported_symbols(binary) -> bool:

def check_ELF_libraries(binary) -> bool:
ok: bool = True

if binary.header.machine_type == lief.ELF.ARCH.x86_64:
return len(binary.libraries) == 0

for library in binary.libraries:
if library not in ELF_ALLOWED_LIBRARIES:
print(f'{filename}: {library} is not in ALLOWED_LIBRARIES!')
Expand Down
3 changes: 2 additions & 1 deletion contrib/guix/libexec/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ esac

# Determine the correct value for -Wl,--dynamic-linker for the current $HOST
case "$HOST" in
x86_64-linux-gnu) ;;
*linux*)
glibc_dynamic_linker=$(
case "$HOST" in
x86_64-linux-gnu) echo /lib64/ld-linux-x86-64.so.2 ;;
arm-linux-gnueabihf) echo /lib/ld-linux-armhf.so.3 ;;
aarch64-linux-gnu) echo /lib/ld-linux-aarch64.so.1 ;;
riscv64-linux-gnu) echo /lib/ld-linux-riscv64-lp64d.so.1 ;;
Expand Down Expand Up @@ -243,6 +243,7 @@ esac

# LDFLAGS
case "$HOST" in
x86_64-linux-gnu) HOST_LDFLAGS="-static-libgcc -static-pie -Wl,-O2" ;; # static-libgcc needed for configure
*linux*) HOST_LDFLAGS="-Wl,--as-needed -Wl,--dynamic-linker=$glibc_dynamic_linker -static-libstdc++ -Wl,-O2" ;;
*mingw*) HOST_LDFLAGS="-Wl,--no-insert-timestamp" ;;
esac
Expand Down

0 comments on commit d73587b

Please sign in to comment.