Skip to content

Commit 685b7a7

Browse files
laanwjPastaPastaPasta
authored andcommitted
Merge bitcoin#23611: build: add LTO option to depends
0947726 build: support LTO in depends (fanquake) Pull request description: This adds an `LTO` option to depends, i.e `make -C depends LTO=1`, which passes `-flto` when building packages (not currently qt), and automatically configures with `--enable-lto` when doing a build using a `CONFIG_SITE`. The following tables comapres the size (in bytes) of the stripped `x86_64` Linux binaries produced with master and this PR (full depends build): | Binary | stripped master | stripped LTO=1 | saving | | -------- | ----------------: | -------------: | --------: | | bitcoin-cli | 1178632 | 469872 | 60% | | bitcoin-tx | 2710584 | 1866504 | 31% | | bitcoin-util | 952880 | 240104 | 74% | | bitcoin-wallet | 7992888 | 5365984 | 32% | | bitcoind | 13421336 | 11868592 | 12% | | bitcoin-qt | 37680496 | 31640976 | 16% | ACKs for top commit: laanwj: Tested ACK 0947726 Tree-SHA512: 6b8483ea490e57a153105ad8c38b25fb1af5d55b1af22db398c7c2573612aaf71b4d2b4cf09c18fd6331b1358dba01641eeaa03e5018a925392e1937118d984a
1 parent d2b8c6b commit 685b7a7

11 files changed

+55
-3
lines changed

depends/Makefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ NO_UPNP ?=
4242
NO_USDT ?=
4343
NO_NATPMP ?=
4444
MULTIPROCESS ?=
45+
LTO ?=
4546
FALLBACK_DOWNLOAD_PATH ?= http://dash-depends-sources.s3-website-us-west-2.amazonaws.com
4647

4748
BUILD = $(shell ./config.guess)
@@ -140,8 +141,8 @@ include packages/packages.mk
140141
# 2. Before including packages/*.mk (excluding packages/packages.mk), since
141142
# they rely on the build_id variables
142143
#
143-
build_id:=$(shell env CC='$(build_CC)' CXX='$(build_CXX)' AR='$(build_AR)' RANLIB='$(build_RANLIB)' STRIP='$(build_STRIP)' SHA256SUM='$(build_SHA256SUM)' DEBUG='$(DEBUG)' ./gen_id '$(BUILD_ID_SALT)' 'GUIX_ENVIRONMENT=$(realpath $(GUIX_ENVIRONMENT))')
144-
$(host_arch)_$(host_os)_id:=$(shell env CC='$(host_CC)' CXX='$(host_CXX)' AR='$(host_AR)' RANLIB='$(host_RANLIB)' STRIP='$(host_STRIP)' SHA256SUM='$(build_SHA256SUM)' DEBUG='$(DEBUG)' ./gen_id '$(HOST_ID_SALT)' 'GUIX_ENVIRONMENT=$(realpath $(GUIX_ENVIRONMENT))')
144+
build_id:=$(shell env CC='$(build_CC)' CXX='$(build_CXX)' AR='$(build_AR)' RANLIB='$(build_RANLIB)' STRIP='$(build_STRIP)' SHA256SUM='$(build_SHA256SUM)' DEBUG='$(DEBUG)' LTO='$(LTO)' ./gen_id '$(BUILD_ID_SALT)' 'GUIX_ENVIRONMENT=$(realpath $(GUIX_ENVIRONMENT))')
145+
$(host_arch)_$(host_os)_id:=$(shell env CC='$(host_CC)' CXX='$(host_CXX)' AR='$(host_AR)' RANLIB='$(host_RANLIB)' STRIP='$(host_STRIP)' SHA256SUM='$(build_SHA256SUM)' DEBUG='$(DEBUG)' LTO='$(LTO)' ./gen_id '$(HOST_ID_SALT)' 'GUIX_ENVIRONMENT=$(realpath $(GUIX_ENVIRONMENT))')
145146

146147
qrencode_packages_$(NO_QR) = $(qrencode_$(host_os)_packages)
147148

