[lld-macho] Fix segment filesize calculation
authorJez Ng <jezng@fb.com>
Tue, 28 Jul 2020 16:56:55 +0000 (09:56 -0700)
committerJez Ng <jezng@fb.com>
Tue, 28 Jul 2020 17:02:19 +0000 (10:02 -0700)
commitd32e32500f92602ccedcf967df2915da6f3803d2
tree68cd6850eb6e883225c3b0d5fde897d3f1c36a35
parent4853a86022feee1b16249cc7a0ea12c842fa5986
[lld-macho] Fix segment filesize calculation

The previous approach of adding up the file sizes of the
component sections ignored the fact that the sections did not have to be
contiguous in the file. As such, it was underestimating the true size.

I discovered this issue because `codesign` checks whether `__LINKEDIT`
extends to the end of the file. Since we were underestimating segment
sizes, this check failed.

Reviewed By: #lld-macho, compnerd

Differential Revision: https://reviews.llvm.org/D84574
lld/MachO/Writer.cpp
lld/test/MachO/section-headers.s
lld/test/MachO/segments.s