summaryrefslogtreecommitdiff
blob: d20909f4eaa54265c129372084280b7047dd7049 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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 <federico@gnome.org>
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: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/832>
--- 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