[SPEC2DEF] Work-around a bug in MS linker handling of extern forwarders

This commit is contained in:
Jérôme Gardou 2020-11-25 14:26:53 +01:00 committed by Jérôme Gardou
parent d53b03e676
commit 5387a7ccb2

View file

@ -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)
{
@ -737,6 +749,15 @@ OutputLine_def(FILE *fileDest, EXPORT *pexp)
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, " ");