History

Fix fct asm label: only valid for declaration

- Fix function assembly label mechanism introduced in commit 9b09fc376e8c212a767c875e71ca003e3b9a0d2e to only accept alternative name for function declaration. - merge the code with the one introduced in commit 264a103610e3ee86b27b8cbb0e4ec81cd654d980. - Don't memorize token for asm label but directly the asm label.

Thomas Preud'homme committed 15 years ago

Commit 32a682b1 parent c2340023 files · +26 −58Browse files

Unified · Split

3 files
  1. libtcc.c +4 −4
  2. tcc.h +1 −1
  3. tccgen.c +21 −53
libtcc.c+4−4
@@ -436,10 +436,7 @@ ST_FUNC void put_extern_sym2(Sym *sym, Section *section, · 435 unmodified lines
436436 }
437437
438438 if (!sym->c) {
439− if (sym->a)
440− name = get_tok_str(sym->a, NULL);
441− else
442− name = get_tok_str(sym->v, NULL);
439+ name = get_tok_str(sym->v, NULL);
443440 #ifdef CONFIG_TCC_BCHECK
444441 if (tcc_state->do_bounds_check) {
445442 char buf[32];
@@ -496,6 +493,9 @@ ST_FUNC void put_extern_sym2(Sym *sym, Section *section, · 50 unmodified lines
496493 pstrcpy(buf1 + 1, sizeof(buf1) - 1, name);
497494 name = buf1;
498495 }
496+ if (sym->asm_label) {
497+ name = sym->asm_label;
498+ }
499499 info = ELFW(ST_INFO)(sym_bind, sym_type);
500500 sym->c = add_elf_sym(symtab_section, value, size, info, other, sh_num, name);
501501 } else {
tcc.h+1−1
@@ -219,7 +219,7 @@ typedef struct SValue { · 218 unmodified lines
219219 /* symbol management */
220220 typedef struct Sym {
221221 int v; /* symbol token */
222− int a; /* asm symbol token */
222+ char *asm_label; /* associated asm label */
223223 long r; /* associated register */
224224 union {
225225 long c; /* associated number */
tccgen.c+21−53
@@ -128,6 +128,7 @@ static inline Sym *sym_malloc(void) · 127 unmodified lines
128128 ST_INLN void sym_free(Sym *sym)
129129 {
130130 sym->next = sym_free_first;
131+ tcc_free(sym->asm_label);
131132 sym_free_first = sym;
132133 }
133134
@@ -136,7 +137,7 @@ ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, long c) · 2 unmodified lines
136137 {
137138 Sym *s;
138139 s = sym_malloc();
139− s->a = 0;
140+ s->asm_label = NULL;
140141 s->v = v;
141142 s->type.t = t;
142143 s->type.ref = NULL;
@@ -360,8 +361,10 @@ ST_FUNC Sym *external_global_sym(int v, CType *type, int r) · 217 unmodified lines
360361 return s;
361362 }
362363
363−/* define a new external reference to a symbol 'v' of type 'u' */
364−static Sym *external_sym(int v, CType *type, int r)
364+/* define a new external reference to a symbol 'v' with alternate asm
365+ name 'asm_label' of type 'u'. 'asm_label' is equal to NULL if there
366+ is no alternate name (most cases) */
367+static Sym *external_sym(int v, CType *type, int r, char *asm_label)
365368 {
366369 Sym *s;
367370
@@ -369,8 +372,7 @@ static Sym *external_sym(int v, CType *type, int r) · 1 unmodified line
369372 if (!s) {
370373 /* push forward reference */
371374 s = sym_push(v, type, r | VT_CONST | VT_SYM, 0);
372− if (type && type->ref && type->ref->a)
373− s->a = type->ref->a;
375+ s->asm_label = asm_label;
374376 s->type.t |= VT_EXTERN;
375377 } else if (s->type.ref == func_old_type.ref) {
376378 s->type.ref = type->ref;
@@ -3029,8 +3031,6 @@ static void post_type(CType *type, AttributeDef *ad) · 2652 unmodified lines
30293031 CType pt;
30303032
30313033 if (tok == '(') {
3032− TokenSym *ts = NULL;
3033−
30343034 /* function declaration */
30353035 next();
30363036 l = 0;
@@ -3086,19 +3086,10 @@ static void post_type(CType *type, AttributeDef *ad) · 49 unmodified lines
30863086 /* NOTE: const is ignored in returned type as it has a special
30873087 meaning in gcc / C++ */
30883088 type->t &= ~(VT_STORAGE | VT_CONSTANT);
3089− if (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3) {
3090− CString astr;
3091−
3092− asm_label_instr(&astr);
3093− ts = tok_alloc(astr.data, strlen(astr.data));
3094− cstr_free(&astr);
3095− }
30963089 post_type(type, ad);
30973090 /* we push a anonymous symbol which will contain the function prototype */
30983091 ad->func_args = arg_size;
30993092 s = sym_push(SYM_FIELD, type, INT_ATTR(ad), l);
3100− if (ts != NULL)
3101− s->a = ts->tok;
31023093 s->next = first;
31033094 type->t = t1 | VT_FUNC;
31043095 type->ref = s;
@@ -5251,7 +5242,8 @@ static void func_decl_list(Sym *func_sym) · 2146 unmodified lines
52515242 CType btype, type;
52525243
52535244 /* parse each declaration */
5254− while (tok != '{' && tok != ';' && tok != ',' && tok != TOK_EOF) {
5245+ while (tok != '{' && tok != ';' && tok != ',' && tok != TOK_EOF &&
5246+ tok != TOK_ASM1 && tok != TOK_ASM2 && tok != TOK_ASM3) {
52555247 if (!parse_btype(&btype, &ad))
52565248 expect("declaration list");
52575249 if (((btype.t & VT_BTYPE) == VT_ENUM ||
@@ -5298,10 +5290,7 @@ static void gen_function(Sym *sym) · 40 unmodified lines
52985290 ind = cur_text_section->data_offset;
52995291 /* NOTE: we patch the symbol size later */
53005292 put_extern_sym(sym, cur_text_section, ind, 0);
5301− if (sym->a)
5302− funcname = get_tok_str(sym->a, NULL);
5303− else
5304− funcname = get_tok_str(sym->v, NULL);
5293+ funcname = get_tok_str(sym->v, NULL);
53055294 func_ind = ind;
53065295 /* put debug symbol */
53075296 if (tcc_state->do_debug)
@@ -5387,12 +5376,6 @@ ST_FUNC void decl(int l) · 79 unmodified lines
53875376 Sym *sym;
53885377 AttributeDef ad;
53895378
5390− /*
5391− * type.ref must be either a valid reference or NULL for external_sym to
5392− * work. As type = btype is executed before external_sym is call, setting
5393− * btype.ref to 0 is enough.
5394− */
5395− btype.ref = 0;
53965379 while (1) {
53975380 if (!parse_btype(&btype, &ad)) {
53985381 /* skip redundant ';' */
@@ -5548,39 +5531,24 @@ ST_FUNC void decl(int l) · 149 unmodified lines
55485531 sym = sym_push(v, &type, INT_ATTR(&ad), 0);
55495532 sym->type.t |= VT_TYPEDEF;
55505533 } else if ((type.t & VT_BTYPE) == VT_FUNC) {
5534+ char *asm_label; // associated asm label
55515535 Sym *fn;
5536+
5537+ asm_label = NULL;
55525538 /* external function definition */
55535539 /* specific case for func_call attribute */
55545540 type.ref->r = INT_ATTR(&ad);
5555− fn = external_sym(v, &type, 0);
55565541
55575542 if (gnu_ext && (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3)) {
5558− char target[256];
5559−
5560− *target = 0;
5561− next();
5562− skip('(');
5563− /* Part 1: __USER_LABEL_PREFIX__ (user defined) */
5564− if (tok == TOK_STR)
5565− pstrcat(target, sizeof(target), tokc.cstr->data);
5566− else
5567− pstrcat(target, sizeof(target), get_tok_str(tok, NULL));
5568−
5569− next();
5570− /* Part 2: api name */
5571− if (tok == TOK_STR)
5572− pstrcat(target, sizeof(target), tokc.cstr->data);
5573− else
5574− pstrcat(target, sizeof(target), get_tok_str(tok, NULL));
5575−
5576− next();
5577− skip(')');
5578− if (tcc_state->warn_unsupported)
5579− warning("ignoring redirection from %s to %s\n", get_tok_str(v, NULL), target);
5543+ CString astr;
55805544
5581− if (tok == TOK_ATTRIBUTE1 || tok == TOK_ATTRIBUTE2)
5582− parse_attribute((AttributeDef *) &fn->type.ref->r);
5545+ asm_label_instr(&astr);
5546+ asm_label = tcc_strdup(astr.data);
5547+ cstr_free(&astr);
55835548 }
5549+ fn = external_sym(v, &type, 0, asm_label);
5550+ if (gnu_ext && (tok == TOK_ATTRIBUTE1 || tok == TOK_ATTRIBUTE2))
5551+ parse_attribute((AttributeDef *) &fn->type.ref->r);
55845552 } else {
55855553 /* not lvalue if array */
55865554 r = 0;
@@ -5594,7 +5562,7 @@ ST_FUNC void decl(int l) · 7 unmodified lines
55945562 /* NOTE: as GCC, uninitialized global static
55955563 arrays of null size are considered as
55965564 extern */
5597− external_sym(v, &type, r);
5565+ external_sym(v, &type, r, NULL);
55985566 } else {
55995567 type.t |= (btype.t & VT_STATIC); /* Retain "static". */
56005568 if (type.t & VT_STATIC)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t