xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AVR/AVRTargetObjectFile.cpp (revision 5e801ac66d24704442eba426ed13c3effb8a34e7)
1 //===-- AVRTargetObjectFile.cpp - AVR Object Files ------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "AVRTargetObjectFile.h"
10 
11 #include "llvm/BinaryFormat/ELF.h"
12 #include "llvm/IR/DerivedTypes.h"
13 #include "llvm/IR/GlobalValue.h"
14 #include "llvm/IR/Mangler.h"
15 #include "llvm/MC/MCContext.h"
16 #include "llvm/MC/MCSectionELF.h"
17 
18 #include "AVR.h"
19 
20 namespace llvm {
21 void AVRTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) {
22   Base::Initialize(Ctx, TM);
23   ProgmemDataSection =
24       Ctx.getELFSection(".progmem.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
25 }
26 
27 MCSection *AVRTargetObjectFile::SelectSectionForGlobal(
28     const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
29   // Global values in flash memory are placed in the progmem.data section
30   // unless they already have a user assigned section.
31   if (AVR::isProgramMemoryAddress(GO) && !GO->hasSection() && Kind.isReadOnly())
32     return ProgmemDataSection;
33 
34   // Otherwise, we work the same way as ELF.
35   return Base::SelectSectionForGlobal(GO, Kind, TM);
36 }
37 } // end of namespace llvm
38