https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7dcfda815c569ddcf2a7f…
commit 7dcfda815c569ddcf2a7f860a176be50cc942bff
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Fri Sep 13 21:06:20 2024 +0300
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Wed Oct 16 20:00:26 2024 +0300
[SPEC2DEF] Use explicit ordinals on MSVC, too
This prevents MSVC from reordering the exports in a way that doesn't match our
spec file. Also improve the algorithm to apply ordinals, by starting with the first
specified ordinal, possibly reserving ordinals for anything declared without an ordinal
before.
---
sdk/tools/spec2def/spec2def.c | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/sdk/tools/spec2def/spec2def.c b/sdk/tools/spec2def/spec2def.c
index 55955ee605e..36612eb4bfc 100644
--- a/sdk/tools/spec2def/spec2def.c
+++ b/sdk/tools/spec2def/spec2def.c
@@ -781,8 +781,8 @@ OutputLine_def(FILE *fileDest, EXPORT *pexp)
else
OutputLine_def_GCC(fileDest, pexp);
- /* On GCC builds we force ordinals */
- if ((pexp->uFlags & FL_ORDINAL) || (!gbMSComp && !gbImportLib))
+ /* If it is not an import lib, we force ordinals */
+ if ((pexp->uFlags & FL_ORDINAL) || !gbImportLib)
{
fprintf(fileDest, " @%d", pexp->nOrdinal);
}
@@ -1421,6 +1421,7 @@ ApplyOrdinals(EXPORT* pexports, unsigned cExports)
{
unsigned short i, j;
char* used;
+ unsigned short firstOrdinal = 0xFFFF, firstIndex = 0;
/* Allocate a table to mark used ordinals */
used = malloc(65536);
@@ -1442,11 +1443,28 @@ ApplyOrdinals(EXPORT* pexports, unsigned cExports)
return -1;
}
used[pexports[i].nOrdinal] = 1;
+ if (pexports[i].nOrdinal < firstOrdinal)
+ {
+ firstOrdinal = pexports[i].nOrdinal;
+ firstIndex = i;
+ }
}
}
+ /* Check if we found an ordinal and it's larger than it's index */
+ if ((firstOrdinal != 0xFFFF) && (firstOrdinal > firstIndex))
+ {
+ /* We did. Calculate an appropriate starting ordinal. */
+ firstOrdinal -= firstIndex;
+ }
+ else
+ {
+ /* We didn't, so start with 1 */
+ firstOrdinal = 1;
+ }
+
/* Pass 2: apply available ordinals */
- for (i = 0, j = 1; i < cExports; i++)
+ for (i = 0, j = firstOrdinal; i < cExports; i++)
{
if ((pexports[i].uFlags & FL_ORDINAL) == 0 &&
pexports[i].bVersionIncluded)
{
@@ -1640,13 +1658,10 @@ int main(int argc, char *argv[])
return -1;
}
- if (!gbMSComp)
+ if (ApplyOrdinals(pexports, cExports) < 0)
{
- if (ApplyOrdinals(pexports, cExports) < 0)
- {
- fprintf(stderr, "error: could not apply ordinals!\n");
- return -1;
- }
+ fprintf(stderr, "error: could not apply ordinals!\n");
+ return -1;
}
if (pszDefFileName)