aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Soroka <gits@joesoroka.com>2011-03-07 01:02:23 -0800
committerJoe Soroka <gits@joesoroka.com>2011-03-07 01:02:23 -0800
commit8bcb2ae1b262fd94fbc30ebf6f3b9bdd1ae6dc4a (patch)
tree34dffb2c3ddde7f252760b94a526a1634a816d1c
parent0f0c2d9c02d357c247f7310908124c39b8625d35 (diff)
downloadtinycc-8bcb2ae1b262fd94fbc30ebf6f3b9bdd1ae6dc4a.tar.gz
tinycc-8bcb2ae1b262fd94fbc30ebf6f3b9bdd1ae6dc4a.tar.bz2
factor out symbol weakening into new function
-rw-r--r--tccgen.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/tccgen.c b/tccgen.c
index 0c3b50f..c3456b7 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -255,6 +255,19 @@ ST_FUNC void sym_pop(Sym **ptop, Sym *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)
@@ -5213,11 +5226,8 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
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));
- }
+ if (type->t & VT_WEAK)
+ weaken_symbol(sym);
#ifdef CONFIG_TCC_BCHECK
/* handles bounds now because the symbol must be defined
before for the relocation */
@@ -5337,11 +5347,8 @@ static void gen_function(Sym *sym)
((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 (sym->type.t & VT_WEAK)
+ weaken_symbol(sym);
if (tcc_state->do_debug) {
put_stabn(N_FUN, 0, 0, ind - func_ind);
}