~emersion/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
4 2

basu: fails to link with LLD 13

Evgeniy Khramtsov
Details
Message ID
<CANvPQf_5qOdfbe4Tk029yVB6BHipmYfQnuuCVoTUv3N=2f8jfw@mail.gmail.com>
DKIM signature
pass
Download raw message
Hi.

FreeBSD 14 -CURRENT, devel/llvm13 from ports as toolchain, fails to link basu:

ld: error: undefined symbol: __start_BUS_ERROR_MAP
>>> referenced by bus-error.c
>>>               sd-bus_bus-error.c.o:(bus_error_name_to_errno) in archive src/libsystemd/libsystemd_static.a

ld: error: undefined symbol: __stop_BUS_ERROR_MAP
>>> referenced by bus-error.c
>>>               sd-bus_bus-error.c.o:(bus_error_name_to_errno) in archive src/libsystemd/libsystemd_static.a
>>> referenced by bus-error.c
>>>               sd-bus_bus-error.c.o:(bus_error_name_to_errno) in archive src/libsystemd/libsystemd_static.a
clang-13: error: linker command failed with exit code 1 (use -v to see
invocation)

I tried to fix this (WIP where I stopped attached), but test-bus-error fails at:
<26>(../src/libsystemd/sd-bus/test-bus-error.c:184) Assertion
'sd_bus_error_set(NULL, "org.freedesktop.custom-dbus-error-2", NULL)
== -52' failed at ../src/libsystemd/sd-bus/test-bus-error.c:184,
function void test_errno_mapping_custom(void)(). Aborting.
test-bus-error.c:
        test_error(); (OK)
        test_errno_mapping_standard(); (OK)
        test_errno_mapping_custom(); (Fail here)
Details
Message ID
<ZQ1ZM_VCiTfKD5yQlUA8Gt0-pN6BFbD3FflMtrS674Yt952ukJkkb-i8k68Y1lwVmmFVzdCb1VZsEmwYYkvVMcPgoy7Pacz_xfT7p6_GdBc=@emersion.fr>
In-Reply-To
<CANvPQf_5qOdfbe4Tk029yVB6BHipmYfQnuuCVoTUv3N=2f8jfw@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
Maybe try dropping BUS_ERROR_MAP_ELF_REGISTER, and try doing something like:

    const sd_bus_error_map *__stop_BUS_ERROR_MAP = (void *)((char *)bus_standard_errors + sizeof(bus_standard_errors))
Evgeniy Khramtsov
Details
Message ID
<CANvPQf9XE71b1nEiSeWen77xKKLrd-eiYnJ+-xv1z=KGexvbQw@mail.gmail.com>
In-Reply-To
<ZQ1ZM_VCiTfKD5yQlUA8Gt0-pN6BFbD3FflMtrS674Yt952ukJkkb-i8k68Y1lwVmmFVzdCb1VZsEmwYYkvVMcPgoy7Pacz_xfT7p6_GdBc=@emersion.fr> (view parent)
DKIM signature
pass
Download raw message
Upstream solution: https://github.com/systemd/systemd/commit/945317a4b.patch
It does not apply cleanly to basu, version that applies cleanly is attached.

> Maybe try dropping BUS_ERROR_MAP_ELF_REGISTER, and try doing something like:

Thanks for help. The assert still trips, more change needed if one
wants to drop BUS_ERROR_MAP_ELF_REGISTER. I am not sure if it is worth
diverging from upstream.

(Sent twice, forgot to add CC to the first mail)

On Wed, Oct 6, 2021 at 11:53 AM Simon Ser <contact@emersion.fr> wrote:
>
> Maybe try dropping BUS_ERROR_MAP_ELF_REGISTER, and try doing something like:
>
>     const sd_bus_error_map *__stop_BUS_ERROR_MAP = (void *)((char *)bus_standard_errors + sizeof(bus_standard_errors))
Details
Message ID
<Pr1JnR3H3u82KHWqZjBtaxfRBWbCMWV0Llc0fP7tYUVU37KsadobDfLa7Bn5ZHjmQssErwo5dPvImESa6lgIiPnyaPRZEWuG4nINmv4MuJU=@emersion.fr>
In-Reply-To
<CANvPQf9XE71b1nEiSeWen77xKKLrd-eiYnJ+-xv1z=KGexvbQw@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
Can you send this with git-send-email?

[PATCH] sd-bus: set retain attribute on BUS_ERROR_MAP_ELF_REGISTER

Evgeniy Khramtsov
Details
Message ID
<20211126130403.22303-1-evgeniy@khramtsov.org>
In-Reply-To
<Pr1JnR3H3u82KHWqZjBtaxfRBWbCMWV0Llc0fP7tYUVU37KsadobDfLa7Bn5ZHjmQssErwo5dPvImESa6lgIiPnyaPRZEWuG4nINmv4MuJU=@emersion.fr> (view parent)
DKIM signature
pass
Download raw message
Patch: +6 -0
From: Fangrui Song <i@maskray.me>

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
```

Co-authored-by: Evgeniy Khramtsov <evgeniy@khramtsov.org>
---
 src/libsystemd/sd-bus/bus-error.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/libsystemd/sd-bus/bus-error.h b/src/libsystemd/sd-bus/bus-error.h
index 06c478a..883213f 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\"")              \
        __attribute__ ((__section__("BUS_ERROR_MAP")))                  \
        __attribute__ ((__used__))                                      \
        __attribute__ ((retain))                                        \
        __attribute__ ((aligned(8)))

#define BUS_ERROR_MAP_ELF_USE(errors)                                   \
-- 
2.34.1
Reply to thread Export thread (mbox)