//===- lib/ReaderWriter/ELF/Hexagon/HexagonExecutableWriter.h -------------===// // // The LLVM Linker // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #ifndef HEXAGON_EXECUTABLE_WRITER_H #define HEXAGON_EXECUTABLE_WRITER_H #include "ExecutableWriter.h" #include "HexagonELFWriters.h" #include "HexagonExecutableAtoms.h" #include "HexagonLinkingContext.h" namespace lld { namespace elf { template class HexagonTargetLayout; template class HexagonExecutableWriter : public ExecutableWriter, public HexagonELFWriter { public: HexagonExecutableWriter(HexagonLinkingContext &context, HexagonTargetLayout &layout); protected: // Add any runtime files and their atoms to the output virtual bool createImplicitFiles(std::vector> &); virtual void finalizeDefaultAtomValues(); virtual std::error_code setELFHeader() { ExecutableWriter::setELFHeader(); HexagonELFWriter::setELFHeader(*this->_elfHeader); return std::error_code(); } private: void addDefaultAtoms() { _hexagonRuntimeFile->addAbsoluteAtom("_SDA_BASE_"); if (this->_context.isDynamic()) { _hexagonRuntimeFile->addAbsoluteAtom("_GLOBAL_OFFSET_TABLE_"); _hexagonRuntimeFile->addAbsoluteAtom("_DYNAMIC"); } } HexagonLinkingContext &_hexagonLinkingContext; HexagonTargetLayout &_hexagonTargetLayout; std::unique_ptr> _hexagonRuntimeFile; }; template HexagonExecutableWriter::HexagonExecutableWriter( HexagonLinkingContext &context, HexagonTargetLayout &layout) : ExecutableWriter(context, layout), HexagonELFWriter(context, layout), _hexagonLinkingContext(context), _hexagonTargetLayout(layout), _hexagonRuntimeFile(new HexagonRuntimeFile(context)) {} template bool HexagonExecutableWriter::createImplicitFiles( std::vector> &result) { ExecutableWriter::createImplicitFiles(result); // Add the default atoms as defined for hexagon addDefaultAtoms(); result.push_back(std::move(_hexagonRuntimeFile)); return true; } template void HexagonExecutableWriter::finalizeDefaultAtomValues() { // Finalize the atom values that are part of the parent. ExecutableWriter::finalizeDefaultAtomValues(); auto sdabaseAtomIter = _hexagonTargetLayout.findAbsoluteAtom("_SDA_BASE_"); (*sdabaseAtomIter)->_virtualAddr = _hexagonTargetLayout.getSDataSection()->virtualAddr(); HexagonELFWriter::finalizeHexagonRuntimeAtomValues(); } } // namespace elf } // namespace lld #endif // HEXAGON_EXECUTABLE_WRITER_H