15460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===- ARMLDBackend.h -----------------------------------------------------===//
25460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
35460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//                     The MCLinker Project
45460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
55460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// This file is distributed under the University of Illinois Open Source
65460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// License. See LICENSE.TXT for details.
75460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
85460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===----------------------------------------------------------------------===//
95460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#ifndef MCLD_ARM_LDBACKEND_H
105460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#define MCLD_ARM_LDBACKEND_H
115460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
125460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include "ARMELFDynamic.h"
135460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include "ARMGOT.h"
145460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include "ARMPLT.h"
155460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <mcld/LD/LDSection.h>
165460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <mcld/Target/GNULDBackend.h>
175460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <mcld/Target/OutputRelocSection.h>
185460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
195460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaonamespace mcld {
205460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
215460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass MCLDInfo;
225460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass MCLinker;
235460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass Output;
245460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass SectionMap;
255460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
265460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
275460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===----------------------------------------------------------------------===//
285460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao/// ARMGNULDBackend - linker backend of ARM target of GNU ELF format
295460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao///
305460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass ARMGNULDBackend : public GNULDBackend
315460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao{
325460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaopublic:
335460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ARMGNULDBackend();
345460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ~ARMGNULDBackend();
355460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaopublic:
365460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  typedef std::vector<llvm::ELF::Elf32_Dyn*> ELF32DynList;
375460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
385460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /** \enum ReservedEntryType
395460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  \brief The reserved entry type of reserved space in ResolveInfo.
405460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *
415460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  This is used for sacnRelocation to record what kinds of entries are
425460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  reserved for this resolved symbol
435460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *
445460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  In ARM, there are three kinds of entries, GOT, PLT, and dynamic reloction.
455460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  GOT may needs a corresponding relocation to relocate itself, so we
465460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  separate GOT to two situations: GOT and GOTRel. Besides, for the same
475460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  symbol, there might be two kinds of entries reserved for different location.
485460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  For example, reference to the same symbol, one may use GOT and the other may
495460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  use dynamic relocation.
505460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *
515460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  bit:  3       2      1     0
525460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *   | PLT | GOTRel | GOT | Rel |
535460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *
545460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  value    Name         - Description
555460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *
565460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  0000     None         - no reserved entry
575460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  0001     ReserveRel   - reserve an dynamic relocation entry
585460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  0010     ReserveGOT   - reserve an GOT entry
595460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  0011     GOTandRel    - For different relocation, we've reserved GOT and
605460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *                          Rel for different location.
615460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  0100     GOTRel       - reserve an GOT entry and the corresponding Dyncamic
625460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *                          relocation entry which relocate this GOT entry
635460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  0101     GOTRelandRel - For different relocation, we've reserved GOTRel
645460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *                          and relocation entry for different location.
655460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  1000     ReservePLT   - reserve an PLT entry and the corresponding GOT,
665460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *                          Dynamic relocation entries
675460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *  1001     PLTandRel    - For different relocation, we've reserved PLT and
685460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   *                          Rel for different location.
695460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao   */
705460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  enum ReservedEntryType {
715460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao    None         = 0,
725460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao    ReserveRel   = 1,
735460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao    ReserveGOT   = 2,
745460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao    GOTandRel    = 3,
755460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao    GOTRel       = 4,
765460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao    GOTRelandRel = 5,
775460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao    ReservePLT   = 8,
785460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao    PLTandRel    = 9
795460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  };
805460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
815460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaopublic:
825460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// initTargetSectionMap - initialize target dependent section mapping
835460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  bool initTargetSectionMap(SectionMap& pSectionMap);
845460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
855460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// initTargetSections - initialize target dependent sections in output.
865460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  void initTargetSections(MCLinker& pLinker);
875460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
885460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// initTargetSymbols - initialize target dependent symbols in output.
89affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  void initTargetSymbols(MCLinker& pLinker, const Output& pOutput);
905460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
915460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// initRelocFactory - create and initialize RelocationFactory
925460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  bool initRelocFactory(const MCLinker& pLinker);
935460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
945460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// getRelocFactory
955460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  RelocationFactory* getRelocFactory();
965460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
975460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// scanRelocation - determine the empty entries are needed or not and create
985460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// the empty entries if needed.
995460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// For ARM, following entries are check to create:
1005460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// - GOT entry (for .got section)
1015460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// - PLT entry (for .plt section)
1025460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// - dynamin relocation entries (for .rel.plt and .rel.dyn sections)
1035460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  void scanRelocation(Relocation& pReloc,
1045460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                      const LDSymbol& pInputSym,
1055460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                      MCLinker& pLinker,
1065460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                      const MCLDInfo& pLDInfo,
107affc150dc44fab1911775a49636d0ce85333b634Zonr Chang                      const Output& pOutput,
108affc150dc44fab1911775a49636d0ce85333b634Zonr Chang                      const LDSection& pSection);
1095460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1105460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  uint32_t machine() const
1115460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  { return llvm::ELF::EM_ARM; }
1125460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1135460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// OSABI - the value of e_ident[EI_OSABI]
1145460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  virtual uint8_t OSABI() const
1155460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  { return llvm::ELF::ELFOSABI_NONE; }
1165460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1175460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// ABIVersion - the value of e_ident[EI_ABIVRESION]
1185460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  virtual uint8_t ABIVersion() const
1195460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  { return 0x0; }
1205460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1215460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// flags - the value of ElfXX_Ehdr::e_flags
1225460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  virtual uint64_t flags() const
1235460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  { return (llvm::ELF::EF_ARM_EABIMASK & 0x05000000); }
1245460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1255460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  bool isLittleEndian() const
1265460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  { return true; }
1275460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1285460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  unsigned int bitclass() const
1295460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  { return 32; }
1305460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
131affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  uint64_t defaultTextSegmentAddr() const
132affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  { return 0x8000; }
133affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
1345460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// doPreLayout - Backend can do any needed modification before layout
1355460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  void doPreLayout(const Output& pOutput,
1365460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                   const MCLDInfo& pInfo,
1375460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                   MCLinker& pLinker);
1385460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1395460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// doPostLayout -Backend can do any needed modification after layout
1405460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  void doPostLayout(const Output& pOutput,
1415460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                    const MCLDInfo& pInfo,
1425460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                    MCLinker& pLinker);
1435460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1445460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// dynamic - the dynamic section of the target machine.
1455460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// Use co-variant return type to return its own dynamic section.
1465460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ARMELFDynamic& dynamic();
1475460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1485460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// dynamic - the dynamic section of the target machine.
1495460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// Use co-variant return type to return its own dynamic section.
1505460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  const ARMELFDynamic& dynamic() const;
1515460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1525460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1535460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// emitSectionData - write out the section data into the memory region.
1545460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// When writers get a LDSection whose kind is LDFileFormat::Target, writers
1555460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// call back target backend to emit the data.
1565460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ///
1575460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// Backends handle the target-special tables (plt, gp,...) by themselves.
158cedee4b38f4786845183be7f5916dd520a170ae0Shih-wei Liao  /// Backend can put the data of the tables in SectionData directly
1595460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ///  - LDSection.getSectionData can get the section data.
1605460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// Or, backend can put the data into special data structure
1615460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ///  - backend can maintain its own map<LDSection, table> to get the table
1625460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// from given LDSection.
1635460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ///
1645460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// @param pOutput - the output file
1655460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// @param pSection - the given LDSection
1665460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// @param pInfo - all options in the command line.
167affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// @param pLayout - for comouting the size of fragment
1685460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// @param pRegion - the region to write out data
1695460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// @return the size of the table in the file.
1705460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  uint64_t emitSectionData(const Output& pOutput,
1715460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                           const LDSection& pSection,
1725460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                           const MCLDInfo& pInfo,
173affc150dc44fab1911775a49636d0ce85333b634Zonr Chang                           const Layout& pLayout,
1745460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                           MemoryRegion& pRegion) const;
1755460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1765460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ARMGOT& getGOT();
1775460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1785460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  const ARMGOT& getGOT() const;
1795460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1805460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ARMPLT& getPLT();
1815460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1825460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  const ARMPLT& getPLT() const;
1835460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1845460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  OutputRelocSection& getRelDyn();
1855460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1865460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  const OutputRelocSection& getRelDyn() const;
1875460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1885460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  OutputRelocSection& getRelPLT();
1895460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1905460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  const OutputRelocSection& getRelPLT() const;
1915460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
1925460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// getTargetSectionOrder - compute the layout order of ARM target sections
1935460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  unsigned int getTargetSectionOrder(const Output& pOutput,
194affc150dc44fab1911775a49636d0ce85333b634Zonr Chang                                     const LDSection& pSectHdr,
195affc150dc44fab1911775a49636d0ce85333b634Zonr Chang                                     const MCLDInfo& pInfo) const;
1965460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
197affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// finalizeTargetSymbols - finalize the symbol value
198affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  bool finalizeTargetSymbols(MCLinker& pLinker, const Output& pOutput);
1995460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
2005460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// readSection - read target dependent sections
2015460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  bool readSection(Input& pInput,
2025460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                   MCLinker& pLinker,
2035460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                   LDSection& pInputSectHdr);
2045460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
2055460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoprivate:
2065460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  void scanLocalReloc(Relocation& pReloc,
2075460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                      const LDSymbol& pInputSym,
2085460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                      MCLinker& pLinker,
2095460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                      const MCLDInfo& pLDInfo,
2105460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                      const Output& pOutput);
2115460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
2125460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  void scanGlobalReloc(Relocation& pReloc,
2135460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                       const LDSymbol& pInputSym,
2145460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                       MCLinker& pLinker,
2155460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                       const MCLDInfo& pLDInfo,
2165460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                       const Output& pOutput);
2175460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
2185460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  void checkValidReloc(Relocation& pReloc,
2195460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                       const MCLDInfo& pLDInfo,
2205460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                       const Output& pOutput) const;
2215460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
222affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// addCopyReloc - add a copy relocation into .rel.dyn for pSym
223affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// @param pSym - A resolved copy symbol that defined in BSS section
224affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  void addCopyReloc(ResolveInfo& pSym);
225affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
226affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// defineSymbolforCopyReloc - allocate a space in BSS section and
227affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// and force define the copy of pSym to BSS section
228affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  /// @return the output LDSymbol of the copy symbol
229affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  LDSymbol& defineSymbolforCopyReloc(MCLinker& pLinker,
230affc150dc44fab1911775a49636d0ce85333b634Zonr Chang                                     const ResolveInfo& pSym);
231affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
2325460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// updateAddend - update addend value of the relocation if the
2335460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// the target symbol is a section symbol. Addend is the offset
2345460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// in the section. This value should be updated after section
2355460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// merged.
2365460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  void updateAddend(Relocation& pReloc,
2375460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                    const LDSymbol& pInputSym,
2385460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao                    const Layout& pLayout) const;
2395460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
2405460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  void createARMGOT(MCLinker& pLinker, const Output& pOutput);
2415460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
2425460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// createARMPLTandRelPLT - create PLT and RELPLT sections.
2435460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// Because in ELF sh_info in .rel.plt is the shndx of .plt, these two
2445460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// sections should be create together.
2455460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  void createARMPLTandRelPLT(MCLinker& pLinker, const Output& pOutput);
2465460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
2475460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  void createARMRelDyn(MCLinker& pLinker, const Output& pOutput);
2485460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
2495460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoprivate:
2505460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  RelocationFactory* m_pRelocFactory;
2515460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ARMGOT* m_pGOT;
2525460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ARMPLT* m_pPLT;
2535460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// m_RelDyn - dynamic relocation table of .rel.dyn
2545460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  OutputRelocSection* m_pRelDyn;
2555460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  /// m_RelPLT - dynamic relocation table of .rel.plt
2565460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  OutputRelocSection* m_pRelPLT;
2575460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
2585460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ARMELFDynamic* m_pDynamic;
2595460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  LDSymbol* m_pGOTSymbol;
2605460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
2615460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  //     variable name           :  ELF
2625460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  LDSection* m_pEXIDX;           // .ARM.exidx
2635460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  LDSection* m_pEXTAB;           // .ARM.extab
2645460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  LDSection* m_pAttributes;      // .ARM.attributes
2655460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//  LDSection* m_pPreemptMap;      // .ARM.preemptmap
2665460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//  LDSection* m_pDebugOverlay;    // .ARM.debug_overlay
2675460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//  LDSection* m_pOverlayTable;    // .ARM.overlay_table
2685460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao};
2695460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
2705460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===----------------------------------------------------------------------===//
2715460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao/// ARMMachOLDBackend - linker backend of ARM target of MachO format
2725460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao///
2735460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao/**
2745460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass ARMMachOLDBackend : public DarwinARMLDBackend
2755460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao{
2765460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaopublic:
2775460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ARMMachOLDBackend();
2785460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ~ARMMachOLDBackend();
2795460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
2805460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoprivate:
2815460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  MCMachOTargetArchiveReader *createTargetArchiveReader() const;
2825460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  MCMachOTargetObjectReader *createTargetObjectReader() const;
2835460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  MCMachOTargetObjectWriter *createTargetObjectWriter() const;
2845460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
2855460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao};
2865460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao**/
2875460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} // namespace of mcld
2885460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
2895460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#endif
290affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
291