From fc0758237548328941fa7a9699510d6f357896ed Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sun, 21 Nov 2021 17:38:38 +0000 Subject: autotools: enable -fdata/function-sections and --gc-sections Analogue to the parent cmake commit, with linker flag detection. The former two split the functions and data into separate sections within the object file. Which makes it easier for the latter to properly garbage collect and discard unused sections. Signed-off-by: Emil Velikov --- configure.ac | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index cb89c3ee..c8295e4a 100644 --- a/configure.ac +++ b/configure.ac @@ -540,6 +540,22 @@ fi # Checks for supported compiler flags AX_APPEND_COMPILE_FLAGS([-Wall -Wformat -Wformat-security]) +# Place the functions and data into separate sections, allowing the linker +# to garbage collect the unused ones. +save_LDFLAGS=$LDFLAGS +LDFLAGS="$LDFLAGS -Wl,--gc-sections" +AC_MSG_CHECKING([whether ld supports --gc-sections]) +AC_LINK_IFELSE( + [AC_LANG_SOURCE([static char UnusedFunc() { return 5; } int main() { return 0;}])], + [AC_MSG_RESULT([yes]) + GC_SECTIONS="-Wl,--gc-sections"; + AX_APPEND_COMPILE_FLAGS([-ffunction-sections -fdata-sections])], + [AC_MSG_RESULT([no]) + GC_SECTIONS="";]) +LDFLAGS=$save_LDFLAGS + +AC_SUBST(GC_SECTIONS) + # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST # la_TYPE_UID_T defaults to "int", which is incorrect for MinGW -- cgit v1.2.1