[binutils-gdb] ld: testsuite: Associate C identifiers with symbols

Alan Modra via Binutils-cvs <[email protected]> Sun, 19 Jul 2026 05:28:31 +0000 (GMT)
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D0e4e6037429c=
d5df3de62f6e373955c0d3b85533

commit 0e4e6037429cd5df3de62f6e373955c0d3b85533
Author: Jan Dubiec <[email protected]>
Date:   Sat Jul 18 09:52:54 2026 +0200

    ld: testsuite: Associate C identifiers with symbols
   =20
    Some targets prepend an underscore to C identifier, while others do
    not (e.g. H8 vs. ARM). This can cause problems in two situations:
       1. when linking C and assembly code;
       2. when a symbol name is specified on the linker's command line.
   =20
    This patch resolves both issues by using the asm keyword to associate C
    identifiers with the corresponding assembler/linker symbol names in a
    target-independent manner.
   =20
    Signed-off-by: Jan Dubiec <[email protected]>

Diff:
---
 ld/testsuite/ld-elf/merge4a.c  | 4 ++--
 ld/testsuite/ld-gc/pr13683.c   | 6 +++---
 ld/testsuite/ld-gc/pr19161-1.c | 1 +
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/ld/testsuite/ld-elf/merge4a.c b/ld/testsuite/ld-elf/merge4a.c
index 133303e11ac..d050c30702a 100644
--- a/ld/testsuite/ld-elf/merge4a.c
+++ b/ld/testsuite/ld-elf/merge4a.c
@@ -1,8 +1,8 @@
 extern const char * getstr3(int);
 extern int printf (const char *, ...);
=20
-extern const char *addr_of_str;
-extern const char *addr_of_str2;
+extern const char *addr_of_str asm("addr_of_str");
+extern const char *addr_of_str2 asm("addr_of_str2");
=20
 /* "foobar" needs to be a string literal, so that it's put into
    a mergable string section, then merged with the "foobar" from merge4b.s
diff --git a/ld/testsuite/ld-gc/pr13683.c b/ld/testsuite/ld-gc/pr13683.c
index f8c87509218..57afdce3c01 100644
--- a/ld/testsuite/ld-gc/pr13683.c
+++ b/ld/testsuite/ld-gc/pr13683.c
@@ -1,4 +1,6 @@
-void foo(void);
+void foo(void) asm("foo");
+void foo2(void) asm("foo2");
+int main(void) asm("main");
=20
 int main(void)
 {
@@ -24,5 +26,3 @@ void foo3(void)
 {
 	a =3D 3;
 }
-
-
diff --git a/ld/testsuite/ld-gc/pr19161-1.c b/ld/testsuite/ld-gc/pr19161-1.c
index 519948e9b46..0667ff64cf7 100644
--- a/ld/testsuite/ld-gc/pr19161-1.c
+++ b/ld/testsuite/ld-gc/pr19161-1.c
@@ -1,4 +1,5 @@
 int (*p)(void);
+int main(void) asm("main");
=20
 int
 main ()