@@ -781,8 +781,8 @@ OutputLine_def(FILE *fileDest, EXPORT *pexp)
781781 else
782782 OutputLine_def_GCC (fileDest , pexp );
783783
784- /* On GCC builds we force ordinals */
785- if ((pexp -> uFlags & FL_ORDINAL ) || (! gbMSComp && ! gbImportLib ) )
784+ /* If it is not an import lib, we force ordinals */
785+ if ((pexp -> uFlags & FL_ORDINAL ) || ! gbImportLib )
786786 {
787787 fprintf (fileDest , " @%d" , pexp -> nOrdinal );
788788 }
@@ -1421,6 +1421,7 @@ ApplyOrdinals(EXPORT* pexports, unsigned cExports)
14211421{
14221422 unsigned short i , j ;
14231423 char * used ;
1424+ unsigned short firstOrdinal = 0xFFFF , firstIndex = 0 ;
14241425
14251426 /* Allocate a table to mark used ordinals */
14261427 used = malloc (65536 );
@@ -1442,11 +1443,28 @@ ApplyOrdinals(EXPORT* pexports, unsigned cExports)
14421443 return -1 ;
14431444 }
14441445 used [pexports [i ].nOrdinal ] = 1 ;
1446+ if (pexports [i ].nOrdinal < firstOrdinal )
1447+ {
1448+ firstOrdinal = pexports [i ].nOrdinal ;
1449+ firstIndex = i ;
1450+ }
14451451 }
14461452 }
14471453
1454+ /* Check if we found an ordinal and it's larger than it's index */
1455+ if ((firstOrdinal != 0xFFFF ) && (firstOrdinal > firstIndex ))
1456+ {
1457+ /* We did. Calculate an appropriate starting ordinal. */
1458+ firstOrdinal -= firstIndex ;
1459+ }
1460+ else
1461+ {
1462+ /* We didn't, so start with 1 */
1463+ firstOrdinal = 1 ;
1464+ }
1465+
14481466 /* Pass 2: apply available ordinals */
1449- for (i = 0 , j = 1 ; i < cExports ; i ++ )
1467+ for (i = 0 , j = firstOrdinal ; i < cExports ; i ++ )
14501468 {
14511469 if ((pexports [i ].uFlags & FL_ORDINAL ) == 0 && pexports [i ].bVersionIncluded )
14521470 {
@@ -1640,13 +1658,10 @@ int main(int argc, char *argv[])
16401658 return -1 ;
16411659 }
16421660
1643- if (! gbMSComp )
1661+ if (ApplyOrdinals ( pexports , cExports ) < 0 )
16441662 {
1645- if (ApplyOrdinals (pexports , cExports ) < 0 )
1646- {
1647- fprintf (stderr , "error: could not apply ordinals!\n" );
1648- return -1 ;
1649- }
1663+ fprintf (stderr , "error: could not apply ordinals!\n" );
1664+ return -1 ;
16501665 }
16511666
16521667 if (pszDefFileName )
0 commit comments