mirror of
https://github.com/mirror/tinycc.git
synced 2025-02-08 06:40:11 +08:00
tccgen: handle __attribute((alias("target")))
This commit is contained in:
parent
ce8c1886a5
commit
c93eca4fe4
1
tcc.h
1
tcc.h
@ -285,6 +285,7 @@ typedef struct AttributeDef {
|
|||||||
resize : 1,
|
resize : 1,
|
||||||
fill : 10;
|
fill : 10;
|
||||||
struct Section *section;
|
struct Section *section;
|
||||||
|
int alias_target; /* token */
|
||||||
} AttributeDef;
|
} AttributeDef;
|
||||||
|
|
||||||
/* gr: wrappers for casting sym->r for other purposes */
|
/* gr: wrappers for casting sym->r for other purposes */
|
||||||
|
25
tccgen.c
25
tccgen.c
@ -2472,6 +2472,16 @@ static void parse_attribute(AttributeDef *ad)
|
|||||||
next();
|
next();
|
||||||
skip(')');
|
skip(')');
|
||||||
break;
|
break;
|
||||||
|
case TOK_ALIAS1:
|
||||||
|
case TOK_ALIAS2:
|
||||||
|
skip('(');
|
||||||
|
if (tok != TOK_STR)
|
||||||
|
expect("alias(\"target\")");
|
||||||
|
ad->alias_target = /* save string as token, for later */
|
||||||
|
tok_alloc((char*)tokc.cstr->data, tokc.cstr->size-1)->tok;
|
||||||
|
next();
|
||||||
|
skip(')');
|
||||||
|
break;
|
||||||
case TOK_ALIGNED1:
|
case TOK_ALIGNED1:
|
||||||
case TOK_ALIGNED2:
|
case TOK_ALIGNED2:
|
||||||
if (tok == '(') {
|
if (tok == '(') {
|
||||||
@ -5578,7 +5588,20 @@ ST_FUNC void decl(int l)
|
|||||||
/* NOTE: as GCC, uninitialized global static
|
/* NOTE: as GCC, uninitialized global static
|
||||||
arrays of null size are considered as
|
arrays of null size are considered as
|
||||||
extern */
|
extern */
|
||||||
external_sym(v, &type, r, asm_label);
|
sym = external_sym(v, &type, r, asm_label);
|
||||||
|
|
||||||
|
if (ad.alias_target) {
|
||||||
|
Section tsec;
|
||||||
|
Elf32_Sym *esym;
|
||||||
|
Sym *alias_target;
|
||||||
|
|
||||||
|
alias_target = sym_find(ad.alias_target);
|
||||||
|
if (!alias_target || !alias_target->c)
|
||||||
|
error("unsupported forward __alias__ attribute");
|
||||||
|
esym = &((Elf32_Sym *)symtab_section->data)[alias_target->c];
|
||||||
|
tsec.sh_num = esym->st_shndx;
|
||||||
|
put_extern_sym2(sym, &tsec, esym->st_value, esym->st_size, 0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
type.t |= (btype.t & VT_STATIC); /* Retain "static". */
|
type.t |= (btype.t & VT_STATIC); /* Retain "static". */
|
||||||
if (type.t & VT_STATIC)
|
if (type.t & VT_STATIC)
|
||||||
|
2
tcctok.h
2
tcctok.h
@ -100,6 +100,8 @@
|
|||||||
DEF(TOK_PACKED2, "__packed__")
|
DEF(TOK_PACKED2, "__packed__")
|
||||||
DEF(TOK_WEAK1, "weak")
|
DEF(TOK_WEAK1, "weak")
|
||||||
DEF(TOK_WEAK2, "__weak__")
|
DEF(TOK_WEAK2, "__weak__")
|
||||||
|
DEF(TOK_ALIAS1, "alias")
|
||||||
|
DEF(TOK_ALIAS2, "__alias__")
|
||||||
DEF(TOK_UNUSED1, "unused")
|
DEF(TOK_UNUSED1, "unused")
|
||||||
DEF(TOK_UNUSED2, "__unused__")
|
DEF(TOK_UNUSED2, "__unused__")
|
||||||
DEF(TOK_CDECL1, "cdecl")
|
DEF(TOK_CDECL1, "cdecl")
|
||||||
|
Loading…
Reference in New Issue
Block a user