bootstrappable: foo ()->bar.

This commit is contained in:
Jan Nieuwenhuizen 2017-07-23 23:34:09 +02:00
parent 0edcab5c2f
commit 1770c2f008
4 changed files with 36 additions and 23 deletions

View File

@ -1198,7 +1198,8 @@ ST_FUNC int asm_parse_regvar (int t)
s = table_ident[t - TOK_IDENT]->str;
if (s[0] != '%')
return -1;
t = tok_alloc(s+1, strlen(s)-1)->tok;
TokenSym *tok = tok_alloc(s+1, strlen(s)-1);
t = tok->tok;
unget_tok(t);
unget_tok('%');
parse_operand(tcc_state, &op);
@ -1479,7 +1480,8 @@ ST_FUNC void subst_asm_operand(CString *add_str,
in the C symbol table when later looking up
this name. So enter them now into the asm label
list when we still know the symbol. */
get_asm_sym(tok_alloc(name, strlen(name))->tok, sv->sym);
TokenSym *tok = tok_alloc(name, strlen(name));
get_asm_sym(tok->tok, sv->sym);
}
cstr_cat(add_str, name, -1);
if ((uint32_t)sv->c.i == 0)

View File

@ -564,14 +564,17 @@ ST_FUNC void squeeze_multi_relocs(Section *s, size_t oldrelocoffset)
So they will be mostly in order and there aren't many of them.
Secondly we need a stable sort (which qsort isn't). We use
a simple insertion sort. */
for (a = oldrelocoffset + sizeof(*r); a < sr->data_offset; a += sizeof(*r)) {
ssize_t i = a - sizeof(*r);
addr = ((ElfW_Rel*)(sr->data + a))->r_offset;
for (; i >= (ssize_t)oldrelocoffset &&
((ElfW_Rel*)(sr->data + i))->r_offset > addr; i -= sizeof(*r)) {
ElfW_Rel tmp = *(ElfW_Rel*)(sr->data + a);
*(ElfW_Rel*)(sr->data + a) = *(ElfW_Rel*)(sr->data + i);
*(ElfW_Rel*)(sr->data + i) = tmp;
for (a = oldrelocoffset + sizeof(ElfW_Rel); a < sr->data_offset; a += sizeof(ElfW_Rel)) {
ssize_t i = a - sizeof(ElfW_Rel);
ElfW_Rel* ea = (ElfW_Rel*)(sr->data + a);
ElfW_Rel* ei = (ElfW_Rel*)(sr->data + i);
addr = ea->r_offset;
for (; i >= (ssize_t)oldrelocoffset && ei->r_offset > addr;
i -= sizeof(ElfW_Rel)) {
ei = (ElfW_Rel*)(sr->data + i);
ElfW_Rel tmp = *ea;
*ea = *ei;
*ei = tmp;
}
}
@ -1011,7 +1014,8 @@ ST_FUNC void build_got_entries(TCCState *s1)
of function type. */
if (s1->dynsym) {
/* dynsym isn't set for -run :-/ */
dynindex = get_sym_attr(s1, sym_index, 0)->dyn_index;
struct sym_attr *attr = get_sym_attr(s1, sym_index, 0);
dynindex = attr->dyn_index;
esym = (ElfW(Sym) *)s1->dynsym->data + dynindex;
if (dynindex
&& (ELFW(ST_TYPE)(esym->st_info) == STT_FUNC
@ -1352,7 +1356,8 @@ static void bind_exe_dynsyms(TCCState *s1)
ELFW(ST_INFO)(STB_GLOBAL,STT_FUNC), 0, 0,
name);
int index = sym - (ElfW(Sym) *) symtab_section->data;
get_sym_attr(s1, index, 1)->dyn_index = dynindex;
struct sym_attr* attr = get_sym_attr(s1, index, 1);
attr->dyn_index = dynindex;
} else if (type == STT_OBJECT) {
unsigned long offset;
ElfW(Sym) *dynsym;
@ -1447,7 +1452,8 @@ static void export_global_syms(TCCState *s1)
dynindex = put_elf_sym(s1->dynsym, sym->st_value, sym->st_size,
sym->st_info, 0, sym->st_shndx, name);
index = sym - (ElfW(Sym) *) symtab_section->data;
get_sym_attr(s1, index, 1)->dyn_index = dynindex;
struct sym_attr *attr = get_sym_attr(s1, index, 1);
attr->dyn_index = dynindex;
}
}
}

View File

@ -3137,8 +3137,9 @@ static void parse_attribute(AttributeDef *ad)
case TOK_ALIAS2:
skip('(');
parse_mult_str(&astr, "alias(\"target\")");
TokenSym *tk = tok_alloc((char*)astr.data, astr.size-1);
ad->alias_target = /* save string as token, for later */
tok_alloc((char*)astr.data, astr.size-1)->tok;
tk->tok;
skip(')');
cstr_free(&astr);
break;
@ -3979,7 +3980,8 @@ static int asm_label_instr(void)
#ifdef ASM_DEBUG
printf("asm_alias: \"%s\"\n", (char *)astr.data);
#endif
v = tok_alloc(astr.data, astr.size - 1)->tok;
TokenSym *tk = tok_alloc(astr.data, astr.size - 1);
v = tk->tok;
cstr_free(&astr);
return v;
}
@ -5467,10 +5469,12 @@ static void gfunc_return(CType *func_type)
}
#endif
static int case_cmp(const void *pa, const void *pb)
static int case_cmp(const void *ppa, const void *ppb)
{
int64_t a = (*(struct case_t**) pa)->v1;
int64_t b = (*(struct case_t**) pb)->v1;
struct case_t *pa = *(struct case_t**)ppa;
struct case_t *pb = *(struct case_t**)ppb;
int64_t a = pa->v1;
int64_t b = pb->v1;
return a < b ? -1 : a > b;
}

11
tccpp.c
View File

@ -1595,7 +1595,8 @@ static void pragma_parse(TCCState *s1)
goto pragma_err;
if (next(), tok != TOK_STR)
goto pragma_err;
v = tok_alloc(tokc.str.data, tokc.str.size - 1)->tok;
TokenSym *tk = tok_alloc(tokc.str.data, tokc.str.size - 1);
v = tk->tok;
if (next(), tok != ')')
goto pragma_err;
if (t == TOK_push_macro) {
@ -1616,8 +1617,8 @@ static void pragma_parse(TCCState *s1)
pp_debug_tok = t, pp_debug_symv = v;
} else if (tok == TOK_once) {
search_cached_include(s1, file->filename, 1)->once = pp_once;
CachedInclude *p = search_cached_include(s1, file->filename, 1);
p->once = pp_once;
} else if (s1->ppfp) {
/* tcc -E: keep pragmas below unchanged */
unget_tok(' ');
@ -2547,8 +2548,8 @@ static inline void next_nomacro1(void)
#ifdef INC_DEBUG
printf("#endif %s\n", get_tok_str(file->ifndef_macro_saved, NULL));
#endif
search_cached_include(s1, file->filename, 1)
->ifndef_macro = file->ifndef_macro_saved;
CachedInclude *tmp = search_cached_include(s1, file->filename, 1);
tmp->ifndef_macro = file->ifndef_macro_saved;
tok_flags &= ~TOK_FLAG_ENDIF;
}