Unified · Split
| @@ -255,6 +255,19 @@ ST_FUNC void sym_pop(Sym **ptop, Sym *b) · 254 unmodified lines | |||
| 255 | *ptop = b; | 255 | *ptop = b; |
| 256 | } | 256 | } |
| 257 | 257 | ||
| 258 | static void weaken_symbol(Sym *sym) | ||
| 259 | { | ||
| 260 | sym->type.t |= VT_WEAK; | ||
| 261 | if (sym->c > 0) { | ||
| 262 | int esym_type; | ||
| 263 | ElfW(Sym) *esym; | ||
| 264 | |||
| 265 | esym = &((ElfW(Sym) *)symtab_section->data)[sym->c]; | ||
| 266 | esym_type = ELFW(ST_TYPE)(esym->st_info); | ||
| 267 | esym->st_info = ELFW(ST_INFO)(STB_WEAK, esym_type); | ||
| 268 | } | ||
| 269 | } | ||
| 270 | |||
| 258 | /* ------------------------------------------------------------------------- */ | 271 | /* ------------------------------------------------------------------------- */ |
| 259 | 272 | ||
| 260 | ST_FUNC void swap(int *p, int *q) | 273 | ST_FUNC void swap(int *p, int *q) |
| @@ -5213,11 +5226,8 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 4952 unmodified lines | |||
| 5213 | vtop->sym = sym; | 5226 | vtop->sym = sym; |
| 5214 | } | 5227 | } |
| 5215 | /* patch symbol weakness */ | 5228 | /* patch symbol weakness */ |
| 5216 | if (type->t & VT_WEAK) { | 5229 | if (type->t & VT_WEAK) |
| 5217 | unsigned char *st_info = | 5230 | weaken_symbol(sym); |
| 5218 | &((ElfW(Sym) *)symtab_section->data)[sym->c].st_info; | ||
| 5219 | *st_info = ELF32_ST_INFO(STB_WEAK, ELF32_ST_TYPE(*st_info)); | ||
| 5220 | } | ||
| 5221 | #ifdef CONFIG_TCC_BCHECK | 5231 | #ifdef CONFIG_TCC_BCHECK |
| 5222 | /* handles bounds now because the symbol must be defined | 5232 | /* handles bounds now because the symbol must be defined |
| 5223 | before for the relocation */ | 5233 | before for the relocation */ |
| @@ -5337,11 +5347,8 @@ static void gen_function(Sym *sym) · 113 unmodified lines | |||
| 5337 | ((ElfW(Sym) *)symtab_section->data)[sym->c].st_size = | 5347 | ((ElfW(Sym) *)symtab_section->data)[sym->c].st_size = |
| 5338 | ind - func_ind; | 5348 | ind - func_ind; |
| 5339 | /* patch symbol weakness (this definition overrules any prototype) */ | 5349 | /* patch symbol weakness (this definition overrules any prototype) */ |
| 5340 | if (sym->type.t & VT_WEAK) { | 5350 | if (sym->type.t & VT_WEAK) |
| 5341 | unsigned char *st_info = | 5351 | weaken_symbol(sym); |
| 5342 | &((ElfW(Sym) *)symtab_section->data)[sym->c].st_info; | ||
| 5343 | *st_info = ELF32_ST_INFO(STB_WEAK, ELF32_ST_TYPE(*st_info)); | ||
| 5344 | } | ||
| 5345 | if (tcc_state->do_debug) { | 5352 | if (tcc_state->do_debug) { |
| 5346 | put_stabn(N_FUN, 0, 0, ind - func_ind); | 5353 | put_stabn(N_FUN, 0, 0, ind - func_ind); |
| 5347 | } | 5354 | } |