From 5a70c8848324c17683892507d622afd6a989eb45 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 21 Dec 2019 18:50:23 +0100 Subject: [PATCH] transform: make reflection sidetables constant globals These globals are (and must be!) never modified by the reflect package. By marking them as constant, they will be put in read-only memory. This reduces RAM consumption on microcontrollers. --- transform/reflect.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/transform/reflect.go b/transform/reflect.go index 9bfd1690..fcab9a06 100644 --- a/transform/reflect.go +++ b/transform/reflect.go @@ -160,21 +160,25 @@ func assignTypeCodes(mod llvm.Module, typeSlice typeInfoSlice) { global := replaceGlobalIntWithArray(mod, "reflect.namedNonBasicTypesSidetable", state.namedNonBasicTypesSidetable) global.SetLinkage(llvm.InternalLinkage) global.SetUnnamedAddr(true) + global.SetGlobalConstant(true) } if state.needsArrayTypesSidetable { global := replaceGlobalIntWithArray(mod, "reflect.arrayTypesSidetable", state.arrayTypesSidetable) global.SetLinkage(llvm.InternalLinkage) global.SetUnnamedAddr(true) + global.SetGlobalConstant(true) } if state.needsStructTypesSidetable { global := replaceGlobalIntWithArray(mod, "reflect.structTypesSidetable", state.structTypesSidetable) global.SetLinkage(llvm.InternalLinkage) global.SetUnnamedAddr(true) + global.SetGlobalConstant(true) } if state.needsStructNamesSidetable { global := replaceGlobalIntWithArray(mod, "reflect.structNamesSidetable", state.structNamesSidetable) global.SetLinkage(llvm.InternalLinkage) global.SetUnnamedAddr(true) + global.SetGlobalConstant(true) } }