Tidy some code

the real difference is in decl0 where we can use external_sym
just fine also for function definitions, we don't have to use
external_global_sym.  Setting VT_EXTERN in external_sym isn't
necessary either (the type will have it set if necessary).
The rest is tidying: removing unused arguments and moving
some code around.
This commit is contained in:
Michael Matz 2019-04-18 03:36:39 +02:00
parent f2461096b1
commit c07e81b087
5 changed files with 20 additions and 26 deletions

View file

@ -341,7 +341,7 @@ static void gen_static_call(int v)
{ {
Sym *sym; Sym *sym;
sym = external_global_sym(v, &func_old_type, 0); sym = external_global_sym(v, &func_old_type);
oad(0xe8, -4); oad(0xe8, -4);
greloc(cur_text_section, sym, ind-4, R_386_PC32); greloc(cur_text_section, sym, ind-4, R_386_PC32);
} }
@ -1125,7 +1125,7 @@ ST_FUNC void gen_bounded_ptr_deref(void)
/* patch relocation */ /* patch relocation */
/* XXX: find a better solution ? */ /* XXX: find a better solution ? */
rel = (Elf32_Rel *)(cur_text_section->reloc->data + vtop->c.i); rel = (Elf32_Rel *)(cur_text_section->reloc->data + vtop->c.i);
sym = external_global_sym(func, &func_old_type, 0); sym = external_global_sym(func, &func_old_type);
if (!sym->c) if (!sym->c)
put_extern_sym(sym, NULL, 0, 0); put_extern_sym(sym, NULL, 0, 0);
rel->r_info = ELF32_R_INFO(sym->c, ELF32_R_TYPE(rel->r_info)); rel->r_info = ELF32_R_INFO(sym->c, ELF32_R_TYPE(rel->r_info));

2
tcc.h
View file

@ -1318,7 +1318,7 @@ ST_FUNC void test_lvalue(void);
ST_FUNC void vpushi(int v); ST_FUNC void vpushi(int v);
ST_FUNC ElfSym *elfsym(Sym *); ST_FUNC ElfSym *elfsym(Sym *);
ST_FUNC void update_storage(Sym *sym); ST_FUNC void update_storage(Sym *sym);
ST_FUNC Sym *external_global_sym(int v, CType *type, int r); ST_FUNC Sym *external_global_sym(int v, CType *type);
ST_FUNC void vset(CType *type, int r, int v); ST_FUNC void vset(CType *type, int r, int v);
ST_FUNC void vswap(void); ST_FUNC void vswap(void);
ST_FUNC void vpush_global_sym(CType *type, int v); ST_FUNC void vpush_global_sym(CType *type, int v);

View file

