[PECOFF][Writer] Fix SizeOfImage header. It should include the first unmapped page.
llvm-svn: 185534
This commit is contained in:
		
							parent
							
								
									9d2e202d65
								
							
						
					
					
						commit
						4eca75df00
					
				| 
						 | 
					@ -566,20 +566,18 @@ private:
 | 
				
			||||||
    // there's no technical reason to do so, but we'll follow that convention
 | 
					    // there's no technical reason to do so, but we'll follow that convention
 | 
				
			||||||
    // so that we don't produce odd-looking binary. We should update the code
 | 
					    // so that we don't produce odd-looking binary. We should update the code
 | 
				
			||||||
    // (or this comment) once we figure the reason out.
 | 
					    // (or this comment) once we figure the reason out.
 | 
				
			||||||
    uint32_t offset = PAGE_SIZE;
 | 
					    uint32_t rva = PAGE_SIZE;
 | 
				
			||||||
    uint32_t va = offset;
 | 
					 | 
				
			||||||
    for (auto &cp : _chunks) {
 | 
					    for (auto &cp : _chunks) {
 | 
				
			||||||
      if (SectionChunk *chunk = dyn_cast<SectionChunk>(&*cp)) {
 | 
					      if (SectionChunk *chunk = dyn_cast<SectionChunk>(&*cp)) {
 | 
				
			||||||
        chunk->setVirtualAddress(va);
 | 
					        chunk->setVirtualAddress(rva);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Skip the empty section.
 | 
					        // Skip the empty section.
 | 
				
			||||||
        if (chunk->size() == 0)
 | 
					        if (chunk->size() == 0)
 | 
				
			||||||
          continue;
 | 
					          continue;
 | 
				
			||||||
        numSections++;
 | 
					        numSections++;
 | 
				
			||||||
        va = llvm::RoundUpToAlignment(va + chunk->size(), PAGE_SIZE);
 | 
					        rva = llvm::RoundUpToAlignment(rva + chunk->size(), PAGE_SIZE);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    imageSize = va - offset;
 | 
					    imageSize = rva;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// Apply relocations to the output file buffer. This two pass. In the first
 | 
					  /// Apply relocations to the output file buffer. This two pass. In the first
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,7 +39,7 @@ FILE:   MajorImageVersion: 0
 | 
				
			||||||
FILE:   MinorImageVersion: 0
 | 
					FILE:   MinorImageVersion: 0
 | 
				
			||||||
FILE:   MajorSubsystemVersion: 3
 | 
					FILE:   MajorSubsystemVersion: 3
 | 
				
			||||||
FILE:   MinorSubsystemVersion: 11
 | 
					FILE:   MinorSubsystemVersion: 11
 | 
				
			||||||
FILE:   SizeOfImage: 4096
 | 
					FILE:   SizeOfImage: 8192
 | 
				
			||||||
FILE:   SizeOfHeaders: 512
 | 
					FILE:   SizeOfHeaders: 512
 | 
				
			||||||
FILE:   Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI (0x3)
 | 
					FILE:   Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI (0x3)
 | 
				
			||||||
FILE:   Subsystem [ (0x8540)
 | 
					FILE:   Subsystem [ (0x8540)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue