Skip to content

Commit 01c1264

Browse files
committed
patch configure-check-function-sections.patch
1 parent c8eb54b commit 01c1264

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

configure

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,17 @@ set_defaults()
213213
RUST=${RUST:-$(default_rust_setting)}
214214
}
215215

216+
# Given CC and FLAGS do we support -ffunction-sections and --gc-sections?
217+
have_function_sections()
218+
{
219+
# This gets removed automatically on exit!
220+
TMPCFILE=$CONFIG_VAR_FILE.$$.c
221+
TMPOBJFILE=$CONFIG_VAR_FILE.$$.o
222+
223+
echo "int foo(void); int foo(void) { return 0; }" > $TMPCFILE
224+
$1 $2 -ffunction-sections -Wl,--gc-sections -c $TMPCFILE -o $TMPOBJFILE
225+
}
226+
216227
usage()
217228
{
218229
echo "Usage: ./configure [--reconfigure] [setting=value] [options]"
@@ -355,10 +366,19 @@ EOF
355366
done
356367
fi
357368

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

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

364384
if [ "$CLANG_COVERAGE" = "1" ]; then
@@ -406,7 +426,7 @@ if command -v "${PG_CONFIG}" >/dev/null; then
406426
fi
407427

408428
# Clean up on exit.
409-
trap "rm -f $CONFIG_VAR_FILE.$$" 0
429+
trap "rm -f $CONFIG_VAR_FILE.$$*" 0
410430

411431
$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
412432
@@ -619,6 +639,7 @@ add_var FUZZING "$FUZZING"
619639
add_var RUST "$RUST"
620640
add_var PYTHON "$PYTHON"
621641
add_var SED "$SED"
642+
add_var HAVE_FUNCTION_SECTIONS "$HAVE_FUNCTION_SECTIONS"
622643

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

0 commit comments

Comments
 (0)