Dylan McKay | 5c96de3 | 2016-01-07 10:53:15 +0000 | [diff] [blame] | 1 | //===-- AVRTargetObjectFile.cpp - AVR Object Files ------------------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame^] | 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 |
Dylan McKay | 5c96de3 | 2016-01-07 10:53:15 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "AVRTargetObjectFile.h" |
| 10 | |
Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 11 | #include "llvm/BinaryFormat/ELF.h" |
Dylan McKay | 5c96de3 | 2016-01-07 10:53:15 +0000 | [diff] [blame] | 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" |
Dylan McKay | 5c96de3 | 2016-01-07 10:53:15 +0000 | [diff] [blame] | 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 * |
Peter Collingbourne | 6733564 | 2016-10-24 19:23:39 +0000 | [diff] [blame] | 28 | AVRTargetObjectFile::SelectSectionForGlobal(const GlobalObject *GO, |
Dylan McKay | 907cde3 | 2016-09-24 11:38:08 +0000 | [diff] [blame] | 29 | SectionKind Kind, |
Dylan McKay | 5c96de3 | 2016-01-07 10:53:15 +0000 | [diff] [blame] | 30 | 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 Collingbourne | 6733564 | 2016-10-24 19:23:39 +0000 | [diff] [blame] | 33 | if (AVR::isProgramMemoryAddress(GO) && !GO->hasSection()) |
Dylan McKay | 5c96de3 | 2016-01-07 10:53:15 +0000 | [diff] [blame] | 34 | return ProgmemDataSection; |
| 35 | |
| 36 | // Otherwise, we work the same way as ELF. |
Peter Collingbourne | 6733564 | 2016-10-24 19:23:39 +0000 | [diff] [blame] | 37 | return Base::SelectSectionForGlobal(GO, Kind, TM); |
Dylan McKay | 5c96de3 | 2016-01-07 10:53:15 +0000 | [diff] [blame] | 38 | } |
| 39 | } // end of namespace llvm |
Dylan McKay | 907cde3 | 2016-09-24 11:38:08 +0000 | [diff] [blame] | 40 | |