aboutsummaryrefslogtreecommitdiff
path: root/tccgen.c
diff options
context:
space:
mode:
authorJoe Soroka <gits@joesoroka.com>2011-02-01 09:41:03 -0800
committerJoe Soroka <gits@joesoroka.com>2011-02-01 09:41:03 -0800
commitcf08675702044c180553c866ba1fde0414f00590 (patch)
tree8f9938bcc18b868912f173bcd4f6c125da1e2548 /tccgen.c
parentc59d3426b8060bcba3945f1388763512412a5d4d (diff)
downloadtinycc-cf08675702044c180553c866ba1fde0414f00590.tar.gz
tinycc-cf08675702044c180553c866ba1fde0414f00590.tar.bz2
weak definitions overrule non-weak prototypes
Diffstat (limited to 'tccgen.c')
-rw-r--r--tccgen.c12
1 files changed, 12 insertions, 0 deletions
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);
}