cmake: add CURL_DROP_UNUSED option to reduce binary sizes#20357
cmake: add CURL_DROP_UNUSED option to reduce binary sizes#20357vszakats wants to merge 29 commits intocurl:masterfrom
CURL_DROP_UNUSED option to reduce binary sizes#20357Conversation
Open puzzle: MinGW/MSYS2/Cygwin: Binary size grows. I haven't seen this before, ATM I think that enabling this automatically with unity is perhaps overkill. The same could probably be done for autotools. |
|
The problem with MinGW is that gcc and bfd only support ELF section groups and cannot handle COFF COMDAT correctly, so gc-sections won't work. |
What could be the reason that it works in curl-for-win?: gcc without https://github.com/curl/curl-for-win/actions/runs/21143631016/job/60803714998#step:3:6957 vs. gcc with https://github.com/curl/curl-for-win/actions/runs/21169943310/job/60885143940#step:3:6959 same with clang: 4127232 bytes vs 3599872. |
https://sourceware.org/bugzilla/show_bug.cgi?id=11539#c19 https://github.com/curl/curl-for-win/blob/71bc883caa89b394171677df05c5376e64056a60/_build.sh#L1091 |
…-tables` [ci skip] curl/curl#20357 (comment) Thanks-to: @Andarwinux Follow-up to ce5113a
|
Nice! Thanks @Andarwinux! With Is there any concerning property of this option? Would be safe to enable it Also perhaps these options should be applied to the curl binary and libcurl |
|
correction: Fil-C and non-unity also get reduces sizes. (I forgot that I enabled the option only for unity builds initially!) correction 2: MSVC MSBuild jobs also seem some great improvements, but not all of them. Sill looking for the explanation. |
If there isn't anything that uses setjmp/longjmp it's safe, otherwise I'm not sure. |
curl uses |
CI is green, so it should be fine? If there is a problem, curl is supposed to crash. |
curl-for-win had this enabled for 3 years with no issues. I'm rather just wondering |
|
|
Unstripped size hides effective binary sizes due to the added debug information. E.g. `--gc-sections` may inflate unstripped binaries, while their unstripped size decreases. To see if binary size optimization options work, it's more useful to observe unstripped size. Ref: #20357 Follow-up to 4cf4350 #20355 Closes #20359
754da61 to
e04618e
Compare
It is only used for synchronous name resolves on platforms with alarm(), which is not the regular Windows builds... |
To enable known linker options dropping dead code and data from the binaries built. Enabled by default for "unity" builds. Supported platforms: Apple, MSVC, llvm/clang and GCC.
to save build footprint and max out performance by avoiding them for test libraries.
CURL_PURGE_UNUSED optionCURL_PURGE_UNUSED option to reduce binary sizes
CURL_PURGE_UNUSED option to reduce binary sizesCURL_STRIP_UNUSED option to reduce binary sizes
CURL_STRIP_UNUSED option to reduce binary sizesCURL_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:
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.
The curl build option has no effect on it.
-fno-asynchronous-unwind-tablesas a workaround to makethe 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:
curl: 2000000 -> 1937152, libcurl.a: 2065724 -> 2716532 bytes
curl: 1364376 -> 128799 bytes, libcurl.a: unchanged
curl: 410056 -> 405720, libcurl.dylib: 1350336 -> 1348480 bytes
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:
curl: 2339840 -> 1295872, libcurl-d.dll: 3155968 -> 1900544 bytes
bld: 161 -> 97MB
curl: 2933248 -> 2332160, libcurl-d.lib: 4762688 -> 5511330 bytes
bld: 133 -> 121MB
curl: 3514368 -> 2177024, libcurl-d.lib: 2538420 -> 3151740 bytes
bld: 137 -> 83MB
curl: 2629120 -> 2023424, libcurl-d.lib: 4366652 -> 5350670 bytes
bld: 86 -> 69MB
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
CMake jobs only:
no effect(it wasn't enabled!). significant size reduction.no effect on curl exe, the static lib is larger by 52 bytes(doh, wasn't enabled!). It does have size improvements./Gyand/OPT:REFFor VS2010 I found that only the first had an effect in CI.
potentially more CPU use. No observable downside in CI or locally.
Before:
https://ci.appveyor.com/project/curlorg/curl/builds/53395645
https://github.com/curl/curl/actions/runs/21142250302 Windows (gcc/clang stripped)
https://github.com/curl/curl/actions/runs/21138785324 Linux
https://github.com/curl/curl/actions/runs/21138785297 Linux H3
https://github.com/curl/curl/actions/runs/21138785306 macOS
https://github.com/curl/curl/actions/runs/21142863929?pr=20359 non-native (Android/MS-DOS stripped)
After 1.:
https://github.com/curl/curl/actions/runs/21139220699/job/60788722271?pr=20357
https://github.com/curl/curl/actions/runs/21172575934/job/60892756697?pr=20357