15c96de3aSDylan McKay //===-- AVRTargetObjectFile.cpp - AVR Object Files ------------------------===//
25c96de3aSDylan McKay //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65c96de3aSDylan McKay //
75c96de3aSDylan McKay //===----------------------------------------------------------------------===//
85c96de3aSDylan McKay 
95c96de3aSDylan McKay #include "AVRTargetObjectFile.h"
105c96de3aSDylan McKay 
11264b5d9eSZachary Turner #include "llvm/BinaryFormat/ELF.h"
125c96de3aSDylan McKay #include "llvm/IR/DerivedTypes.h"
135c96de3aSDylan McKay #include "llvm/IR/GlobalValue.h"
145c96de3aSDylan McKay #include "llvm/IR/Mangler.h"
155c96de3aSDylan McKay #include "llvm/MC/MCContext.h"
165c96de3aSDylan McKay #include "llvm/MC/MCSectionELF.h"
175c96de3aSDylan McKay 
185c96de3aSDylan McKay #include "AVR.h"
195c96de3aSDylan McKay 
205c96de3aSDylan McKay namespace llvm {
215c96de3aSDylan McKay void AVRTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) {
225c96de3aSDylan McKay   Base::Initialize(Ctx, TM);
235c96de3aSDylan McKay   ProgmemDataSection =
245c96de3aSDylan McKay       Ctx.getELFSection(".progmem.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
255c96de3aSDylan McKay }
265c96de3aSDylan McKay 
275c96de3aSDylan McKay MCSection *
286733564eSPeter Collingbourne AVRTargetObjectFile::SelectSectionForGlobal(const GlobalObject *GO,
29907cde3cSDylan McKay                                             SectionKind Kind,
305c96de3aSDylan McKay                                             const TargetMachine &TM) const {
315c96de3aSDylan McKay   // Global values in flash memory are placed in the progmem.data section
325c96de3aSDylan McKay   // unless they already have a user assigned section.
33*8aad119dSAyke van Laethem   if (AVR::isProgramMemoryAddress(GO) && !GO->hasSection() && Kind.isReadOnly())
345c96de3aSDylan McKay     return ProgmemDataSection;
355c96de3aSDylan McKay 
365c96de3aSDylan McKay   // Otherwise, we work the same way as ELF.
376733564eSPeter Collingbourne   return Base::SelectSectionForGlobal(GO, Kind, TM);
385c96de3aSDylan McKay }
395c96de3aSDylan McKay } // end of namespace llvm
40907cde3cSDylan McKay 
41