blob: 980096a098351fd0a91f5b236b0a84d0e77ef79f [file] [log] [blame]
Dylan McKay5c96de32016-01-07 10:53:15 +00001//===-- AVRTargetObjectFile.cpp - AVR Object Files ------------------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Dylan McKay5c96de32016-01-07 10:53:15 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "AVRTargetObjectFile.h"
10
Zachary Turner264b5d92017-06-07 03:48:56 +000011#include "llvm/BinaryFormat/ELF.h"
Dylan McKay5c96de32016-01-07 10:53:15 +000012#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"
Dylan McKay5c96de32016-01-07 10:53:15 +000017
18#include "AVR.h"
19
20namespace llvm {
21void 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
27MCSection *
Peter Collingbourne67335642016-10-24 19:23:39 +000028AVRTargetObjectFile::SelectSectionForGlobal(const GlobalObject *GO,
Dylan McKay907cde32016-09-24 11:38:08 +000029 SectionKind Kind,
Dylan McKay5c96de32016-01-07 10:53:15 +000030 const TargetMachine &TM) const {
31 // Global values in flash memory are placed in the progmem.data section
32 // unless they already have a user assigned section.
Peter Collingbourne67335642016-10-24 19:23:39 +000033 if (AVR::isProgramMemoryAddress(GO) && !GO->hasSection())
Dylan McKay5c96de32016-01-07 10:53:15 +000034 return ProgmemDataSection;
35
36 // Otherwise, we work the same way as ELF.
Peter Collingbourne67335642016-10-24 19:23:39 +000037 return Base::SelectSectionForGlobal(GO, Kind, TM);
Dylan McKay5c96de32016-01-07 10:53:15 +000038}
39} // end of namespace llvm
Dylan McKay907cde32016-09-24 11:38:08 +000040