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 
27*5449d2daSShivam Gupta MCSection *AVRTargetObjectFile::SelectSectionForGlobal(
28*5449d2daSShivam Gupta     const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
295c96de3aSDylan McKay   // Global values in flash memory are placed in the progmem.data section
305c96de3aSDylan McKay   // unless they already have a user assigned section.
318aad119dSAyke van Laethem   if (AVR::isProgramMemoryAddress(GO) && !GO->hasSection() && Kind.isReadOnly())
325c96de3aSDylan McKay     return ProgmemDataSection;
335c96de3aSDylan McKay 
345c96de3aSDylan McKay   // Otherwise, we work the same way as ELF.
356733564eSPeter Collingbourne   return Base::SelectSectionForGlobal(GO, Kind, TM);
365c96de3aSDylan McKay }
375c96de3aSDylan McKay } // end of namespace llvm
38