Skip to content

Commit 1e9daa0

Browse files
dylanmckaydylanmckay
dylanmckay
authored andcommitted
[AVR] Enable the '__do_copy_data' function
Also enables '__do_clear_bss'. These functions are automaticalled called by the CRT if they are declared. We need these to be called otherwise RAM will start completely uninitialised, even though we need to copy RAM variables from progmem to RAM. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312905 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b5ec409 commit 1e9daa0

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

lib/Target/AVR/MCTargetDesc/AVRTargetStreamer.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,32 @@
1313

1414
#include "AVRTargetStreamer.h"
1515

16+
#include "llvm/MC/MCContext.h"
17+
1618
namespace llvm {
1719

1820
AVRTargetStreamer::AVRTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
1921

2022
AVRTargetAsmStreamer::AVRTargetAsmStreamer(MCStreamer &S)
2123
: AVRTargetStreamer(S) {}
2224

25+
void AVRTargetStreamer::finish() {
26+
MCStreamer &OS = getStreamer();
27+
MCContext &Context = OS.getContext();
28+
29+
MCSymbol *DoCopyData = Context.getOrCreateSymbol("__do_copy_data");
30+
MCSymbol *DoClearBss = Context.getOrCreateSymbol("__do_clear_bss");
31+
32+
// FIXME: We can disable __do_copy_data if there are no static RAM variables.
33+
34+
OS.emitRawComment(" Declaring this symbol tells the CRT that it should");
35+
OS.emitRawComment("copy all variables from program memory to RAM on startup");
36+
OS.EmitSymbolAttribute(DoCopyData, MCSA_Global);
37+
38+
OS.emitRawComment(" Declaring this symbol tells the CRT that it should");
39+
OS.emitRawComment("clear the zeroed data section on startup");
40+
OS.EmitSymbolAttribute(DoClearBss, MCSA_Global);
41+
}
42+
2343
} // end namespace llvm
2444

lib/Target/AVR/MCTargetDesc/AVRTargetStreamer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class MCStreamer;
1919
class AVRTargetStreamer : public MCTargetStreamer {
2020
public:
2121
explicit AVRTargetStreamer(MCStreamer &S);
22+
23+
void finish() override;
2224
};
2325

2426
/// A target streamer for textual AVR assembly code.

test/CodeGen/AVR/clear-bss.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
; RUN: llc < %s -march=avr | FileCheck %s
2+
3+
; CHECK: .globl __do_clear_bss
4+
@zeroed = internal constant [3 x i8] zeroinitializer
5+

test/CodeGen/AVR/copy-data-to-ram.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
; RUN: llc < %s -march=avr | FileCheck %s
2+
3+
; CHECK: .globl __do_copy_data
4+
@str = internal global [3 x i8] c"foo"
5+

0 commit comments

Comments
 (0)