@@ -239,6 +240,7 @@ $(host_prefix)/share/config.site : config.site.in $(host_prefix)/.stamp_$(final_
239240
-e 's|@no_usdt@|$(NO_USDT)|' \
240241
-e 's|@no_natpmp@|$(NO_NATPMP)|' \
241242
-e 's|@multiprocess@|$(MULTIPROCESS)|' \
243+
-e 's|@lto@|$(LTO)|' \
242244
-e 's|@debug@|$(DEBUG)|' \
243245
$< > $@
244246
touch $@

depends/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ The following can be set when running make: `make FOO=bar`
120120
- `LOG`: Use file-based logging for individual packages. During a package build its log file
121121
resides in the `depends` directory, and the log file is printed out automatically in case
122122
of build error. After successful build log files are moved along with package archives
123+
- `LTO`: Use LTO when building packages.
123124

124125
If some packages are not built, for example `make NO_WALLET=1`, the appropriate
125126
options will be passed to Dash Core's configure. In this case, `--disable-wallet`.

depends/config.site.in

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ if test "@host_os@" = darwin; then
7878
BREW=no
7979
fi
8080

81+
if test -z "$enable_lto" && test -n "@lto@"; then
82+
enable_lto=yes
83+
fi
84+
8185
PATH="${depends_prefix}/native/bin:${PATH}"
8286
PKG_CONFIG="$(which pkg-config) --static"
8387

depends/gen_id

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
# Usage: env [ CC=... ] [ CXX=... ] [ AR=... ] [ RANLIB=... ] [ STRIP=... ] \
4-
# [ DEBUG=... ] ./build-id [ID_SALT]...
4+
# [ DEBUG=... ] [ LTO=... ] ./build-id [ID_SALT]...
55
#
66
# Prints to stdout a SHA256 hash representing the current toolset, used by
77
# depends/Makefile as a build id for caching purposes (detecting when the
@@ -63,6 +63,10 @@
6363
env | grep '^STRIP_'
6464
echo "END STRIP"
6565

66+
echo "BEGIN LTO"
67+
echo "LTO=${LTO}"
68+
echo "END LTO"
69+
6670
echo "END ALL"
6771
) | if [ -n "$DEBUG" ] && command -v tee > /dev/null 2>&1; then
6872
# When debugging and `tee` is available, output the preimage to stderr

depends/hosts/android.mk

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ else
55
android_CXX=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)$(ANDROID_API_LEVEL)-clang++
66
android_CC=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)$(ANDROID_API_LEVEL)-clang
77
endif
8+
9+
ifneq ($(LTO),)
10+
android_CFLAGS += -flto
11+
android_LDFLAGS += -flto
12+
endif
13+
814
android_AR=$(ANDROID_TOOLCHAIN_BIN)/llvm-ar
915
android_RANLIB=$(ANDROID_TOOLCHAIN_BIN)/llvm-ranlib
1016

depends/hosts/darwin.mk

+6
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ darwin_CXX=env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH \
113113
-Xclang -internal-externc-isystem$(OSX_SDK)/usr/include
114114

115115
darwin_CFLAGS=-pipe
116+
117+
ifneq ($(LTO),)
118+
darwin_CFLAGS += -flto
119+
darwin_LDFLAGS += -flto
120+
endif
121+
116122
darwin_CXXFLAGS=$(darwin_CFLAGS)
117123

118124
darwin_release_CFLAGS=-O2

depends/hosts/freebsd.mk

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
freebsd_CFLAGS=-pipe
2+
3+
ifneq ($(LTO),)
4+
freebsd_CFLAGS += -flto
5+
freebsd_LDFLAGS += -flto
6+
endif
7+
28
freebsd_CXXFLAGS=$(freebsd_CFLAGS)
39

410
freebsd_release_CFLAGS=-O2

depends/hosts/linux.mk

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
linux_CFLAGS=-pipe
2+
3+
ifneq ($(LTO),)
4+
linux_CFLAGS += -flto
5+
linux_LDFLAGS += -flto
6+
endif
7+
28
linux_CXXFLAGS=$(linux_CFLAGS)
39

410
linux_release_CFLAGS=-O2

depends/hosts/mingw32.mk

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ mingw32_CXX := $(host)-g++-posix
33
endif
44

55
mingw32_CFLAGS=-pipe
6+
7+
ifneq ($(LTO),)
8+
mingw32_CFLAGS += -flto
9+
mingw32_LDFLAGS += -flto
10+
endif
11+
612
mingw32_CXXFLAGS=$(mingw32_CFLAGS)
713

814
mingw32_release_CFLAGS=-O2

depends/hosts/netbsd.mk

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
netbsd_CFLAGS=-pipe
2+
3+
ifneq ($(LTO),)
4+
netbsd_CFLAGS += -flto
5+
netbsd_LDFLAGS += -flto
6+
endif
7+
28
netbsd_CXXFLAGS=$(netbsd_CFLAGS)
39

410
netbsd_release_CFLAGS=-O2

depends/hosts/openbsd.mk

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
openbsd_CFLAGS=-pipe
22
openbsd_CXXFLAGS=$(openbsd_CFLAGS)
33

4+
ifneq ($(LTO),)
5+
openbsd_CFLAGS += -flto
6+
openbsd_LDFLAGS += -flto
7+
endif
8+
49
openbsd_release_CFLAGS=-O2
510
openbsd_release_CXXFLAGS=$(openbsd_release_CFLAGS)
611

0 commit comments

Comments
 (0)