https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5387a7ccb2ed0dc5bc39ed3d946c0f761bcce37b
commit 5387a7ccb2ed0dc5bc39ed3d946c0f761bcce37b Author: Jérôme Gardou <jerome.gar...@reactos.org> AuthorDate: Wed Nov 25 14:26:53 2020 +0100 Commit: Jérôme Gardou <zefk...@users.noreply.github.com> CommitDate: Mon Dec 28 12:13:30 2020 +0100 [SPEC2DEF] Work-around a bug in MS linker handling of extern forwarders --- sdk/tools/spec2def/spec2def.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sdk/tools/spec2def/spec2def.c b/sdk/tools/spec2def/spec2def.c index 9fc4d8cda45..8eb12c1d84d 100644 --- a/sdk/tools/spec2def/spec2def.c +++ b/sdk/tools/spec2def/spec2def.c @@ -244,6 +244,18 @@ OutputLine_stub(FILE *file, EXPORT *pexp) int bRelay = 0; int bInPrototype = 0; + /* Workaround for forwarded externs. See here for an explanation: + * https://stackoverflow.com/questions/4060143/forwarding-data-in-a-dll */ + if (gbMSComp && + (pexp->nCallingConvention == CC_EXTERN) && + (pexp->strTarget.buf != NULL) && + (!!ScanToken(pexp->strTarget.buf, '.'))) + { + fprintf(file, "#pragma comment(linker,\"/export:%s%.*s=%.*s,DATA\")\n\n", + gpszUnderscore, pexp->strName.len, pexp->strName.buf, pexp->strTarget.len, pexp->strTarget.buf); + return 0; + } + if (pexp->nCallingConvention != CC_STUB && (pexp->uFlags & FL_STUB) == 0) { @@ -736,6 +748,15 @@ OutputLine_def(FILE *fileDest, EXPORT *pexp) DbgPrint("OutputLine_def: skipping private export '%.*s'...\n", pexp->strName.len, pexp->strName.buf); return 1; } + + /* For MS linker, forwarded externs are managed via #pragma comment(linker,"/export:_data=org.data,DATA") */ + if (gbMSComp && !gbImportLib && (pexp->nCallingConvention == CC_EXTERN) && + (pexp->strTarget.buf != NULL) && !!ScanToken(pexp->strTarget.buf, '.')) + { + DbgPrint("OutputLine_def: skipping forwarded extern export '%.*s' ->'%.*s'...\n", + pexp->strName.len, pexp->strName.buf, pexp->strTarget.len, pexp->strTarget.buf); + return 1; + } DbgPrint("OutputLine_def: '%.*s'...\n", pexp->strName.len, pexp->strName.buf); fprintf(fileDest, " ");