[lld] 85a2f29 - [lld][COFF] Fix bug causing assertion in Chunk::setAlignment

Andrew Ng via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 10 06:21:03 PST 2023


Author: Andrew Ng
Date: 2023-01-10T14:19:53Z
New Revision: 85a2f29fd485d29e6a93de6f0c2bfdc009d06a56

URL: https://github.com/llvm/llvm-project/commit/85a2f29fd485d29e6a93de6f0c2bfdc009d06a56
DIFF: https://github.com/llvm/llvm-project/commit/85a2f29fd485d29e6a93de6f0c2bfdc009d06a56.diff

LOG: [lld][COFF] Fix bug causing assertion in Chunk::setAlignment

Reinstate use of FakeSection class to avoid constructing SectionChunk
from unintialised coff_section in FakeSectionChunk constructor.

Issue was caused by commit 5a58b19f9c93f3ac51bcde318508131ae78aa10c,
"[LLD] Remove global state in lld/COFF".

Added: 
    

Modified: 
    lld/COFF/COFFLinkerContext.cpp
    lld/COFF/COFFLinkerContext.h
    lld/COFF/Chunks.h

Removed: 
    


################################################################################
diff  --git a/lld/COFF/COFFLinkerContext.cpp b/lld/COFF/COFFLinkerContext.cpp
index 43902fdad042..2aba87d71603 100644
--- a/lld/COFF/COFFLinkerContext.cpp
+++ b/lld/COFF/COFFLinkerContext.cpp
@@ -19,8 +19,10 @@
 namespace lld::coff {
 COFFLinkerContext::COFFLinkerContext()
     : driver(*this), symtab(*this),
-      ltoTextSectionChunk(llvm::COFF::IMAGE_SCN_MEM_EXECUTE),
-      ltoDataSectionChunk(llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA),
+      ltoTextSection(llvm::COFF::IMAGE_SCN_MEM_EXECUTE),
+      ltoDataSection(llvm::COFF::IMAGE_SCN_CNT_INITIALIZED_DATA),
+      ltoTextSectionChunk(&ltoTextSection.section),
+      ltoDataSectionChunk(&ltoDataSection.section),
       rootTimer("Total Linking Time"),
       inputFileTimer("Input File Reading", rootTimer),
       ltoTimer("LTO", rootTimer), gcTimer("GC", rootTimer),

diff  --git a/lld/COFF/COFFLinkerContext.h b/lld/COFF/COFFLinkerContext.h
index 311cfb5b7125..059d4aeddc6e 100644
--- a/lld/COFF/COFFLinkerContext.h
+++ b/lld/COFF/COFFLinkerContext.h
@@ -56,6 +56,8 @@ class COFFLinkerContext : public CommonLinkerContext {
   }
 
   // Fake sections for parsing bitcode files.
+  FakeSection ltoTextSection;
+  FakeSection ltoDataSection;
   FakeSectionChunk ltoTextSectionChunk;
   FakeSectionChunk ltoDataSectionChunk;
 

diff  --git a/lld/COFF/Chunks.h b/lld/COFF/Chunks.h
index f5335fd3d7b6..9d9e73870ccb 100644
--- a/lld/COFF/Chunks.h
+++ b/lld/COFF/Chunks.h
@@ -715,18 +715,24 @@ void applyArm64Addr(uint8_t *off, uint64_t s, uint64_t p, int shift);
 void applyArm64Imm(uint8_t *off, uint64_t imm, uint32_t rangeLimit);
 void applyArm64Branch26(uint8_t *off, int64_t v);
 
+// Convenience class for initializing a coff_section with specific flags.
+class FakeSection {
+public:
+  FakeSection(int c) { section.Characteristics = c; }
+
+  coff_section section;
+};
+
 // Convenience class for initializing a SectionChunk with specific flags.
 class FakeSectionChunk {
 public:
-  FakeSectionChunk(int c) : chunk(nullptr, &section) {
-    section.Characteristics = c;
+  FakeSectionChunk(const coff_section *section) : chunk(nullptr, section) {
     // Comdats from LTO files can't be fully treated as regular comdats
     // at this point; we don't know what size or contents they are going to
     // have, so we can't do proper checking of such aspects of them.
     chunk.selection = llvm::COFF::IMAGE_COMDAT_SELECT_ANY;
   }
 
-  coff_section section;
   SectionChunk chunk;
 };
 


        


More information about the llvm-commits mailing list