Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ else
LDLIBS = -L$(CPATH) -lm $(SQLITE3_LDLIBS) $(COVFLAGS)
endif

ifeq ($(HAVE_FUNCTION_SECTIONS),1)
LDLIBS += -Wl,--gc-sections
endif

# If we have the postgres client library we need to link against it as well
ifeq ($(HAVE_POSTGRES),1)
LDLIBS += $(POSTGRES_LDLIBS)
Expand Down Expand Up @@ -1152,7 +1156,8 @@ ccan-rune-rune.o: $(CCANDIR)/ccan/rune/rune.c
ccan-rune-coding.o: $(CCANDIR)/ccan/rune/coding.c
@$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<)

print-binary-sizes: $(ALL_PROGRAMS) $(ALL_TEST_PROGRAMS)
@find $(ALL_PROGRAMS) $(ALL_TEST_PROGRAMS) -printf '%p\t%s\n'
@echo 'Total program size: '`find $(ALL_PROGRAMS) -printf '%s\n' | awk '{TOTAL+= $$1} END {print TOTAL}'`
@echo 'Total tests size: '`find $(ALL_TEST_PROGRAMS) -printf '%s\n' | awk '{TOTAL+= $$1} END {print TOTAL}'`
print-binary-sizes: $(ALL_PROGRAMS) $(ALL_TEST_PROGRAMS) $(BIN_PROGRAMS)
@echo User programs:
@size -t $(PKGLIBEXEC_PROGRAMS) $(filter-out tools/reckless,$(BIN_PROGRAMS)) $(PLUGINS)
@echo All programs:
@size -t $(ALL_PROGRAMS) $(ALL_TEST_PROGRAMS) | tail -n1
26 changes: 23 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ set_defaults()
FUZZFLAGS="-fsanitize=fuzzer-no-link -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION"
CSANFLAGS="$CSANFLAGS $FUZZFLAGS"
fi
echo CSANFLAGS = $CSANFLAGS
PYTHON=${PYTHON-$(default_python)}
SED=${SED-$(default_sed)}
PYTEST=${PYTEST-$(default_pytest $PYTHON)}
Expand All @@ -213,6 +212,17 @@ set_defaults()
RUST=${RUST:-$(default_rust_setting)}
}

# Given CC and FLAGS do we support -ffunction-sections and --gc-sections?
have_function_sections()
{
# This gets removed automatically on exit!
TMPCFILE=$CONFIG_VAR_FILE.$$.c
TMPOBJFILE=$CONFIG_VAR_FILE.$$.o

echo "int foo(void); int foo(void) { return 0; }" > $TMPCFILE
$1 $2 -ffunction-sections -Wl,--gc-sections -c $TMPCFILE -o $TMPOBJFILE
}

usage()
{
echo "Usage: ./configure [--reconfigure] [setting=value] [options]"
Expand Down Expand Up @@ -355,10 +365,19 @@ EOF
done
fi

# We call this first, so we can make sure configurator runs with it as a sanity check!
if have_function_sections $CC "${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTFLAGS"; then
HAVE_FUNCTION_SECTIONS=1
LDFLAGS="-Wl,--gc-sections"
COPTFLAGS="$COPTFLAGS -ffunction-sections"
else
HAVE_FUNCTION_SECTIONS=0
LDFLAGS=
fi

# We assume warning flags don't affect congfigurator that much!
echo -n "Compiling $CONFIGURATOR..."
$CC ${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTFLAGS -o $CONFIGURATOR $CONFIGURATOR.c
$CC ${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTFLAGS $LDFLAGS -o $CONFIGURATOR $CONFIGURATOR.c
echo "done"

if [ "$CLANG_COVERAGE" = "1" ]; then
Expand Down Expand Up @@ -406,7 +425,7 @@ if command -v "${PG_CONFIG}" >/dev/null; then
fi

# Clean up on exit.
trap "rm -f $CONFIG_VAR_FILE.$$" 0
trap "rm -f $CONFIG_VAR_FILE.$$*" 0

$CONFIGURATOR --extra-tests --autotools-style --var-file=$CONFIG_VAR_FILE.$$ --header-file=$CONFIG_HEADER.$$ --configurator-cc="$CONFIGURATOR_CC" --wrapper="$CONFIGURATOR_WRAPPER" "$CC" ${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTFLAGS $CSANFLAGS -I$CPATH -L$LIBRARY_PATH $SQLITE3_CFLAGS $SODIUM_CFLAGS $POSTGRES_INCLUDE <<EOF

Expand Down Expand Up @@ -619,6 +638,7 @@ add_var FUZZING "$FUZZING"
add_var RUST "$RUST"
add_var PYTHON "$PYTHON"
add_var SED "$SED"
add_var HAVE_FUNCTION_SECTIONS "$HAVE_FUNCTION_SECTIONS"

# Hack to avoid sha256 name clash with libwally: will be fixed when that
# becomes a standalone shared lib.
Expand Down
Loading