factor out symbol weakening into new function

This commit is contained in:
Joe Soroka 2011-03-07 01:02:23 -08:00
parent 0f0c2d9c02
commit 8bcb2ae1b2

View File

@ -255,6 +255,19 @@ ST_FUNC void sym_pop(Sym **ptop, Sym *b)
*ptop = b; *ptop = b;
} }
static void weaken_symbol(Sym *sym)
{
sym->type.t |= VT_WEAK;
if (sym->c > 0) {
int esym_type;
ElfW(Sym) *esym;
esym = &((ElfW(Sym) *)symtab_section->data)[sym->c];
esym_type = ELFW(ST_TYPE)(esym->st_info);
esym->st_info = ELFW(ST_INFO)(STB_WEAK, esym_type);
}
}
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
ST_FUNC void swap(int *p, int *q) ST_FUNC void swap(int *p, int *q)
@ -5213,11 +5226,8 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
vtop->sym = sym; vtop->sym = sym;
} }
/* patch symbol weakness */ /* patch symbol weakness */
if (type->t & VT_WEAK) { if (type->t & VT_WEAK)
unsigned char *st_info = weaken_symbol(sym);
&((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 #ifdef CONFIG_TCC_BCHECK
/* handles bounds now because the symbol must be defined /* handles bounds now because the symbol must be defined
before for the relocation */ before for the relocation */
@ -5337,11 +5347,8 @@ static void gen_function(Sym *sym)
((ElfW(Sym) *)symtab_section->data)[sym->c].st_size = ((ElfW(Sym) *)symtab_section->data)[sym->c].st_size =
ind - func_ind; ind - func_ind;
/* patch symbol weakness (this definition overrules any prototype) */ /* patch symbol weakness (this definition overrules any prototype) */
if (sym->type.t & VT_WEAK) { if (sym->type.t & VT_WEAK)
unsigned char *st_info = weaken_symbol(sym);
&((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) { if (tcc_state->do_debug) {
put_stabn(N_FUN, 0, 0, ind - func_ind); put_stabn(N_FUN, 0, 0, ind - func_ind);
} }