ObjectBuilder.h revision 533eae20118036f425f27bf0536ef0ccbb090b65
1//===- ObjectBuilder.h ----------------------------------------------------===// 2// 3// The MCLinker Project 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9#ifndef MCLD_OBJECT_OBJECTBUILDER_H 10#define MCLD_OBJECT_OBJECTBUILDER_H 11#include <mcld/LD/LDFileFormat.h> 12#include <mcld/LD/EhFrame.h> 13 14#include <llvm/Support/DataTypes.h> 15 16#include <string> 17 18namespace mcld { 19 20class Module; 21class LDSection; 22class SectionData; 23class Fragment; 24class Input; 25 26/** \class ObjectBuilder 27 * \brief ObjectBuilder recieve ObjectAction and build the mcld::Module. 28 */ 29class ObjectBuilder 30{ 31public: 32 ObjectBuilder(Module& pTheModule); 33 34/// @} 35/// @name Section Methods 36/// @{ 37 /// CreateSection - To create an output LDSection in mcld::Module. 38 /// Link scripts and command line options define some SECTIONS commands that 39 /// specify where input sections are placed into output sections. This function 40 /// checks SECTIONS commands to change given name to the output section name. 41 /// This function creates a new LDSection and push the created LDSection into 42 /// @ref mcld::Module. 43 /// 44 /// To create an input LDSection in mcld::LDContext, use @ref LDSection::Create(). 45 /// 46 /// @see SectionMap 47 /// 48 /// @param [in] pName The given name. Returned LDSection used the changed name 49 /// by SectionMap. 50 LDSection* CreateSection(const std::string& pInputName, 51 LDFileFormat::Kind pKind, 52 uint32_t pType, 53 uint32_t pFlag, 54 uint32_t pAlign = 0x0); 55 56 /// MergeSection - merge the pInput section to mcld::Module. 57 /// This function moves all fragments in pInputSection to the corresponding 58 /// output section of mcld::Module. 59 /// 60 /// @see SectionMap 61 /// @param [in] pInputSection The merged input section. 62 /// @return The merged output section. If the corresponding output sections 63 /// is not defined, return NULL. 64 LDSection* MergeSection(const Input& pInputFile, LDSection& pInputSection); 65 66 /// MoveSectionData - move the fragment of pFrom to pTo section data. 67 static bool MoveSectionData(SectionData& pFrom, SectionData& pTo); 68 69 /// UpdateSectionAlign - update alignment for input section 70 static void UpdateSectionAlign(LDSection& pTo, const LDSection& pFrom); 71 72 /// UpdateSectionAlign - update alignment for the section 73 static void UpdateSectionAlign(LDSection& pSection, 74 uint32_t pAlignConstraint); 75 76/// @} 77/// @name Fragment Methods 78/// @{ 79 /// AppendFragment - To append pFrag to the given SectionData pSD. 80 /// In order to keep the alignment of pFrag, This function inserts an 81 /// AlignFragment before pFrag if pAlignConstraint is larger than 1. 82 /// 83 /// @note This function does not update the alignment constraint of LDSection. 84 /// 85 /// @param [in, out] pFrag The appended fragment. The offset of the appended 86 /// pFrag is set to the offset in pSD. 87 /// @param [in, out] pSD The section data being appended. 88 /// @param [in] pAlignConstraint The alignment constraint. 89 /// @return Total size of the inserted fragments. 90 static uint64_t AppendFragment(Fragment& pFrag, SectionData& pSD, 91 uint32_t pAlignConstraint = 1); 92 93private: 94 Module& m_Module; 95}; 96 97} // namespace of mcld 98 99#endif 100 101