[lld-macho] Ensure __bss sections we output have file offset of zero
authorJez Ng <jezng@fb.com>
Sun, 14 Jun 2020 03:00:36 +0000 (20:00 -0700)
committerJez Ng <jezng@fb.com>
Thu, 18 Jun 2020 03:41:28 +0000 (20:41 -0700)
commit74871cdad729aa5a5f39804214e5872f8e418d8e
treee1648678996fd927eebde4d4e6e4f44714a37726
parenta12e7d406de2c31633414e5c73881869c930d194
[lld-macho] Ensure __bss sections we output have file offset of zero

Summary:
llvm-mc emits `__bss` sections with an offset of zero, but we weren't expecting
that in our input, so we were copying non-zero data from the start of the file and
putting it in `__bss`, with obviously undesirable runtime results. (It appears that
the kernel will copy those nonzero bytes as long as the offset is nonzero, regardless
of whether S_ZERO_FILL is set.)

I debated on whether to make a special ZeroFillSection -- separate from a
regular InputSection -- but it seemed like too much work for now. But I'm happy
to refactor if anyone feels strongly about having it as a separate class.

Depends on D80857.

Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee

Reviewed By: smeenai

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80859
lld/MachO/InputFiles.cpp
lld/MachO/InputSection.cpp
lld/MachO/InputSection.h
lld/MachO/SyntheticSections.cpp
lld/MachO/Writer.cpp
lld/test/MachO/bss.s [new file with mode: 0644]