Fix weak symbols to work in tcc.

Fixes #322.
This commit is contained in:
Andrius Štikonas 2024-01-09 22:52:43 +00:00
parent 9ec45654cf
commit be15f9caca
10 changed files with 82 additions and 73 deletions

View file

@ -1 +0,0 @@
../patches/ignore-static-inside-array.patch

View file

@ -1 +0,0 @@
../patches/static-link.patch

View file

@ -0,0 +1,50 @@
SPDX-FileCopyrightText: 2021 Alexander Sosedkin <monk@unboiled.info>
SPDX-License-Identifier: LGPL-2.0-or-later
From da11cf651576f94486dbd043dbfcde469e497574 Mon Sep 17 00:00:00 2001
From: Alexander Sosedkin <monk@unboiled.info>
Date: Sat, 30 Oct 2021 16:04:11 +0200
Subject: [PATCH] Don't skip weak symbols during ar creation
```
$ echo 'int __attribute__((__weak__)) f(void) { return 4; }' > w.c
$ tcc -c w.c -o w.o
$ tcc-old -ar rc w.a w.o; nm -s w.a # previous behaviour, not indexed
w.o:
0000000000000000 W f
$ ar rc w.a w.o; nm -s w.a # GNU binutils behaviour, indexed
Archive index:
f in w.o
0000000000000000 W f
$ tcc-new rc w.a w.o; nm -s w.a # new behaviour, indexed
Archive index:
f in w.o
0000000000000000 W f
```
---
tcctools.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tcctools.c b/tcctools.c
index cf174965..4567b81a 100644
--- tcctools.c
+++ tcctools.c
@@ -200,6 +200,9 @@ ST_FUNC int tcc_tool_ar(TCCState *s1, int argc, char **argv)
(sym->st_info == 0x10
|| sym->st_info == 0x11
|| sym->st_info == 0x12
+ || sym->st_info == 0x20
+ || sym->st_info == 0x21
+ || sym->st_info == 0x22
)) {
//printf("symtab: %2Xh %4Xh %2Xh %s\n", sym->st_info, sym->st_size, sym->st_shndx, strtab + sym->st_name);
istrlen = strlen(strtab + sym->st_name)+1;
--
2.11.4.GIT

View file

@ -1,19 +0,0 @@
SPDX-FileCopyrightText: 2021 Andrius Štikonas <andrius@stikonas.eu>
SPDX-License-Identifier: LGPL-2.0-or-later
Ignore duplicate symbols. Due to poor support for weak symbols in tcc-ar
we had to patch musl to replace weak symbols with strong symbols
--- tccelf.c 2021-02-02 17:41:08.662247892 +0000
+++ tccelf.c 2021-02-02 23:21:49.652080201 +0000
@@ -552,8 +552,9 @@
#if 0
printf("new_bind=%x new_shndx=%x new_vis=%x old_bind=%x old_shndx=%x old_vis=%x\n",
sym_bind, shndx, new_vis, esym_bind, esym->st_shndx, esym_vis);
-#endif
tcc_error_noabort("'%s' defined twice", name);
+#endif
+ goto do_patch;
}
} else {
do_patch: