[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Weak symbol problem
From: |
Daniel Glöckner |
Subject: |
Re: [Tinycc-devel] Weak symbol problem |
Date: |
Sat, 15 May 2010 04:13:49 +0200 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
Before I commit the following patch as fix, can somebody please look
over it for side effects?
The patch marks all undefined weak symbols found in external libraries
as strong. The value of all remaining weak symbols is set to zero just
before the section is output.
If this approach is correct, is it needed as well on FreeBSD, where
the PLT offset is moved to the GOT?
Daniel
diff --git a/tccelf.c b/tccelf.c
index fb5f3f9..3ceae47 100644
--- a/tccelf.c
+++ b/tccelf.c
@@ -1391,6 +1391,17 @@ void patch_dynsym_undef(TCCState *s1, Section *s)
#else
#define HAVE_PHDR 0
#define EXTRA_RELITEMS 9
+
+/* zero plt offsets of weak symbols in .dynsym */
+void patch_dynsym_undef(TCCState *s1, Section *s)
+{
+ ElfW(Sym) *sym, *sym_end;
+
+ sym_end = (ElfW(Sym) *)(s->data + s->data_offset);
+ for (sym = (ElfW(Sym) *)s->data + 1; sym < sym_end; sym++)
+ if (sym->st_shndx == SHN_UNDEF && ELFW(ST_BIND)(sym->st_info) ==
STB_WEAK)
+ sym->st_value = 0;
+}
#endif
ST_FUNC void fill_got_entry(TCCState *s1, ElfW_Rel *rel)
@@ -1531,7 +1542,7 @@ static int elf_output_file(TCCState *s1, const char
*filename)
type = ELFW(ST_TYPE)(esym->st_info);
if (type == STT_FUNC) {
put_got_entry(s1, R_JMP_SLOT, esym->st_size,
- esym->st_info,
+ ELFW(ST_INFO)(STB_GLOBAL, type),
sym - (ElfW(Sym)
*)symtab_section->data);
} else if (type == STT_OBJECT) {
unsigned long offset;
@@ -2151,10 +2162,8 @@ static int elf_output_file(TCCState *s1, const char
*filename)
for(i=1;i<s1->nb_sections;i++) {
s = s1->sections[section_order[i]];
if (s->sh_type != SHT_NOBITS) {
-#if defined(__FreeBSD__)
if (s->sh_type == SHT_DYNSYM)
patch_dynsym_undef(s1, s);
-#endif
while (offset < s->sh_offset) {
fputc(0, f);
offset++;