diff options
author | Martin Matuška <martin@matuska.org> | 2022-01-03 12:07:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-03 12:07:13 +0100 |
commit | dd733f5c25efcc727c38949811e597d196a003f7 (patch) | |
tree | 89f84668ac88e22d9e732b525bcffa16d79c70e7 /configure.ac | |
parent | 38db08b16698e73c22b131cddd68658b80a43845 (diff) | |
parent | fc0758237548328941fa7a9699510d6f357896ed (diff) | |
download | libarchive-dd733f5c25efcc727c38949811e597d196a003f7.tar.gz |
Merge pull request #1625 from evelikov/gc-sections
Instrument gcc/clang to discard unused code during link
Diffstat (limited to 'configure.ac')
-rw-r--r-- | configure.ac | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index 85868ade..f9fe624e 100644 --- a/configure.ac +++ b/configure.ac @@ -542,6 +542,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 |