在 2025-3-8 10:57, LIU Hao 写道:
As said above, ideally all the pieces in `.idata` and `.didat`, other than `.didat$5`, should be put into `.rdata` and not entire new sections on their own. I previously attempted to move `R_IDATA` etc. into `.rdata` but the program crashed upon startup.

In our delayimp.c there's:

   ```
   static unsigned IndexFromPImgThunkData(PCImgThunkData pitdCur,PCImgThunkData 
pitdBase)
   {
     return (unsigned) (pitdCur - pitdBase);
   }

   // ... ...

   FARPROC WINAPI __delayLoadHelper2(PCImgDelayDescr pidd,FARPROC *ppfnIATEntry)
   {
     // ... ...

     unsigned iIAT, iINT;

     // ... ...

     iIAT = IndexFromPImgThunkData((PCImgThunkData)(ppfnIATEntry),idd.pIAT);
     iINT = iIAT;

     // ... ...
   }
   ```

On a 64-bit system, this truncates the difference from `ppfnIATEntry` to `idd.pIAT` to 32 bits then zero-extend it back, which can cause trouble if the difference is negative.

Because of the layout of `.didat` (and the mistaken `.idata`), at the moment the difference can't be negative. However I suggest we change this to

   ```
   FARPROC WINAPI __delayLoadHelper2(PCImgDelayDescr pidd,FARPROC *ppfnIATEntry)
   {
     // ... ...

     ptrdiff_t iIAT, iINT;

     // ... ...

     iIAT = (PCImgThunkData)(ppfnIATEntry) - idd.pIAT;
     iINT = iIAT;

     // ... ...
   }
   ```




--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to