mirror of
https://github.com/mirror/tinycc.git
synced 2025-02-04 06:30:10 +08:00
Implement __attribute__((nodecorate))
Prevent any decoration that would otherwise affect an exported PE function. For example, given the following: __declspec(dllexport) __stdcall int decorated(int arg) { return 0; } __declspec(dllexport) __stdcall __attribute__((nodecorate)) int undecorated(int arg) { return 0; } The following exported functions can now be seen in the DLL: _decorated@4 undecorated The attribute is recognised for all targets but only affects PE codegen. I'm not sure whether this would be useful for other targets; its intended use was to allow the creation of a DLL matching an existing set of signatures.
This commit is contained in:
parent
d79caa9ff6
commit
0edbed1d52
@ -548,6 +548,7 @@ instead of
|
|||||||
@cindex stdcall attribute
|
@cindex stdcall attribute
|
||||||
@cindex regparm attribute
|
@cindex regparm attribute
|
||||||
@cindex dllexport attribute
|
@cindex dllexport attribute
|
||||||
|
@cindex nodecorate attribute
|
||||||
|
|
||||||
@item The keyword @code{__attribute__} is handled to specify variable or
|
@item The keyword @code{__attribute__} is handled to specify variable or
|
||||||
function attributes. The following attributes are supported:
|
function attributes. The following attributes are supported:
|
||||||
@ -575,6 +576,8 @@ registers @code{%eax}, @code{%edx} and @code{%ecx}.
|
|||||||
|
|
||||||
@item @code{dllexport}: export function from dll/executable (win32 only)
|
@item @code{dllexport}: export function from dll/executable (win32 only)
|
||||||
|
|
||||||
|
@item @code{nodecorate}: do not apply any decorations that would otherwise be applied when exporting function from dll/executable (win32 only)
|
||||||
|
|
||||||
@end itemize
|
@end itemize
|
||||||
|
|
||||||
Here are some examples:
|
Here are some examples:
|
||||||
|
3
tcc.h
3
tcc.h
@ -439,8 +439,9 @@ struct SymAttr {
|
|||||||
weak : 1,
|
weak : 1,
|
||||||
visibility : 2,
|
visibility : 2,
|
||||||
dllexport : 1,
|
dllexport : 1,
|
||||||
|
nodecorate : 1,
|
||||||
dllimport : 1,
|
dllimport : 1,
|
||||||
unused : 5;
|
unused : 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* function attributes or temporary attributes for parsing */
|
/* function attributes or temporary attributes for parsing */
|
||||||
|
6
tccgen.c
6
tccgen.c
@ -391,6 +391,9 @@ ST_FUNC void put_extern_sym2(Sym *sym, int sh_num,
|
|||||||
#ifdef TCC_TARGET_PE
|
#ifdef TCC_TARGET_PE
|
||||||
if (sym_type == STT_FUNC && sym->type.ref) {
|
if (sym_type == STT_FUNC && sym->type.ref) {
|
||||||
Sym *ref = sym->type.ref;
|
Sym *ref = sym->type.ref;
|
||||||
|
if (ref->a.nodecorate) {
|
||||||
|
can_add_underscore = 0;
|
||||||
|
}
|
||||||
if (ref->f.func_call == FUNC_STDCALL && can_add_underscore) {
|
if (ref->f.func_call == FUNC_STDCALL && can_add_underscore) {
|
||||||
sprintf(buf1, "_%s@%d", name, ref->f.func_args * PTR_SIZE);
|
sprintf(buf1, "_%s@%d", name, ref->f.func_args * PTR_SIZE);
|
||||||
name = buf1;
|
name = buf1;
|
||||||
@ -3438,6 +3441,9 @@ redo:
|
|||||||
case TOK_DLLEXPORT:
|
case TOK_DLLEXPORT:
|
||||||
ad->a.dllexport = 1;
|
ad->a.dllexport = 1;
|
||||||
break;
|
break;
|
||||||
|
case TOK_NODECORATE:
|
||||||
|
ad->a.nodecorate = 1;
|
||||||
|
break;
|
||||||
case TOK_DLLIMPORT:
|
case TOK_DLLIMPORT:
|
||||||
ad->a.dllimport = 1;
|
ad->a.dllimport = 1;
|
||||||
break;
|
break;
|
||||||
|
1
tcctok.h
1
tcctok.h
@ -132,6 +132,7 @@
|
|||||||
|
|
||||||
DEF(TOK_DLLEXPORT, "dllexport")
|
DEF(TOK_DLLEXPORT, "dllexport")
|
||||||
DEF(TOK_DLLIMPORT, "dllimport")
|
DEF(TOK_DLLIMPORT, "dllimport")
|
||||||
|
DEF(TOK_NODECORATE, "nodecorate")
|
||||||
DEF(TOK_NORETURN1, "noreturn")
|
DEF(TOK_NORETURN1, "noreturn")
|
||||||
DEF(TOK_NORETURN2, "__noreturn__")
|
DEF(TOK_NORETURN2, "__noreturn__")
|
||||||
DEF(TOK_VISIBILITY1, "visibility")
|
DEF(TOK_VISIBILITY1, "visibility")
|
||||||
|
Loading…
Reference in New Issue
Block a user