Support aliasing static global nonfunction objects
Enables code such as: #undef NDEBUG #include <assert.h> #include <stdint.h> static int st_x = 42; static int st_x_ __attribute((alias("st_x"))); int main(void){ assert((uintptr_t)&st_x == (uintptr_t)&st_x_); } which would previously fail with no compiler warnings. The limitation of this is that the alias must be done (or redone) after an actual definition. An alias done right after a later overridden tentative declaration won't work (sufficient for my use case).
This commit is contained in:
parent
b214fb6ed3
commit
08c777053c
1 changed files with 10 additions and 0 deletions
10
tccgen.c
10
tccgen.c
|
@ -8661,6 +8661,16 @@ static int decl(int l)
|
||||||
else if (l == VT_CONST)
|
else if (l == VT_CONST)
|
||||||
/* uninitialized global variables may be overridden */
|
/* uninitialized global variables may be overridden */
|
||||||
type.t |= VT_EXTERN;
|
type.t |= VT_EXTERN;
|
||||||
|
|
||||||
|
if (ad.alias_target && 1) {
|
||||||
|
Sym *alias_target = sym_find(ad.alias_target);
|
||||||
|
ElfSym *esym = elfsym(alias_target);
|
||||||
|
if (!esym) tcc_error("unsupported forward __alias__ attribute");
|
||||||
|
sym = external_sym(v, &type, r, &ad);
|
||||||
|
put_extern_sym2(sym, esym->st_shndx,
|
||||||
|
esym->st_value, esym->st_size, 1);
|
||||||
|
}
|
||||||
|
|
||||||
decl_initializer_alloc(&type, &ad, r, has_init, v, l == VT_CONST);
|
decl_initializer_alloc(&type, &ad, r, has_init, v, l == VT_CONST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue