Skip to content

Commit 962c241

Browse files
aykevldylanmckay
authored andcommitted
[AVR] Do not place functions in .progmem.data
Previously, the AVR backend would put functions in .progmem.data. This is probably a regression from when functions still lived in address space 0. With this change, only global constants are placed in .progmem.data. This is not complete: avr-gcc additionally respects -fdata-sections for progmem global constants, which LLVM doesn't yet do. But fixing that is a bit more complicated (and I believe other backends such as RISC-V might also have similar issues). Differential Revision: https://reviews.llvm.org/D78212
1 parent 65b8b17 commit 962c241

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

llvm/lib/Target/AVR/AVRTargetObjectFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ AVRTargetObjectFile::SelectSectionForGlobal(const GlobalObject *GO,
3030
const TargetMachine &TM) const {
3131
// Global values in flash memory are placed in the progmem.data section
3232
// unless they already have a user assigned section.
33-
if (AVR::isProgramMemoryAddress(GO) && !GO->hasSection())
33+
if (AVR::isProgramMemoryAddress(GO) && !GO->hasSection() && Kind.isReadOnly())
3434
return ProgmemDataSection;
3535

3636
// Otherwise, we work the same way as ELF.

llvm/test/CodeGen/AVR/sections.ll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; RUN: llc < %s -march=avr | FileCheck --check-prefixes=CHECK,NOSECTIONS %s
2+
; RUN: llc -function-sections -data-sections < %s -march=avr | FileCheck --check-prefixes=CHECK,SECTIONS %s
3+
4+
; Test that functions (in address space 1) are not considered .progmem data.
5+
6+
; CHECK: .text
7+
; SECTIONS: .text.somefunc,"ax",@progbits
8+
; CHECK-LABEL: somefunc:
9+
define void @somefunc() addrspace(1) {
10+
ret void
11+
}
12+
13+
14+
; Test whether global variables are placed in the correct section.
15+
16+
; Note: avr-gcc would place this global in .progmem.data.flash with
17+
; -fdata-sections. The AVR backend does not yet respect -fdata-sections in this
18+
; case.
19+
; CHECK: .section .progmem.data,"a",@progbits
20+
; CHECK-LABEL: flash:
21+
@flash = addrspace(1) constant i16 3
22+
23+
; NOSECTIONS: .section .rodata,"a",@progbits
24+
; SECTIONS: .section .rodata.ram1,"a",@progbits
25+
; CHECK-LABEL: ram1:
26+
@ram1 = constant i16 3
27+
28+
; NOSECTIONS: .data
29+
; SECTIONS: .section .data.ram2,"aw",@progbits
30+
; CHECK-LABEL: ram2:
31+
@ram2 = global i16 3

0 commit comments

Comments
 (0)