summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2021-03-28 23:35:06 -0700
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-03-29 12:31:42 +0200
commit945317a4b69d33752c9513bb8994fe8d5a786ea6 (patch)
tree8efd1da75ac11277d9bd7e924ba560c420000d33
parent8a773a30ba622faf62e4313b0add25808a2b4df9 (diff)
downloadsystemd-945317a4b69d33752c9513bb8994fe8d5a786ea6.tar.gz
sd-bus: set retain attribute on BUS_ERROR_MAP_ELF_REGISTER
LLD 13 and GNU ld 2.37 support -z start-stop-gc which allows garbage collection of C identifier name sections despite the __start_/__stop_ references. Simply set the retain attribute so that GCC 11 (if configure-time binutils is 2.36 or newer)/Clang 13 will set the SHF_GNU_RETAIN section attribute to prevent garbage collection. Without the patch, there are linker errors like the following with -z start-stop-gc. ``` ld: error: undefined symbol: __start_SYSTEMD_BUS_ERROR_MAP >>> referenced by bus-error.c:93 (../src/libsystemd/sd-bus/bus-error.c:93) >>> sd-bus_bus-error.c.o:(bus_error_name_to_errno) in archive src/libsystemd/libsystemd_static.a ```
-rw-r--r--src/libsystemd/sd-bus/bus-error.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/libsystemd/sd-bus/bus-error.h b/src/libsystemd/sd-bus/bus-error.h
index 557284faf8..d981f72449 100644
--- a/src/libsystemd/sd-bus/bus-error.h
+++ b/src/libsystemd/sd-bus/bus-error.h
@@ -28,11 +28,17 @@ int bus_error_set_errnofv(sd_bus_error *e, int error, const char *format, va_lis
* the bus error table, and BUS_ERROR_MAP_ELF_USE has to be used at
* least once per compilation unit (i.e. per library), to ensure that
* the error map is really added to the final binary.
+ *
+ * In addition, set the retain attribute so that the section cannot be
+ * discarded by ld --gc-sections -z start-stop-gc. Older compilers would
+ * warn for the unknown attribute, so just disable -Wattributes.
*/
#define BUS_ERROR_MAP_ELF_REGISTER \
+ _Pragma("GCC diagnostic ignored \"-Wattributes\"") \
_section_("SYSTEMD_BUS_ERROR_MAP") \
_used_ \
+ __attribute__((retain)) \
_alignptr_ \
_variable_no_sanitize_address_