History

tccgen: handle __attribute((alias("target")))

Joe Soroka committed 15 years ago

Commit c93eca41 parent ce8c1883 files · +27 −1Browse files

Unified · Split

3 files
  1. tcc.h +1 −0
  2. tccgen.c +24 −1
  3. tcctok.h +2 −0
tcc.h+1−0
@@ -285,6 +285,7 @@ typedef struct AttributeDef { · 284 unmodified lines
285285 resize : 1,
286286 fill : 10;
287287 struct Section *section;
288+ int alias_target; /* token */
288289 } AttributeDef;
289290
290291 /* gr: wrappers for casting sym->r for other purposes */
tccgen.c+24−1
@@ -2472,6 +2472,16 @@ static void parse_attribute(AttributeDef *ad) · 2471 unmodified lines
24722472 next();
24732473 skip(')');
24742474 break;
2475+ case TOK_ALIAS1:
2476+ case TOK_ALIAS2:
2477+ skip('(');
2478+ if (tok != TOK_STR)
2479+ expect("alias(\"target\")");
2480+ ad->alias_target = /* save string as token, for later */
2481+ tok_alloc((char*)tokc.cstr->data, tokc.cstr->size-1)->tok;
2482+ next();
2483+ skip(')');
2484+ break;
24752485 case TOK_ALIGNED1:
24762486 case TOK_ALIGNED2:
24772487 if (tok == '(') {
@@ -5578,7 +5588,20 @@ ST_FUNC void decl(int l) · 3100 unmodified lines
55785588 /* NOTE: as GCC, uninitialized global static
55795589 arrays of null size are considered as
55805590 extern */
5581− external_sym(v, &type, r, asm_label);
5591+ sym = external_sym(v, &type, r, asm_label);
5592+
5593+ if (ad.alias_target) {
5594+ Section tsec;
5595+ Elf32_Sym *esym;
5596+ Sym *alias_target;
5597+
5598+ alias_target = sym_find(ad.alias_target);
5599+ if (!alias_target || !alias_target->c)
5600+ error("unsupported forward __alias__ attribute");
5601+ esym = &((Elf32_Sym *)symtab_section->data)[alias_target->c];
5602+ tsec.sh_num = esym->st_shndx;
5603+ put_extern_sym2(sym, &tsec, esym->st_value, esym->st_size, 0);
5604+ }
55825605 } else {
55835606 type.t |= (btype.t & VT_STATIC); /* Retain "static". */
55845607 if (type.t & VT_STATIC)
tcctok.h+2−0
@@ -100,6 +100,8 @@ · 99 unmodified lines
100100 DEF(TOK_PACKED2, "__packed__")
101101 DEF(TOK_WEAK1, "weak")
102102 DEF(TOK_WEAK2, "__weak__")
103+ DEF(TOK_ALIAS1, "alias")
104+ DEF(TOK_ALIAS2, "__alias__")
103105 DEF(TOK_UNUSED1, "unused")
104106 DEF(TOK_UNUSED2, "__unused__")
105107 DEF(TOK_CDECL1, "cdecl")

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