[PATCH] D54495: [LLD] [COFF] Remove empty sections before calculating the size of section headers

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 13 23:22:11 PST 2018


mstorsjo added inline comments.


================
Comment at: COFF/Writer.cpp:888-892
+  auto IsEmpty = [](OutputSection *S) {
+    for (Chunk *C : S->Chunks)
+      if (C->getSize() > 0)
+        return false;
+    return true;
----------------
ruiu wrote:
> It feels like `S->getVirtualSize()` should return 0 if all sections in it are empty. Can you fix the code computing output section size instead of computing a bogus value as a size and then remove such section here?
`S->getVirtualSize()` doesn't do any calculation at all, it only returns `Header.VirtualSize` (where `Header` is a `llvm::object::coff_section` which will be written to disk as is). If we'd make `getVirtualSize()` actually do the calculation, it'd redo it every time we query it later.

Or should we move this into a `isEmpty()` helper method in `OutputSection` instead?


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D54495





More information about the llvm-commits mailing list