Skip to content

Commit c310742

Browse files
committedNov 30, 2018
Do not assume .idata is zero-initialized.
We initialize .text section with 0xcc (INT3 instruction), so we need to explicitly write data even if it is zero if it can be in a .text section. If you specify /merge:.rdata=.text, .rdata (which contains .idata) is put to .text, so we need to do this. Fixes https://bugs.llvm.org/show_bug.cgi?id=39826 Differential Revision: https://reviews.llvm.org/D55098 llvm-svn: 348000
1 parent 81b77e9 commit c310742

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed
 

‎lld/COFF/Chunks.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ uint32_t CommonChunk::getOutputCharacteristics() const {
619619

620620
void StringChunk::writeTo(uint8_t *Buf) const {
621621
memcpy(Buf + OutputSectionOff, Str.data(), Str.size());
622+
Buf[OutputSectionOff + Str.size()] = '\0';
622623
}
623624

624625
ImportThunkChunkX64::ImportThunkChunkX64(Defined *S) : ImpSymbol(S) {

‎lld/COFF/DLL.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ class AddressTableChunk : public Chunk {
416416
size_t getSize() const override { return Size * 4; }
417417

418418
void writeTo(uint8_t *Buf) const override {
419+
memset(Buf + OutputSectionOff, 0, getSize());
420+
419421
for (const Export &E : Config->Exports) {
420422
uint8_t *P = Buf + OutputSectionOff + E.Ordinal * 4;
421423
uint32_t Bit = 0;

‎lld/test/COFF/export.test

+9
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,12 @@ FORWARDER: Ordinal RVA Name
9797
FORWARDER: 0 0
9898
FORWARDER: 1 0x1010 exportfn
9999
FORWARDER: 2 foo (forwarded to kernel32.foobar)
100+
101+
# RUN: lld-link /out:%t.dll /dll %t.obj /merge:.rdata=.text /export:exportfn1 /export:exportfn2
102+
# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=MERGE -match-full-lines %s
103+
104+
MERGE: DLL name: export.test.tmp.dll
105+
MERGE: Ordinal RVA Name
106+
MERGE-NEXT: 0 0
107+
MERGE-NEXT: 1 0x1008 exportfn1
108+
MERGE-NEXT: 2 0x1010 exportfn2

0 commit comments

Comments
 (0)