Re: [PATCH] H8: Add support for preinit/init/fini array

Jeff Johnston <[email protected]> Tue, 14 Jul 2026 19:36:08 -0400
Newsgroups gmane.comp.lib.newlib
Message-ID <CAOox84vhR4PP0a_8wQxFfadNdrzCHTjo0G5avpPYHnucKmfgTA@mail.gmail.com>
--00000000000090b36906569aac2f
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Patch merged.

-- Jeff J.

On Sun, Jul 12, 2026 at 4:09=E2=80=AFPM Jan Dubiec <[email protected]> wrote:

> This patch adds support for .preinit_array, .init_array, and .fini_array
> for the H8 family when binutils and GCC are configured with
> "--enable-initfini-array".
>
> The changes to init.c and fini.c ensure that linker-defined symbols
> referenced from C code are not affected by target-specific symbol naming
> conventions. For example, GCC for H8 prefixes external symbol names with
> an underscore, whereas GCC for ARM does not. The asm keyword is used to
> associate C identifiers with the corresponding linker-defined symbol name=
s
> in a target-independent manner.
>
> The patch has been tested on H8 wher it enables support for the
> initialization and finalization arrays and on ARM in order to verify that
> the changes do not introduce any regressions.
>
> Signed-off-by: Jan Dubiec <[email protected]>
> ---
>  newlib/libc/misc/fini.c         |  6 ++++--
>  newlib/libc/misc/init.c         | 12 ++++++++----
>  newlib/libc/sys/h8300hms/crt0.S |  6 ++++++
>  3 files changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/newlib/libc/misc/fini.c b/newlib/libc/misc/fini.c
> index 5f2016070..0c3a1e0d5 100644
> --- a/newlib/libc/misc/fini.c
> +++ b/newlib/libc/misc/fini.c
> @@ -14,8 +14,10 @@
>  #include <sys/types.h>
>
>  #ifdef _HAVE_INITFINI_ARRAY
> -extern void (*__fini_array_start []) (void) __attribute__((weak));
> -extern void (*__fini_array_end []) (void) __attribute__((weak));
> +extern void (*__fini_array_start []) (void) asm("__fini_array_start")
> +       __attribute__((weak));
> +extern void (*__fini_array_end []) (void) asm("__fini_array_end")
> +       __attribute__((weak));
>
>  #ifdef _HAVE_INIT_FINI
>  extern void _fini (void);
> diff --git a/newlib/libc/misc/init.c b/newlib/libc/misc/init.c
> index 3aef7ad06..5781535f9 100644
> --- a/newlib/libc/misc/init.c
> +++ b/newlib/libc/misc/init.c
> @@ -16,10 +16,14 @@
>  #ifdef _HAVE_INITFINI_ARRAY
>
>  /* These magic symbols are provided by the linker.  */
> -extern void (*__preinit_array_start []) (void) __attribute__((weak));
> -extern void (*__preinit_array_end []) (void) __attribute__((weak));
> -extern void (*__init_array_start []) (void) __attribute__((weak));
> -extern void (*__init_array_end []) (void) __attribute__((weak));
> +extern void (*__preinit_array_start []) (void)
> asm("__preinit_array_start")
> +       __attribute__((weak));
> +extern void (*__preinit_array_end []) (void) asm("__preinit_array_end")
> +       __attribute__((weak));
> +extern void (*__init_array_start []) (void) asm("__init_array_start")
> +       __attribute__((weak));
> +extern void (*__init_array_end []) (void) asm("__init_array_end")
> +       __attribute__((weak));
>
>  #ifdef _HAVE_INIT_FINI
>  extern void _init (void);
> diff --git a/newlib/libc/sys/h8300hms/crt0.S
> b/newlib/libc/sys/h8300hms/crt0.S
> index 757fb0477..020b957d6 100644
> --- a/newlib/libc/sys/h8300hms/crt0.S
> +++ b/newlib/libc/sys/h8300hms/crt0.S
> @@ -1,6 +1,12 @@
>  ; H8/300, H8/300H, H8/300S and H8SX start up file.
>
>  #include "setarch.h"
> +#include "newlib.h"
> +
> +#ifdef _HAVE_INITFINI_ARRAY
> +#define __init ___libc_init_array
> +#define __fini ___libc_fini_array
> +#endif
>
>  #ifdef __H8300__
>
> --
> 2.54.0
>
>