@ -48,9 +48,7 @@ static Sym *asm_label_push(int v)
/* We always add VT_EXTERN, for sym definition that's tentative /* We always add VT_EXTERN, for sym definition that's tentative
(for .set, removed for real defs), for mere references it's correct (for .set, removed for real defs), for mere references it's correct
as is. */ as is. */
Sym *sym = global_identifier_push(v, VT_ASM | VT_EXTERN | VT_STATIC, 0); return global_identifier_push(v, VT_ASM | VT_EXTERN | VT_STATIC, 0);
sym->r = VT_CONST | VT_SYM;
return sym;
} }
/* Return a symbol we can use inside the assembler, having name NAME. /* Return a symbol we can use inside the assembler, having name NAME.

View file

@ -616,11 +616,12 @@ ST_FUNC Sym *global_identifier_push(int v, int t, int c)
{ {
Sym *s, **ps; Sym *s, **ps;
s = sym_push2(&global_stack, v, t, c); s = sym_push2(&global_stack, v, t, c);
s->r = VT_CONST | VT_SYM;
/* don't record anonymous symbol */ /* don't record anonymous symbol */
if (v < SYM_FIRST_ANOM) { if (v < SYM_FIRST_ANOM) {
ps = &table_ident[v - TOK_IDENT]->sym_identifier; ps = &table_ident[v - TOK_IDENT]->sym_identifier;
/* modify the top most local identifier, so that /* modify the top most local identifier, so that sym_identifier will
sym_identifier will point to 's' when popped */ point to 's' when popped; happens when called from inline asm */
while (*ps != NULL && (*ps)->sym_scope) while (*ps != NULL && (*ps)->sym_scope)
ps = &(*ps)->prev_tok; ps = &(*ps)->prev_tok;
s->prev_tok = *ps; s->prev_tok = *ps;
@ -846,9 +847,8 @@ ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsign
Sym *sym; Sym *sym;
v = anon_sym++; v = anon_sym++;
sym = global_identifier_push(v, type->t | VT_STATIC, 0); sym = sym_push(v, type, VT_CONST | VT_SYM, 0);
sym->type.ref = type->ref; sym->type.t |= VT_STATIC;
sym->r = VT_CONST | VT_SYM;
put_extern_sym(sym, sec, offset, size); put_extern_sym(sym, sec, offset, size);
return sym; return sym;
} }
@ -860,7 +860,7 @@ static void vpush_ref(CType *type, Section *sec, unsigned long offset, unsigned
} }
/* define a new external reference to a symbol 'v' of type 'u' */ /* define a new external reference to a symbol 'v' of type 'u' */
ST_FUNC Sym *external_global_sym(int v, CType *type, int r) ST_FUNC Sym *external_global_sym(int v, CType *type)
{ {
Sym *s; Sym *s;
@ -869,7 +869,6 @@ ST_FUNC Sym *external_global_sym(int v, CType *type, int r)
/* push forward reference */ /* push forward reference */
s = global_identifier_push(v, type->t | VT_EXTERN, 0); s = global_identifier_push(v, type->t | VT_EXTERN, 0);
s->type.ref = type->ref; s->type.ref = type->ref;
s->r = r | VT_CONST | VT_SYM;
} else if (IS_ASM_SYM(s)) { } else if (IS_ASM_SYM(s)) {
s->type.t = type->t | (s->type.t & VT_EXTERN); s->type.t = type->t | (s->type.t & VT_EXTERN);
s->type.ref = type->ref; s->type.ref = type->ref;
@ -1001,7 +1000,6 @@ static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad)
tcc_error("conflicting types for '%s'", get_tok_str(s->v, NULL)); tcc_error("conflicting types for '%s'", get_tok_str(s->v, NULL));
/* push forward reference */ /* push forward reference */
s = sym_push(v, type, r | VT_CONST | VT_SYM, 0); s = sym_push(v, type, r | VT_CONST | VT_SYM, 0);
s->type.t |= VT_EXTERN;
s->a = ad->a; s->a = ad->a;
s->sym_scope = 0; s->sym_scope = 0;
} else { } else {
@ -1018,7 +1016,7 @@ static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad)
/* push a reference to global symbol v */ /* push a reference to global symbol v */
ST_FUNC void vpush_global_sym(CType *type, int v) ST_FUNC void vpush_global_sym(CType *type, int v)
{ {
vpushsym(type, external_global_sym(v, type, 0)); vpushsym(type, external_global_sym(v, type));
} }
/* save registers up to (vtop - n) stack entry */ /* save registers up to (vtop - n) stack entry */
@ -3427,7 +3425,7 @@ redo:
if (!s) { if (!s) {
tcc_warning("implicit declaration of function '%s'", tcc_warning("implicit declaration of function '%s'",
get_tok_str(tok, &tokc)); get_tok_str(tok, &tokc));
s = external_global_sym(tok, &func_old_type, 0); s = external_global_sym(tok, &func_old_type);
} }
ad->cleanup_func = s; ad->cleanup_func = s;
next(); next();
@ -5258,7 +5256,7 @@ special_math_val:
#endif #endif
) )
tcc_warning("implicit declaration of function '%s'", name); tcc_warning("implicit declaration of function '%s'", name);
s = external_global_sym(t, &func_old_type, 0); s = external_global_sym(t, &func_old_type);
} }
r = s->r; r = s->r;
@ -7265,8 +7263,8 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
put_extern_sym(sym, sec, addr, size); put_extern_sym(sym, sec, addr, size);
} else { } else {
/* push global reference */ /* push global reference */
sym = get_sym_ref(type, sec, addr, size); vpush_ref(type, sec, addr, size);
vpushsym(type, sym); sym = vtop->sym;
vtop->r |= r; vtop->r |= r;
} }
@ -7556,9 +7554,7 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym)
type.t = (type.t & ~VT_EXTERN) | VT_STATIC; type.t = (type.t & ~VT_EXTERN) | VT_STATIC;
/* put function symbol */ /* put function symbol */
sym = external_global_sym(v, &type, 0); sym = external_sym(v, &type, 0, &ad);
type.t &= ~VT_EXTERN;
patch_storage(sym, &ad, &type);
/* static inline functions are just recorded as a kind /* static inline functions are just recorded as a kind
of macro. Their code will be emitted at the end of of macro. Their code will be emitted at the end of

View file

@ -649,7 +649,7 @@ static unsigned long func_bound_ind;
static void gen_static_call(int v) static void gen_static_call(int v)
{ {
Sym *sym = external_global_sym(v, &func_old_type, 0); Sym *sym = external_global_sym(v, &func_old_type);
oad(0xe8, 0); oad(0xe8, 0);
greloca(cur_text_section, sym, ind-4, R_X86_64_PC32, -4); greloca(cur_text_section, sym, ind-4, R_X86_64_PC32, -4);
} }
@ -713,7 +713,7 @@ ST_FUNC void gen_bounded_ptr_deref(void)
break; break;
} }
sym = external_global_sym(func, &func_old_type, 0); sym = external_global_sym(func, &func_old_type);
if (!sym->c) if (!sym->c)
put_extern_sym(sym, NULL, 0, 0); put_extern_sym(sym, NULL, 0, 0);
@ -1031,7 +1031,7 @@ void gfunc_epilog(void)
v = (func_scratch + -loc + 15) & -16; v = (func_scratch + -loc + 15) & -16;
if (v >= 4096) { if (v >= 4096) {
Sym *sym = external_global_sym(TOK___chkstk, &func_old_type, 0); Sym *sym = external_global_sym(TOK___chkstk, &func_old_type);
oad(0xb8, v); /* mov stacksize, %eax */ oad(0xb8, v); /* mov stacksize, %eax */
oad(0xe8, 0); /* call __chkstk, (does the stackframe too) */ oad(0xe8, 0); /* call __chkstk, (does the stackframe too) */
greloca(cur_text_section, sym, ind-4, R_X86_64_PC32, -4); greloca(cur_text_section, sym, ind-4, R_X86_64_PC32, -4);