On 07/09/2026 14:45, Pádraig Brady wrote:
test-sd-dlopen fails to link (on cfarm13) due to: https://sourceware.org/bugzilla/show_bug.cgi?id=26256Note coreutils' sort does not mix ordered and unordered, so does not hit the same build issue. Do we really want to support mixing these, or would split out test binaries for each suffice?
I'm thinking an AC_LINK_IFELSE check is appropriate to test for this and possibly other link errors like already mentioned for LLVM < 18? The attached works on cfarm13 at least. cheers, Padraig
From 04038857463f040966bbbb97ced2e29026c4af29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]> Date: Mon, 7 Sep 2026 15:24:02 +0100 Subject: [PATCH] sd-dlopen: fix build failure with binutils-2.35 This was noticed on Debian 11 with binutils 2.35.2 which does not have the following fix: https://sourceware.org/bugzilla/show_bug.cgi?id=26256 * m4/sd-dlopen.m4 (gl_SD_DLOPEN): Do a link test to ensure the linker supports ordered and unordered sections. * lib/sd-dlopen.h (SD_ELF_NOTE_DLOPEN_ANCHORED): Fallback to a non-anchored note where not supported. --- ChangeLog | 8 ++++++++ lib/sd-dlopen.h | 6 ++++-- m4/sd-dlopen.m4 | 51 +++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index f36c2c1791..1b133e3c9f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2026-09-07 Pádraig Brady <[email protected]> + + sd-dlopen: fix build failure with binutils-2.35 + * m4/sd-dlopen.m4 (gl_SD_DLOPEN): Do a link test to + ensure the linker supports ordered and unordered sections. + * lib/sd-dlopen.h (SD_ELF_NOTE_DLOPEN_ANCHORED): Fallback to a + non-anchored note where not supported. + 2026-09-06 Paul Eggert <[email protected]> regex: pacify GCC 16 -Wuseless-cast diff --git a/lib/sd-dlopen.h b/lib/sd-dlopen.h index 24ee8aa517..e999f6359b 100644 --- a/lib/sd-dlopen.h +++ b/lib/sd-dlopen.h @@ -203,8 +203,10 @@ extern "C" { #define SD_ELF_NOTE_DLOPEN(feature, description, priority, ...) \ _SD_ELF_NOTE_DLOPEN(_SD_DLOPEN_JSON(feature, description, priority, __VA_ARGS__)) -/* The anchored note requires LLVM >= 18 (see above). Fall back to the non-anchored note on older clang. */ -#if (defined(__clang__) ? defined(__apple_build_version__) || __clang_major__ >= 18 : _SD_ELF_NOTE_SUPPORTS_REFERENCES) +/* Fall back to the non-anchored note when the configured toolchain cannot + * link it alongside an ordinary note. */ +#if defined _SD_ELF_NOTE_SUPPORTS_REFERENCES \ + && _SD_ELF_NOTE_SUPPORTS_REFERENCES # define SD_ELF_NOTE_DLOPEN_ANCHORED(tag, feature, description, priority, ...) \ _SD_ELF_NOTE_DLOPEN_ANCHORED(tag, _SD_DLOPEN_JSON(feature, description, priority, __VA_ARGS__)) #else diff --git a/m4/sd-dlopen.m4 b/m4/sd-dlopen.m4 index 1b84836cb2..6dc38f8ab7 100644 --- a/m4/sd-dlopen.m4 +++ b/m4/sd-dlopen.m4 @@ -1,5 +1,5 @@ # sd-dlopen.m4 -# serial 4 +# serial 5 dnl Copyright (C) 2026 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -38,8 +38,55 @@ __asm__ (".ifndef \"gl_sd_dlopen_test\"\n" [gl_cv_asm_section_o=yes], [gl_cv_asm_section_o=no])]) if test $gl_cv_asm_section_o = yes; then + AC_CACHE_CHECK( + [whether ordered and unordered ELF sections can be linked], + [gl_cv_elf_mixed_ordered_sections], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[ +extern volatile const unsigned char gl_sd_dlopen_unordered; +extern volatile const unsigned char gl_sd_dlopen_anchor; + +__asm__ ( + ".pushsection .note.dlopen, \"aG\", %note," + " gl_sd_dlopen_unordered_group, comdat\n" + ".globl gl_sd_dlopen_unordered\n" + ".hidden gl_sd_dlopen_unordered\n" + ".type gl_sd_dlopen_unordered, %object\n" + "gl_sd_dlopen_unordered:\n" + ".balign 4\n" + ".long 0, 0, 0\n" + ".popsection\n" + + ".pushsection .data.gl_sd_dlopen_anchor, \"awG\", %progbits," + " gl_sd_dlopen_ordered_group, comdat\n" + ".globl gl_sd_dlopen_anchor\n" + ".hidden gl_sd_dlopen_anchor\n" + ".type gl_sd_dlopen_anchor, %object\n" + "gl_sd_dlopen_anchor:\n" + ".byte 0\n" + ".popsection\n" + + ".pushsection .note.dlopen, \"aGo\", %note," + " gl_sd_dlopen_anchor, gl_sd_dlopen_ordered_group, comdat\n" + ".balign 4\n" + ".long 0, 0, 0\n" + ".popsection\n"); + ]], + [[ +volatile unsigned int gl_sink = + gl_sd_dlopen_unordered + gl_sd_dlopen_anchor; +(void) gl_sink; + ]])], + [gl_cv_elf_mixed_ordered_sections=yes], + [gl_cv_elf_mixed_ordered_sections=no])]) + else + gl_cv_elf_mixed_ordered_sections=no + fi + if test $gl_cv_elf_mixed_ordered_sections = yes; then AC_DEFINE([_SD_ELF_NOTE_SUPPORTS_REFERENCES], [1], - [Define to 1 if the ELF .section command supports the o flag.]) + [Define to 1 if SHF_LINK_ORDER notes can be linked alongside + ordinary notes of the same name.]) fi AC_CACHE_CHECK([whether the assembler supports the section flag R], -- 2.55.0