--00000000000090b36906569aac2f
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-family:verdana,=
sans-serif">Patch merged.</div><div class=3D"gmail_default" style=3D"font-f=
amily:verdana,sans-serif"><br></div><div class=3D"gmail_default" style=3D"f=
ont-family:verdana,sans-serif">-- Jeff J.</div></div><br><div class=3D"gmai=
l_quote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Sun=
, Jul 12, 2026 at 4:09=E2=80=AFPM Jan Dubiec &lt;<a href=3D"mailto:[email protected]=
l">[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddin=
g-left:1ex">This patch adds support for .preinit_array, .init_array, and .f=
ini_array<br>
for the H8 family when binutils and GCC are configured with &quot;--enable-=
initfini-array&quot;.<br>
<br>
The changes to init.c and fini.c ensure that linker-defined symbols<br>
referenced from C code are not affected by target-specific symbol naming<br=
>
conventions. For example, GCC for H8 prefixes external symbol names with<br=
>
an underscore, whereas GCC for ARM does not. The asm keyword is used to<br>
associate C identifiers with the corresponding linker-defined symbol names<=
br>
in a target-independent manner.<br>
<br>
The patch has been tested on H8 wher it enables support for the<br>
initialization and finalization arrays and on ARM in order to verify that<b=
r>
the changes do not introduce any regressions.<br>
<br>
Signed-off-by: Jan Dubiec &lt;<a href=3D"mailto:[email protected]" target=3D"_blank=
">[email protected]</a>&gt;<br>
---<br>
=C2=A0newlib/libc/misc/fini.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0 6 ++=
++--<br>
=C2=A0newlib/libc/misc/init.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 12 +++++++=
+----<br>
=C2=A0newlib/libc/sys/h8300hms/crt0.S |=C2=A0 6 ++++++<br>
=C2=A03 files changed, 18 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/newlib/libc/misc/fini.c b/newlib/libc/misc/fini.c<br>
index 5f2016070..0c3a1e0d5 100644<br>
--- a/newlib/libc/misc/fini.c<br>
+++ b/newlib/libc/misc/fini.c<br>
@@ -14,8 +14,10 @@<br>
=C2=A0#include &lt;sys/types.h&gt;<br>
<br>
=C2=A0#ifdef _HAVE_INITFINI_ARRAY<br>
-extern void (*__fini_array_start []) (void) __attribute__((weak));<br>
-extern void (*__fini_array_end []) (void) __attribute__((weak));<br>
+extern void (*__fini_array_start []) (void) asm(&quot;__fini_array_start&q=
uot;)<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0__attribute__((weak));<br>
+extern void (*__fini_array_end []) (void) asm(&quot;__fini_array_end&quot;=
)<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0__attribute__((weak));<br>
<br>
=C2=A0#ifdef _HAVE_INIT_FINI<br>
=C2=A0extern void _fini (void);<br>
diff --git a/newlib/libc/misc/init.c b/newlib/libc/misc/init.c<br>
index 3aef7ad06..5781535f9 100644<br>
--- a/newlib/libc/misc/init.c<br>
+++ b/newlib/libc/misc/init.c<br>
@@ -16,10 +16,14 @@<br>
=C2=A0#ifdef _HAVE_INITFINI_ARRAY<br>
<br>
=C2=A0/* These magic symbols are provided by the linker.=C2=A0 */<br>
-extern void (*__preinit_array_start []) (void) __attribute__((weak));<br>
-extern void (*__preinit_array_end []) (void) __attribute__((weak));<br>
-extern void (*__init_array_start []) (void) __attribute__((weak));<br>
-extern void (*__init_array_end []) (void) __attribute__((weak));<br>
+extern void (*__preinit_array_start []) (void) asm(&quot;__preinit_array_s=
tart&quot;)<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0__attribute__((weak));<br>
+extern void (*__preinit_array_end []) (void) asm(&quot;__preinit_array_end=
&quot;)<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0__attribute__((weak));<br>
+extern void (*__init_array_start []) (void) asm(&quot;__init_array_start&q=
uot;)<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0__attribute__((weak));<br>
+extern void (*__init_array_end []) (void) asm(&quot;__init_array_end&quot;=
)<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0__attribute__((weak));<br>
<br>
=C2=A0#ifdef _HAVE_INIT_FINI<br>
=C2=A0extern void _init (void);<br>
diff --git a/newlib/libc/sys/h8300hms/crt0.S b/newlib/libc/sys/h8300hms/crt=
0.S<br>
index 757fb0477..020b957d6 100644<br>
--- a/newlib/libc/sys/h8300hms/crt0.S<br>
+++ b/newlib/libc/sys/h8300hms/crt0.S<br>
@@ -1,6 +1,12 @@<br>
=C2=A0; H8/300, H8/300H, H8/300S and H8SX start up file.<br>
<br>
=C2=A0#include &quot;setarch.h&quot;<br>
+#include &quot;newlib.h&quot;<br>
+<br>
+#ifdef _HAVE_INITFINI_ARRAY<br>
+#define __init ___libc_init_array<br>
+#define __fini ___libc_fini_array<br>
+#endif<br>
<br>
=C2=A0#ifdef __H8300__<br>
<br>
-- <br>
2.54.0<br>
<br>
</blockquote></div>

--00000000000090b36906569aac2f--