curl/src
Viktor Szakats 66ad54e46b
cmake: add CURL_DROP_UNUSED option to reduce binary sizes
To enable known linker options dropping unused, dead, code and data from
the executables built.

Useful to reduce binary sizes for curl, libcurl shared lib and apps
linking static libcurl. It's effective on both "unity" and non-unity
builds. Aligning "unity" build sizes with default, non-unity ones.

Supported platforms: Apple, MSVC, llvm/clang and GCC on all tested
platforms: Linux, BSDs, Windows, MSYS2/Cygwin, Android, MS-DOS.

Notes:
- Static libraries grow 20-30% with non-Apple toolchains.
  This effect is controlled by separate, optional compiler flags on
  non-Apple. This patch enables them automatically for public binaries
  (libcurl and curl tool), and leaves them off for internal/test ones.
- MSVC enables this option by default for 'Release' configurations.
  The curl build option has no effect on it.
- Observed effect on VS2010 is negligible. VS2012+ is recommended.
- Works with LTO, Fil-C.
- No observed/conclusive effect on build speed.
- On Windows with clang/gcc (mingw-w64/MSYS2/Cygwin) it also enables
  `-fno-asynchronous-unwind-tables` as a workaround to make
  the toolchain options actually work.
  Ref: https://sourceware.org/bugzilla/show_bug.cgi?id=11539
  Thanks-to: Andarwinux

Also:
- GHA: enable in Linux and MinGW jobs to test it. Size changes:

  - linux aws-lc H3:
    curl: 2000000 -> 1937152, libcurl.a: 2065724 -> 2716532 bytes
  - macos clang HTTP-only:
    curl: 1364376 -> 128799 bytes, libcurl.a: unchanged
  - macos llvm MultiSSL:
    curl: 410056 -> 405720, libcurl.dylib: 1350336 -> 1348480 bytes
  - mingw schannel c-ares U:
    curl: 1588736 -> 1507328, libcurl-d.a: 3322040 -> 3884746 bytes
    bld: 34 -> 35MB

- GHA: enable in MSVC and Apple jobs to reduce disk footprint, with no
  obvious downside. Size changes:

  - AppVeyor CI VS2019:
    curl: 2339840 -> 1295872, libcurl-d.dll: 3155968 -> 1900544 bytes
    bld: 161 -> 97MB
  - AppVeyor CI VS2022 clang-cl:
    curl: 2933248 -> 2332160, libcurl-d.lib: 4762688 -> 5511330 bytes
    bld: 133 -> 121MB
  - AppVeyor CI VS2022 HTTP-only:
    curl: 3514368 -> 2177024, libcurl-d.lib: 2538420 -> 3151740 bytes
    bld: 137 -> 83MB
  - GHA intel:
    curl: 2629120 -> 2023424, libcurl-d.lib: 4366652 -> 5350670 bytes
    bld: 86 -> 69MB
  - GHA arm64:
    curl: 2832896 -> 2063872, libcurl-d.lib: 4690616 -> 5597250 bytes
    bld: 82 -> 66MB

Refs:
https://maskray.me/blog/2021-02-28-linker-garbage-collection
https://web.archive.org/web/20110811230637/msdn.microsoft.com/en-us/library/bxwfs976.aspx (VS2010)
https://learn.microsoft.com/cpp/build/reference/opt-optimizations
https://learn.microsoft.com/cpp/build/reference/gy-enable-function-level-linking

