avr: properly support the .rodata section

Unfortunately, the .rodata section can't be stored in flash. Instead, an
explicit .progmem section should be used, which is supported in LLVM as
address space 1 but not exposed to normal programs.

Eventually a pass should be written that converts trivial const globals
of which all loads are visible to be in addrspace 1, to get the benefits
of storing those globals directly in ROM.
This commit is contained in:
Ayke van Laethem
2020-10-31 20:40:20 +01:00
committed by Ron Evans
parent 3364da6f25
commit 171f793c1e
6 changed files with 4 additions and 44 deletions
-13
View File
@@ -19,19 +19,6 @@ func ApplyFunctionSections(mod llvm.Module) {
}
}
// NonConstGlobals turns all global constants into global variables. This works
// around a limitation on Harvard architectures (e.g. AVR), where constant and
// non-constant pointers point to a different address space. Normal pointer
// behavior is restored by using the data space only, at the cost of RAM for
// constant global variables.
func NonConstGlobals(mod llvm.Module) {
global := mod.FirstGlobal()
for !global.IsNil() {
global.SetGlobalConstant(false)
global = llvm.NextGlobal(global)
}
}
// DisableTailCalls adds the "disable-tail-calls"="true" function attribute to
// all functions. This may be necessary, in particular to avoid an error with
// WebAssembly in LLVM 11.
-7
View File
@@ -12,10 +12,3 @@ func TestApplyFunctionSections(t *testing.T) {
ApplyFunctionSections(mod)
})
}
func TestNonConstGlobals(t *testing.T) {
t.Parallel()
testTransform(t, "testdata/globals-non-const", func(mod llvm.Module) {
NonConstGlobals(mod)
})
}
-5
View File
@@ -1,5 +0,0 @@
target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
target triple = "armv7em-none-eabi"
@globalIntConst = constant i32 3
@globalIntVar = global i32 5
-5
View File
@@ -1,5 +0,0 @@
target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
target triple = "armv7em-none-eabi"
@globalIntConst = global i32 3
@globalIntVar = global i32 5