@@ -828,33 +828,45 @@ bool Writer::fixGnuImportChunks() {
828
828
// terminator in .idata$2.
829
829
void Writer::addSyntheticIdata () {
830
830
uint32_t rdata = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ;
831
+ uint32_t INIT2 = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ |
832
+ IMAGE_SCN_MEM_WRITE | IMAGE_SCN_MEM_DISCARDABLE |
833
+ IMAGE_SCN_MEM_NOT_PAGED;
834
+ uint32_t selectOutChars = ctx.config .driver ? INIT2 : rdata;
835
+
831
836
idata.create (ctx);
832
837
833
838
// Add the .idata content in the right section groups, to allow
834
839
// chunks from other linked in object files to be grouped together.
835
840
// See Microsoft PE/COFF spec 5.4 for details.
836
- auto add = [&](StringRef n, std::vector<Chunk *> &v) {
837
- PartialSection *pSec = createPartialSection (n, rdata );
841
+ auto add = [&](StringRef n, std::vector<Chunk *> &v, uint32_t outChars ) {
842
+ PartialSection *pSec = createPartialSection (n, outChars );
838
843
pSec->chunks .insert (pSec->chunks .end (), v.begin (), v.end ());
839
844
};
840
845
841
846
// The loader assumes a specific order of data.
842
847
// Add each type in the correct order.
843
- add (ctx.config .driver ? " INIT$2" : " .idata$2" , idata.dirs );
844
- add (ctx.config .driver ? " INIT$4" : " .idata$4" , idata.lookups );
845
- add (" .idata$5" , idata.addresses );
848
+ add (ctx.config .driver ? " INIT2$2" : " .idata$2" , idata.dirs , selectOutChars);
849
+ add (ctx.config .driver ? " INIT2$4" : " .idata$4" , idata.lookups ,
850
+ selectOutChars);
851
+ add (" .idata$5" , idata.addresses , rdata);
846
852
if (!idata.hints .empty ())
847
- add (ctx.config .driver ? " INIT$6" : " .idata$6" , idata.hints );
848
- add (ctx.config .driver ? " INIT$7" : " .idata$7" , idata.dllNames );
853
+ add (ctx.config .driver ? " INIT2$6" : " .idata$6" , idata.hints ,
854
+ selectOutChars);
855
+ add (ctx.config .driver ? " INIT2$7" : " .idata$7" , idata.dllNames ,
856
+ selectOutChars);
849
857
}
850
858
851
859
// Locate the first Chunk and size of the import directory list and the
852
860
// IAT.
853
861
void Writer::locateImportTables () {
854
862
uint32_t rdata = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ;
863
+ uint32_t INIT2 = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ |
864
+ IMAGE_SCN_MEM_WRITE | IMAGE_SCN_MEM_DISCARDABLE |
865
+ IMAGE_SCN_MEM_NOT_PAGED;
866
+ uint32_t selectOutChars = ctx.config .driver ? INIT2 : rdata;
855
867
856
868
if (PartialSection *importDirs = findPartialSection (
857
- ctx.config .driver ? " INIT $2" : " .idata$2" , rdata )) {
869
+ ctx.config .driver ? " INIT2 $2" : " .idata$2" , selectOutChars )) {
858
870
if (!importDirs->chunks .empty ())
859
871
importTableStart = importDirs->chunks .front ();
860
872
for (Chunk *c : importDirs->chunks )
0 commit comments