Path: blob/main/contrib/llvm-project/llvm/lib/Target/AVR/AVRTargetObjectFile.cpp
35266 views
//===-- AVRTargetObjectFile.cpp - AVR Object Files ------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "AVRTargetObjectFile.h"9#include "AVRTargetMachine.h"1011#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"1718#include "AVR.h"1920namespace llvm {21void AVRTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) {22Base::Initialize(Ctx, TM);23ProgmemDataSection =24Ctx.getELFSection(".progmem.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);25Progmem1DataSection =26Ctx.getELFSection(".progmem1.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);27Progmem2DataSection =28Ctx.getELFSection(".progmem2.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);29Progmem3DataSection =30Ctx.getELFSection(".progmem3.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);31Progmem4DataSection =32Ctx.getELFSection(".progmem4.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);33Progmem5DataSection =34Ctx.getELFSection(".progmem5.data", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);35}3637MCSection *AVRTargetObjectFile::SelectSectionForGlobal(38const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {39// Global values in flash memory are placed in the progmem*.data section40// unless they already have a user assigned section.41const auto &AVRTM = static_cast<const AVRTargetMachine &>(TM);42if (AVR::isProgramMemoryAddress(GO) && !GO->hasSection() &&43Kind.isReadOnly()) {44// The AVR subtarget should support LPM to access section '.progmem*.data'.45if (!AVRTM.getSubtargetImpl()->hasLPM()) {46// TODO: Get the global object's location in source file.47getContext().reportError(48SMLoc(),49"Current AVR subtarget does not support accessing program memory");50return Base::SelectSectionForGlobal(GO, Kind, TM);51}52// The AVR subtarget should support ELPM to access section53// '.progmem[1|2|3|4|5].data'.54if (!AVRTM.getSubtargetImpl()->hasELPM() &&55AVR::getAddressSpace(GO) != AVR::ProgramMemory) {56// TODO: Get the global object's location in source file.57getContext().reportError(SMLoc(),58"Current AVR subtarget does not support "59"accessing extended program memory");60return ProgmemDataSection;61}62switch (AVR::getAddressSpace(GO)) {63case AVR::ProgramMemory: // address space 164return ProgmemDataSection;65case AVR::ProgramMemory1: // address space 266return Progmem1DataSection;67case AVR::ProgramMemory2: // address space 368return Progmem2DataSection;69case AVR::ProgramMemory3: // address space 470return Progmem3DataSection;71case AVR::ProgramMemory4: // address space 572return Progmem4DataSection;73case AVR::ProgramMemory5: // address space 674return Progmem5DataSection;75default:76llvm_unreachable("unexpected program memory index");77}78}7980// Otherwise, we work the same way as ELF.81return Base::SelectSectionForGlobal(GO, Kind, TM);82}83} // end of namespace llvm848586