From cf08675702044c180553c866ba1fde0414f00590 Mon Sep 17 00:00:00 2001 From: Joe Soroka Date: Tue, 1 Feb 2011 09:41:03 -0800 Subject: weak definitions overrule non-weak prototypes --- tccgen.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tccgen.c') diff --git a/tccgen.c b/tccgen.c index 2d7e4ae..7144ccd 100644 --- a/tccgen.c +++ b/tccgen.c @@ -5194,6 +5194,12 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, vsetc(type, VT_CONST | VT_SYM, &cval); vtop->sym = sym; } + /* patch symbol weakness */ + if (type->t & VT_WEAK) { + unsigned char *st_info = + &((ElfW(Sym) *)symtab_section->data)[sym->c].st_info; + *st_info = ELF32_ST_INFO(STB_WEAK, ELF32_ST_TYPE(*st_info)); + } #ifdef CONFIG_TCC_BCHECK /* handles bounds now because the symbol must be defined before for the relocation */ @@ -5314,6 +5320,12 @@ static void gen_function(Sym *sym) /* patch symbol size */ ((ElfW(Sym) *)symtab_section->data)[sym->c].st_size = ind - func_ind; + /* patch symbol weakness (this definition overrules any prototype) */ + if (sym->type.t & VT_WEAK) { + unsigned char *st_info = + &((ElfW(Sym) *)symtab_section->data)[sym->c].st_info; + *st_info = ELF32_ST_INFO(STB_WEAK, ELF32_ST_TYPE(*st_info)); + } if (tcc_state->do_debug) { put_stabn(N_FUN, 0, 0, ind - func_ind); } -- cgit v1.3.1