View | Details | Raw Unified | Return to bug 258812 | Differences between
and this patch

Collapse All | Expand All

(-)b/devel/basu/files/patch-attribute-retain (-1 / +48 lines)
Added Link Here
0
- 
1
From 96ae9eb8abf5dc4b0686151142fe65b34ab45896 Mon Sep 17 00:00:00 2001
2
From: Fangrui Song <i@maskray.me>
3
Date: Sun, 28 Mar 2021 23:35:06 -0700
4
Subject: [PATCH] sd-bus: set retain attribute on BUS_ERROR_MAP_ELF_REGISTER
5
6
LLD 13 and GNU ld 2.37 support -z start-stop-gc which allows garbage
7
collection of C identifier name sections despite the __start_/__stop_
8
references.  Simply set the retain attribute so that GCC 11 (if
9
configure-time binutils is 2.36 or newer)/Clang 13 will set the
10
SHF_GNU_RETAIN section attribute to prevent garbage collection.
11
12
Without the patch, there are linker errors like the following with -z
13
start-stop-gc.
14
15
```
16
ld: error: undefined symbol: __start_SYSTEMD_BUS_ERROR_MAP
17
>>> referenced by bus-error.c:93 (../src/libsystemd/sd-bus/bus-error.c:93)
18
>>>               sd-bus_bus-error.c.o:(bus_error_name_to_errno) in archive src/libsystemd/libsystemd_static.a
19
```
20
---
21
 src/libsystemd/sd-bus/bus-error.h | 6 ++++++
22
 1 file changed, 6 insertions(+)
23
24
diff --git src/libsystemd/sd-bus/bus-error.h src/libsystemd/sd-bus/bus-error.h
25
index 06c478a..883213f 100644
26
--- src/libsystemd/sd-bus/bus-error.h
27
+++ src/libsystemd/sd-bus/bus-error.h
28
@@ -28,11 +28,17 @@ int bus_error_set_errnofv(sd_bus_error *e, int error, const char *format, va_lis
29
  * the bus error table, and BUS_ERROR_MAP_ELF_USE has to be used at
30
  * least once per compilation unit (i.e. per library), to ensure that
31
  * the error map is really added to the final binary.
32
+ *
33
+ * In addition, set the retain attribute so that the section cannot be
34
+ * discarded by ld --gc-sections -z start-stop-gc. Older compilers would
35
+ * warn for the unknown attribute, so just disable -Wattributes.
36
  */
37
 
38
 #define BUS_ERROR_MAP_ELF_REGISTER                                      \
39
+        _Pragma("GCC diagnostic ignored \"-Wattributes\"")              \
40
         __attribute__ ((__section__("BUS_ERROR_MAP")))                  \
41
         __attribute__ ((__used__))                                      \
42
+        __attribute__ ((retain))                                        \
43
         __attribute__ ((aligned(8)))
44
 
45
 #define BUS_ERROR_MAP_ELF_USE(errors)                                   \
46
-- 
47
2.32.0
48

Return to bug 258812