Skip to content

Commit 9e453a5

Browse files
aykevldeadprogram
authored andcommitted
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.
1 parent a08d3aa commit 9e453a5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

builder/sizes.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,18 @@ func loadProgramSize(path string) (*programSize, error) {
8484
if section.Type != elf.SHT_PROGBITS && section.Type != elf.SHT_NOBITS {
8585
continue
8686
}
87-
if section.Type == elf.SHT_NOBITS {
87+
if section.Name == ".stack" {
88+
// HACK: this works around a bug in ld.lld from LLVM 10. The linker
89+
// marks sections with no input symbols (such as is the case for the
90+
// .stack section) as SHT_PROGBITS instead of SHT_NOBITS. While it
91+
// doesn't affect the generated binaries (.hex and .bin), it does
92+
// affect the reported size.
93+
// https://bugs.llvm.org/show_bug.cgi?id=45336
94+
// https://reviews.llvm.org/D76981
95+
// It has been merged in master, but it has not (yet) been
96+
// backported to the LLVM 10 release branch.
97+
sumBSS += section.Size
98+
} else if section.Type == elf.SHT_NOBITS {
8899
sumBSS += section.Size
89100
} else if section.Flags&elf.SHF_EXECINSTR != 0 {
90101
sumCode += section.Size

0 commit comments

Comments
 (0)