Skip to content

Commit 9c9296f

Browse files
authored
Update Writer.cpp
1 parent 123ff9c commit 9c9296f

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

lld/COFF/Writer.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -828,33 +828,45 @@ bool Writer::fixGnuImportChunks() {
828828
// terminator in .idata$2.
829829
void Writer::addSyntheticIdata() {
830830
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+
831836
idata.create(ctx);
832837

833838
// Add the .idata content in the right section groups, to allow
834839
// chunks from other linked in object files to be grouped together.
835840
// 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);
838843
pSec->chunks.insert(pSec->chunks.end(), v.begin(), v.end());
839844
};
840845

841846
// The loader assumes a specific order of data.
842847
// 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);
846852
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);
849857
}
850858

851859
// Locate the first Chunk and size of the import directory list and the
852860
// IAT.
853861
void Writer::locateImportTables() {
854862
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;
855867

856868
if (PartialSection *importDirs = findPartialSection(
857-
ctx.config.driver ? "INIT$2" : ".idata$2", rdata)) {
869+
ctx.config.driver ? "INIT2$2" : ".idata$2", selectOutChars)) {
858870
if (!importDirs->chunks.empty())
859871
importTableStart = importDirs->chunks.front();
860872
for (Chunk *c : importDirs->chunks)

0 commit comments

Comments
 (0)