History

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.

Jonathan Newman committed 8 years ago

Commit 0edbed11 parent d79caa94 files · +12 −1Browse files

Unified · Split

4 files
  1. tcc-doc.texi +3 −0
  2. tcc.h +2 −1
  3. tccgen.c +6 −0
  4. tcctok.h +1 −0
tcc-doc.texi+3−0
@@ -548,6 +548,7 @@ instead of · 547 unmodified lines
548548 @cindex stdcall attribute
549549 @cindex regparm attribute
550550 @cindex dllexport attribute
551+@cindex nodecorate attribute
551552
552553 @item The keyword @code{__attribute__} is handled to specify variable or
553554 function attributes. The following attributes are supported:
@@ -575,6 +576,8 @@ registers @code{%eax}, @code{%edx} and @code{%ecx}. · 21 unmodified lines
575576
576577 @item @code{dllexport}: export function from dll/executable (win32 only)
577578
579+ @item @code{nodecorate}: do not apply any decorations that would otherwise be applied when exporting function from dll/executable (win32 only)
580+
578581 @end itemize
579582
580583 Here are some examples:
tcc.h+2−1
@@ -439,8 +439,9 @@ struct SymAttr { · 438 unmodified lines
439439 weak : 1,
440440 visibility : 2,
441441 dllexport : 1,
442+ nodecorate : 1,
442443 dllimport : 1,
443− unused : 5;
444+ unused : 4;
444445 };
445446
446447 /* function attributes or temporary attributes for parsing */
tccgen.c+6−0
@@ -391,6 +391,9 @@ ST_FUNC void put_extern_sym2(Sym *sym, int sh_num, · 390 unmodified lines
391391 #ifdef TCC_TARGET_PE
392392 if (sym_type == STT_FUNC && sym->type.ref) {
393393 Sym *ref = sym->type.ref;
394+ if (ref->a.nodecorate) {
395+ can_add_underscore = 0;
396+ }
394397 if (ref->f.func_call == FUNC_STDCALL && can_add_underscore) {
395398 sprintf(buf1, "_%s@%d", name, ref->f.func_args * PTR_SIZE);
396399 name = buf1;
@@ -3438,6 +3441,9 @@ redo: · 3041 unmodified lines
34383441 case TOK_DLLEXPORT:
34393442 ad->a.dllexport = 1;
34403443 break;
3444+ case TOK_NODECORATE:
3445+ ad->a.nodecorate = 1;
3446+ break;
34413447 case TOK_DLLIMPORT:
34423448 ad->a.dllimport = 1;
34433449 break;
tcctok.h+1−0
@@ -132,6 +132,7 @@ · 131 unmodified lines
132132
133133 DEF(TOK_DLLEXPORT, "dllexport")
134134 DEF(TOK_DLLIMPORT, "dllimport")
135+ DEF(TOK_NODECORATE, "nodecorate")
135136 DEF(TOK_NORETURN1, "noreturn")
136137 DEF(TOK_NORETURN2, "__noreturn__")
137138 DEF(TOK_VISIBILITY1, "visibility")

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