Re: [PATCH] H8: Add support for preinit/init/fini array
Hans-Peter Nilsson <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
> From: Jan Dubiec <[email protected]> > Date: Sun, 12 Jul 2026 21:54:53 +0200 > 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". To accomplish that, there should have been a fix to binutils, per below. Instead, this patch broke initfini support for targets with a USER_LABEL_PREFIX, like cris-elf. I was alerted to this commit when people tried to use newlib master with cris-elf in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126518 > 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 names > 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. Since ARM isn't a USER_LABEL_PREFIX-target, your patch was neutral there. While testing the patch there too makes sense, that target wasn't in the cross-hairs; it didn't change the symbols. The parts of this patch to the generic files, should be reverted. Instead I suggest to correct binutils for h8300 to emit the "_" as a prefix to those linker-generated initfini-symbols in the default linker scripts, something like: diff --git a/ld/emulparams/h8300elf.sh b/ld/emulparams/h8300elf.sh index 45b3458d1cea..dd007fcd0ffc 100644 --- a/ld/emulparams/h8300elf.sh +++ b/ld/emulparams/h8300elf.sh @@ -9,6 +9,7 @@ MAXPAGESIZE=2 TARGET_PAGE_SIZE=128 ARCH=h8300 TEMPLATE_NAME=elf +USER_LABEL_PREFIX=_ EMBEDDED=yes STACK_ADDR=0xfefc TINY_READONLY_SECTION=".tinyrodata : (cf. emulparams/criself.sh and ld/scripttempl/elf.sc) That might of course have fallout for other symbols defined in those scripts, but would align with other targets (no special defines or asm-renames needed). brgds, H-P