[PATCH] h8300-elf: ld: Use USER_LABEL_PREFIX when generating linker scripts.

Jan Dubiec <[email protected]>
Newsgroups gmane.comp.gnu.binutils
Message-ID <[email protected]>
This patch is a spin-off of the following thread: https://inbox.sourceware.org/newlib/CAOox84s_SjpbEZsAx9EprDrTxB-bT0pgbavt8NXY7iiph8h6Vg@mail.gmail.com/T/#t .

Gcc sets USER_LABEL_PREFIX: https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/h8300/elf.h;hb=HEAD .
Strangely, ld does not. As a result, ld exports a symbol without a leading
underscore, while gcc expects the symbol to have one. For example:

linker scirpt:
[...]
PROVIDE_HIDDEN (__preinit_array_start = .);
[...]

C source code (the compiler adds 3rd underscore):
[...]
extern void (*__preinit_array_start []) (void) __attribute__((weak));
[...]

This can lead to sneaky bugs when the symbol is declared as weak. It also
creates maintenance issues when the C code is intended to be multiplatform.

Signed-off-by: Jan Dubiec <[email protected]>
---
 ld/emulparams/h8300elf.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ld/emulparams/h8300elf.sh b/ld/emulparams/h8300elf.sh
index 45b3458d1ce..cb85989e2db 100644
--- a/ld/emulparams/h8300elf.sh
+++ b/ld/emulparams/h8300elf.sh
@@ -9,7 +9,9 @@ MAXPAGESIZE=2
 TARGET_PAGE_SIZE=128
 ARCH=h8300
 TEMPLATE_NAME=elf
+USER_LABEL_PREFIX=_
 EMBEDDED=yes
+ENTRY=_start
 STACK_ADDR=0xfefc
 TINY_READONLY_SECTION=".tinyrodata :
   {
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.