From 73ab44c17866c61ba9a725ee42c0505b94efe65b Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 16 Nov 2021 01:39:32 +0100 Subject: [PATCH] builder: support -size= flag on the esp32 This fixes a small mistake when calculating binary size for an Xtensa file. Previously it would exit with the following error: $ tinygo build -o test.elf -size=short -target=esp32-mini32 examples/serial panic: runtime error: index out of range [65521] with length 18 Now it runs as expected: $ tinygo build -o test.elf -size=short -target=esp32-mini32 examples/serial code data bss | flash ram 2897 0 4136 | 2897 4136 --- builder/sizes.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/builder/sizes.go b/builder/sizes.go index f7e72049..7297f42f 100644 --- a/builder/sizes.go +++ b/builder/sizes.go @@ -288,6 +288,13 @@ func loadProgramSize(path string, packagePathMap map[string]string) (*programSiz if symType != elf.STT_FUNC && symType != elf.STT_OBJECT && symType != elf.STT_NOTYPE { continue } + if symbol.Section >= elf.SHN_LORESERVE { + // Not a regular section, so skip it. + // One example is elf.SHN_ABS, which is used for symbols + // declared with an absolute value such as the memset function + // on the ESP32 which is defined in the mask ROM. + continue + } section := file.Sections[symbol.Section] if section.Flags&elf.SHF_ALLOC == 0 { continue