https://gitlab.gnome.org/GNOME/librsvg/-/issues/965 https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/832 https://github.com/rust-lang/rust/issues/111593 From 61bba147f65019eab2a42148065798bc568169ab Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Thu, 18 May 2023 17:57:01 -0600 Subject: [PATCH] (#965): Shrink the shared library by telling the linker to omit unused code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to Sebastian Dröge for spotting this. Fixes https://gitlab.gnome.org/GNOME/librsvg/-/issues/965 Part-of: --- a/Makefile.am +++ b/Makefile.am @@ -217,12 +217,24 @@ librsvg_@RSVG_API_MAJOR_VERSION@_la_CPPFLAGS = $(AM_CPPFLAGS) librsvg_@RSVG_API_MAJOR_VERSION@_la_CFLAGS = $(AM_CFLAGS) -librsvg_@RSVG_API_MAJOR_VERSION@_la_LDFLAGS = \ - $(BSYMBOLIC_LDFLAG) \ - -version-info @RSVG_LT_VERSION_INFO@ \ - -export-dynamic \ - -no-undefined \ - -export-symbols-regex "^rsvg_.*" \ +# This is not strictly needed, but since we are telling Cargo to build a staticlib, it puts in +# all of Rust's standard library and code from dependencies even when it is not needed. +# With the following, we shrink the final .so size; see issue #965. +# +# This will no longer be needed when we switch to cargo-cbuild, which does this automatically. +if OS_DARWIN +gc_linked_library_args="-Wl,-dead_strip" +else +gc_linked_library_args="-Wl,--gc-sections" +endif + +librsvg_@RSVG_API_MAJOR_VERSION@_la_LDFLAGS = \ + $(BSYMBOLIC_LDFLAG) \ + -version-info @RSVG_LT_VERSION_INFO@ \ + -export-dynamic \ + -no-undefined \ + -export-symbols-regex "^rsvg_.*" \ + $(gc_linked_library_args) \ $(AM_LDFLAGS) if OS_DARWIN -- GitLab