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 = external_global_sym(v, &func_old_type, 0);
sym = external_global_sym(v, &func_old_type);
oad(0xe8, -4);
greloc(cur_text_section, sym, ind-4, R_386_PC32);
}
@ -1125,7 +1125,7 @@ ST_FUNC void gen_bounded_ptr_deref(void)
/* patch relocation */
/* XXX: find a better solution ? */
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)
put_extern_sym(sym, NULL, 0, 0);
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 ElfSym *elfsym(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 vswap(void);
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
(for .set, removed for real defs), for mere references it's correct
as is. */
Sym *sym = global_identifier_push(v, VT_ASM | VT_EXTERN | VT_STATIC, 0);
sym->r = VT_CONST | VT_SYM;
return sym;
return global_identifier_push(v, VT_ASM | VT_EXTERN | VT_STATIC, 0);
}
/* 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;
s = sym_push2(&global_stack, v, t, c);
s->r = VT_CONST | VT_SYM;
/* don't record anonymous symbol */
if (v < SYM_FIRST_ANOM) {
ps = &table_ident[v - TOK_IDENT]->sym_identifier;
/* modify the top most local identifier, so that
sym_identifier will point to 's' when popped */
/* modify the top most local identifier, so that sym_identifier will
point to 's' when popped; happens when called from inline asm */
while (*ps != NULL && (*ps)->sym_scope)
ps = &(*ps)->prev_tok;
s->prev_tok = *ps;
@ -846,9 +847,8 @@ ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsign
Sym *sym;
v = anon_sym++;
sym = global_identifier_push(v, type->t | VT_STATIC, 0);
sym->type.ref = type->ref;
sym->r = VT_CONST | VT_SYM;
sym = sym_push(v, type, VT_CONST | VT_SYM, 0);
sym->type.t |= VT_STATIC;
put_extern_sym(sym, sec, offset, size);
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' */
ST_FUNC Sym *external_global_sym(int v, CType *type, int r)
ST_FUNC Sym *external_global_sym(int v, CType *type)
{
Sym *s;
@ -869,7 +869,6 @@ ST_FUNC Sym *external_global_sym(int v, CType *type, int r)
/* push forward reference */
s = global_identifier_push(v, type->t | VT_EXTERN, 0);
s->type.ref = type->ref;
s->r = r | VT_CONST | VT_SYM;
} else if (IS_ASM_SYM(s)) {
s->type.t = type->t | (s->type.t & VT_EXTERN);
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));
/* push forward reference */
s = sym_push(v, type, r | VT_CONST | VT_SYM, 0);
s->type.t |= VT_EXTERN;
s->a = ad->a;
s->sym_scope = 0;
} else {
@ -1018,7 +1016,7 @@ static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad)
/* push a reference to global symbol 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 */
@ -3427,7 +3425,7 @@ redo:
if (!s) {
tcc_warning("implicit declaration of function '%s'",
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;
next();
@ -5258,7 +5256,7 @@ special_math_val:
#endif
)
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;
@ -7265,8 +7263,8 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
put_extern_sym(sym, sec, addr, size);
} else {
/* push global reference */
sym = get_sym_ref(type, sec, addr, size);
vpushsym(type, sym);
vpush_ref(type, sec, addr, size);
sym = vtop->sym;
vtop->r |= r;
}
@ -7556,14 +7554,12 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym)
type.t = (type.t & ~VT_EXTERN) | VT_STATIC;
/* put function symbol */
sym = external_global_sym(v, &type, 0);
type.t &= ~VT_EXTERN;
patch_storage(sym, &ad, &type);
sym = external_sym(v, &type, 0, &ad);
/* static inline functions are just recorded as a kind
of macro. Their code will be emitted at the end of
the compilation unit only if they are used */
if ((type.t & (VT_INLINE | VT_STATIC)) ==
if ((type.t & (VT_INLINE | VT_STATIC)) ==
(VT_INLINE | VT_STATIC)) {
struct InlineFunc *fn;
const char *filename;

View File

@ -649,7 +649,7 @@ static unsigned long func_bound_ind;
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);
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;
}
sym = external_global_sym(func, &func_old_type, 0);
sym = external_global_sym(func, &func_old_type);
if (!sym->c)
put_extern_sym(sym, NULL, 0, 0);
@ -1031,7 +1031,7 @@ void gfunc_epilog(void)
v = (func_scratch + -loc + 15) & -16;
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(0xe8, 0); /* call __chkstk, (does the stackframe too) */
greloca(cur_text_section, sym, ind-4, R_X86_64_PC32, -4);