[ELF][PPC64] Fix potentially corrupted section content with empty .got

D91426 makes .got possibly empty while needed. If .got and .data have the same
address, and .got's content is written after .data, the first word of .data will
be corrupted.

The bug is not testable without D131247.
This commit is contained in:
Fangrui Song 2022-08-05 15:22:57 -07:00
parent 5f1c7e2cc5
commit 28d05d6723
1 changed files with 3 additions and 0 deletions

View File

@ -678,6 +678,9 @@ bool GotSection::isNeeded() const {
}
void GotSection::writeTo(uint8_t *buf) {
// On PPC64 .got may be needed but empty. Skip the write.
if (size == 0)
return;
target->writeGotHeader(buf);
relocateAlloc(buf, buf + size);
}