diff --git a/llvm/lib/Target/AVR/AVRTargetObjectFile.cpp b/llvm/lib/Target/AVR/AVRTargetObjectFile.cpp --- a/llvm/lib/Target/AVR/AVRTargetObjectFile.cpp +++ b/llvm/lib/Target/AVR/AVRTargetObjectFile.cpp @@ -30,7 +30,7 @@ const TargetMachine &TM) const { // Global values in flash memory are placed in the progmem.data section // unless they already have a user assigned section. - if (AVR::isProgramMemoryAddress(GO) && !GO->hasSection()) + if (AVR::isProgramMemoryAddress(GO) && !GO->hasSection() && Kind.isReadOnly()) return ProgmemDataSection; // Otherwise, we work the same way as ELF. diff --git a/llvm/test/CodeGen/AVR/sections.ll b/llvm/test/CodeGen/AVR/sections.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/AVR/sections.ll @@ -0,0 +1,28 @@ +; RUN: llc < %s -march=avr | FileCheck --check-prefixes=CHECK,NOSECTIONS %s +; RUN: llc -function-sections -data-sections < %s -march=avr | FileCheck --check-prefixes=CHECK,SECTIONS %s + +; Test that functions (in address space 1) are not considered .progmem data. + +; CHECK: .text +; SECTIONS: .text.somefunc,"ax",@progbits +; CHECK-LABEL: somefunc: +define void @somefunc() addrspace(1) { + ret void +} + +; Test whether global variables are placed in the correct section. + +; CHECK: .section .progmem.data,"a",@progbits +; CHECK-LABEL: flash: +@flash = addrspace(1) constant i16 3 + + +; NOSECTIONS: .section .rodata,"a",@progbits +; SECTIONS: .section .rodata.ram1,"a",@progbits +; CHECK-LABEL: ram1: +@ram1 = constant i16 3 + +; NOSECTIONS: .data +; SECTIONS: .section .data.ram2,"aw",@progbits +; CHECK-LABEL: ram2: +@ram2 = global i16 3