[lld] 28d05d6 - [ELF][PPC64] Fix potentially corrupted section content with empty .got

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 5 15:23:04 PDT 2022


Author: Fangrui Song
Date: 2022-08-05T15:22:57-07:00
New Revision: 28d05d672300e51f53c73fe9a4bd053e73844247

URL: https://github.com/llvm/llvm-project/commit/28d05d672300e51f53c73fe9a4bd053e73844247
DIFF: https://github.com/llvm/llvm-project/commit/28d05d672300e51f53c73fe9a4bd053e73844247.diff

LOG: [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.

Added: 
    

Modified: 
    lld/ELF/SyntheticSections.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index a33f79b628eb2..ff48f085a2d75 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -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);
 }


        


More information about the llvm-commits mailing list