Skip to content

Commit 34c887f

Browse files
committed
Merging r312905:
------------------------------------------------------------------------ r312905 | dylanmckay | 2017-09-11 22:32:51 +1200 (Mon, 11 Sep 2017) | 10 lines [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. ------------------------------------------------------------------------ llvm-svn: 314356
1 parent 7f6d22c commit 34c887f

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

llvm/lib/Target/AVR/MCTargetDesc/AVRTargetStreamer.cpp

+20
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

llvm/lib/Target/AVR/MCTargetDesc/AVRTargetStreamer.h

+2
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.

llvm/test/CodeGen/AVR/clear-bss.ll

+5
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+
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)