Closes #20357
2026-01-22 17:08:20 +01:00
..
toolx localtime: detect thread-safe alternatives and use them 2025-12-16 14:30:06 +01:00
.checksrc checksrc: disallow atoi and atol globally 2025-11-13 14:28:25 +01:00
.gitignore rtmp: remove no longer used proto member 2025-05-08 10:24:19 +02:00
CMakeLists.txt cmake: add CURL_DROP_UNUSED option to reduce binary sizes 2026-01-22 17:08:20 +01:00
config2setopts.c tool: enable header separation for HTTPS proxies 2026-01-22 16:51:34 +01:00
config2setopts.h curl: remove the global argument from many functions 2025-07-10 23:28:31 +02:00
curl.rc build: merge TrackMemory (CURLDEBUG) into debug-enabled option 2026-01-19 18:43:17 +01:00
curlinfo.c build: merge TrackMemory (CURLDEBUG) into debug-enabled option 2026-01-19 18:43:17 +01:00
Makefile.am build: merge TrackMemory (CURLDEBUG) into debug-enabled option 2026-01-19 18:43:17 +01:00
Makefile.inc curlx: curlx_strcopy() instead of strcpy() 2025-12-22 23:01:05 +01:00
mk-file-embed.pl scripts: enable strict warnings in Perl where missing, fix fallouts 2025-07-27 22:35:18 +02:00
mkhelp.pl build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
slist_wc.c tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
slist_wc.h tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
terminal.c src: fix formatting nits 2025-12-03 20:50:18 +01:00
terminal.h curl: make warnings and other messages aware of terminal width 2024-05-28 23:12:32 +02:00
tool_bname.c tidy-up: miscellaneous 2026-01-15 13:06:13 +01:00
tool_bname.h tidy-up: avoid (()), clang-format fixes and more 2025-12-05 16:07:03 +01:00
tool_cb_dbg.c build: drop more forward function declarations 2026-01-14 23:34:05 +01:00
tool_cb_dbg.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_cb_hdr.c tidy-up: miscellaneous 2026-01-15 13:06:13 +01:00
tool_cb_hdr.h tool_cb_hrd: remove global pointer from 'struct HdrCbData' 2025-08-05 15:47:56 +02:00
tool_cb_prg.c build: drop global suppression of -Wformat-nonliteral, fix fallouts 2026-01-20 12:38:02 +01:00
tool_cb_prg.h tidy-up: miscellaneous 2025-12-18 21:27:58 +01:00
tool_cb_rea.c tidy-up: miscellaneous 2026-01-15 13:06:13 +01:00
tool_cb_rea.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_cb_see.c tidy-up: miscellaneous 2025-12-18 21:27:58 +01:00
tool_cb_see.h tidy-up: miscellaneous 2026-01-15 13:06:13 +01:00
tool_cb_soc.c checksrc: ensure using ifdef/ifndef when possible, fix fallouts 2025-12-21 21:12:31 +01:00
tool_cb_soc.h curl: (on linux) add MPTCP support 2024-06-07 10:54:19 +02:00
tool_cb_wrt.c build: update to not need _CRT_NONSTDC_NO_DEPRECATE with MSVC 2026-01-20 23:19:54 +01:00
tool_cb_wrt.h copyright: update all copyright lines and remove year ranges 2023-01-03 09:19:21 +01:00
tool_cfgable.c tidy-up: miscellaneous 2026-01-15 13:06:13 +01:00
tool_cfgable.h tidy-up: miscellaneous 2026-01-15 13:06:13 +01:00
tool_dirhie.c build: update to not need _CRT_NONSTDC_NO_DEPRECATE with MSVC 2026-01-20 23:19:54 +01:00
tool_dirhie.h src: drop unused includes 2025-12-25 18:42:54 +01:00
tool_doswin.c tool_doswin: document ENABLE_VIRTUAL_TERMINAL_PROCESSING toolchain support 2026-01-14 12:53:14 +01:00
tool_doswin.h tool: improve error/warning messages when output filename sanitization fails 2026-01-10 13:21:27 +01:00
tool_easysrc.c src: fix formatting nits 2025-12-03 20:50:18 +01:00
tool_easysrc.h tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_filetime.c windows: fix CreateFile() calls to support long filenames 2025-12-20 14:16:42 +01:00
tool_filetime.h tool_filetime: sync dummy macro signature with function prototype 2026-01-12 16:29:32 +01:00
tool_findfile.c build: update to not need _CRT_NONSTDC_NO_DEPRECATE with MSVC 2026-01-20 23:19:54 +01:00
tool_findfile.h windows: use built-in _WIN32 macro to detect Windows 2023-11-22 15:42:25 +00:00
tool_formparse.c src: drop unused includes 2025-12-25 18:42:54 +01:00
tool_formparse.h curl: make global truly global 2025-08-07 10:43:06 +02:00
tool_getparam.c cmake: silence silly Apple clang warnings in C89 mode, test in CI 2026-01-20 13:05:01 +01:00
tool_getparam.h tidy-up: miscellaneous 2026-01-20 12:37:56 +01:00
tool_getpass.c build: update to not need _CRT_NONSTDC_NO_DEPRECATE with MSVC 2026-01-20 23:19:54 +01:00
tool_getpass.h code: language cleanup in comments 2024-07-01 22:58:55 +02:00
tool_help.c src: drop unused includes 2025-12-25 18:42:54 +01:00
tool_help.h tidy-up: miscellaneous 2026-01-15 13:06:13 +01:00
tool_helpers.c src: fix formatting nits 2025-12-03 20:50:18 +01:00
tool_helpers.h curl: make global truly global 2025-08-07 10:43:06 +02:00
tool_hugehelp.h build: drop tool_hugehelp.c.cvs, tidy up macros, drop buildconf.bat 2025-01-26 14:22:49 +01:00
tool_ipfs.c src: fix formatting nits 2025-12-03 20:50:18 +01:00
tool_ipfs.h tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_libinfo.c build: merge TrackMemory (CURLDEBUG) into debug-enabled option 2026-01-19 18:43:17 +01:00
tool_libinfo.h build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_listhelp.c tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_main.c socket: check result of SO_NOSIGPIPE 2026-01-20 16:38:49 +01:00
tool_main.h src: fix formatting nits 2025-12-03 20:50:18 +01:00
tool_msgs.c src: drop unused includes 2025-12-25 18:42:54 +01:00
tool_msgs.h tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_operate.c build: update to not need _CRT_NONSTDC_NO_DEPRECATE with MSVC 2026-01-20 23:19:54 +01:00
tool_operate.h tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_operhlp.c tool: improve error/warning messages when output filename sanitization fails 2026-01-10 13:21:27 +01:00
tool_operhlp.h tool: improve error/warning messages when output filename sanitization fails 2026-01-10 13:21:27 +01:00
tool_paramhlp.c tool_paramhlp: simplify number parsing 2026-01-01 12:15:34 +01:00
tool_paramhlp.h src: drop unused includes 2025-12-25 18:42:54 +01:00
tool_parsecfg.c tool_urlglob: support globs as long as config line lengths 2025-12-13 14:26:20 +01:00
tool_parsecfg.h tool: log when loading .curlrc in verbose mode 2025-11-25 16:06:27 +01:00
tool_progress.c tool_progress: fix large time outputs and decimal size display 2026-01-04 00:16:59 +01:00
tool_progress.h tidy-up: miscellaneous 2026-01-15 13:06:13 +01:00
tool_sdecls.h tidy-up: miscellaneous 2026-01-15 13:06:13 +01:00
tool_setopt.c src: drop unused includes 2025-12-25 18:42:54 +01:00
tool_setopt.h src: drop unused includes 2025-12-25 18:42:54 +01:00
tool_setup.h build: drop stray ifndef guards for local/internal macros 2026-01-14 12:53:14 +01:00
tool_ssls.c source: misc typos 2026-01-01 12:43:59 +01:00
tool_ssls.h src: drop unused includes 2025-12-25 18:42:54 +01:00
tool_stderr.c tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_stderr.h tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_strdup.c build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_strdup.h build: stop overriding standard memory allocation functions 2025-11-28 10:44:26 +01:00
tool_urlglob.c tool: improve error/warning messages when output filename sanitization fails 2026-01-10 13:21:27 +01:00
tool_urlglob.h tool: improve error/warning messages when output filename sanitization fails 2026-01-10 13:21:27 +01:00
tool_util.c src: fix formatting nits 2025-12-03 20:50:18 +01:00
tool_util.h build: drop Windows CE / CeGCC support 2025-11-15 15:35:23 +01:00
tool_version.h src: fix formatting nits 2025-12-03 20:50:18 +01:00
tool_vms.c src: fix formatting nits 2025-12-03 20:50:18 +01:00
tool_vms.h src: fix formatting nits 2025-12-03 20:50:18 +01:00
tool_writeout.c build: drop global suppression of -Wformat-nonliteral, fix fallouts 2026-01-20 12:38:02 +01:00
tool_writeout.h tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_writeout_json.c tidy-up: miscellaneous 2025-12-18 21:27:58 +01:00
tool_writeout_json.h tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_xattr.c tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00
tool_xattr.h src: fix formatting nits 2025-12-03 20:50:18 +01:00
var.c src: drop unused includes 2025-12-25 18:42:54 +01:00
var.h tidy-up: miscellaneous 2025-12-26 22:06:09 +01:00