1 //===-- MSP430ELFStreamer.cpp - MSP430 ELF Target Streamer Methods --------===// 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 // This file provides MSP430 specific target streamer methods. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "MSP430MCTargetDesc.h" 14 #include "llvm/BinaryFormat/ELF.h" 15 #include "llvm/MC/MCContext.h" 16 #include "llvm/MC/MCELFStreamer.h" 17 #include "llvm/MC/MCSectionELF.h" 18 #include "llvm/MC/MCStreamer.h" 19 #include "llvm/MC/MCSubtargetInfo.h" 20 #include "llvm/Support/MSP430Attributes.h" 21 22 using namespace llvm; 23 using namespace llvm::MSP430Attrs; 24 25 namespace llvm { 26 27 class MSP430TargetELFStreamer : public MCTargetStreamer { 28 public: 29 MCELFStreamer &getStreamer(); 30 MSP430TargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI); 31 }; 32 33 // This part is for ELF object output. 34 MSP430TargetELFStreamer::MSP430TargetELFStreamer(MCStreamer &S, 35 const MCSubtargetInfo &STI) 36 : MCTargetStreamer(S) { 37 MCAssembler &MCA = getStreamer().getAssembler(); 38 unsigned EFlags = MCA.getELFHeaderEFlags(); 39 MCA.setELFHeaderEFlags(EFlags); 40 41 // Emit build attributes section according to 42 // MSP430 EABI (slaa534.pdf, part 13). 43 MCSection *AttributeSection = getStreamer().getContext().getELFSection( 44 ".MSP430.attributes", ELF::SHT_MSP430_ATTRIBUTES, 0); 45 Streamer.SwitchSection(AttributeSection); 46 47 // Format version. 48 Streamer.emitInt8(0x41); 49 // Subsection length. 50 Streamer.emitInt32(22); 51 // Vendor name string, zero-terminated. 52 Streamer.emitBytes("mspabi"); 53 Streamer.emitInt8(0); 54 55 // Attribute vector scope tag. 1 stands for the entire file. 56 Streamer.emitInt8(1); 57 // Attribute vector length. 58 Streamer.emitInt32(11); 59 60 Streamer.emitInt8(TagISA); 61 Streamer.emitInt8(STI.hasFeature(MSP430::FeatureX) ? ISAMSP430X : ISAMSP430); 62 Streamer.emitInt8(TagCodeModel); 63 Streamer.emitInt8(CMSmall); 64 Streamer.emitInt8(TagDataModel); 65 Streamer.emitInt8(DMSmall); 66 // Don't emit TagEnumSize, for full GCC compatibility. 67 } 68 69 MCELFStreamer &MSP430TargetELFStreamer::getStreamer() { 70 return static_cast<MCELFStreamer &>(Streamer); 71 } 72 73 MCTargetStreamer * 74 createMSP430ObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) { 75 const Triple &TT = STI.getTargetTriple(); 76 if (TT.isOSBinFormatELF()) 77 return new MSP430TargetELFStreamer(S, STI); 78 return nullptr; 79 } 80 81 } // namespace llvm 82