From 9e453a5a291e9dabf8a9209a2f99ed0f09f8e692 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Fri, 3 Apr 2020 21:40:39 +0200 Subject: [PATCH] builder: work around a bug in ld.lld in LLVM 10 See comment in the commit for details. It works around a bug that's been reported here: https://bugs.llvm.org/show_bug.cgi?id=45336 This is a separate commit so it can easily be reverted if/when this patch is backported to the LLVM 10 stable branch. --- builder/sizes.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/builder/sizes.go b/builder/sizes.go index c88c9b7b..750c4bd9 100644 --- a/builder/sizes.go +++ b/builder/sizes.go @@ -84,7 +84,18 @@ func loadProgramSize(path string) (*programSize, error) { if section.Type != elf.SHT_PROGBITS && section.Type != elf.SHT_NOBITS { continue } - if section.Type == elf.SHT_NOBITS { + if section.Name == ".stack" { + // HACK: this works around a bug in ld.lld from LLVM 10. The linker + // marks sections with no input symbols (such as is the case for the + // .stack section) as SHT_PROGBITS instead of SHT_NOBITS. While it + // doesn't affect the generated binaries (.hex and .bin), it does + // affect the reported size. + // https://bugs.llvm.org/show_bug.cgi?id=45336 + // https://reviews.llvm.org/D76981 + // It has been merged in master, but it has not (yet) been + // backported to the LLVM 10 release branch. + sumBSS += section.Size + } else if section.Type == elf.SHT_NOBITS { sumBSS += section.Size } else if section.Flags&elf.SHF_EXECINSTR != 0 { sumCode += section.Size