Home | History | Annotate | Download | only in Target
      1 //===-- llvm/Target/TargetELFWriterInfo.h - ELF Writer Info -----*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file defines the TargetELFWriterInfo class.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef LLVM_TARGET_TARGETELFWRITERINFO_H
     15 #define LLVM_TARGET_TARGETELFWRITERINFO_H
     16 
     17 namespace llvm {
     18 
     19   //===--------------------------------------------------------------------===//
     20   //                          TargetELFWriterInfo
     21   //===--------------------------------------------------------------------===//
     22 
     23   class TargetELFWriterInfo {
     24   protected:
     25     // EMachine - This field is the target specific value to emit as the
     26     // e_machine member of the ELF header.
     27     unsigned short EMachine;
     28     bool is64Bit, isLittleEndian;
     29   public:
     30 
     31     // Machine architectures
     32     enum MachineType {
     33       EM_NONE = 0,     // No machine
     34       EM_M32 = 1,      // AT&T WE 32100
     35       EM_SPARC = 2,    // SPARC
     36       EM_386 = 3,      // Intel 386
     37       EM_68K = 4,      // Motorola 68000
     38       EM_88K = 5,      // Motorola 88000
     39       EM_486 = 6,      // Intel 486 (deprecated)
     40       EM_860 = 7,      // Intel 80860
     41       EM_MIPS = 8,     // MIPS R3000
     42       EM_PPC = 20,     // PowerPC
     43       EM_ARM = 40,     // ARM
     44       EM_ALPHA = 41,   // DEC Alpha
     45       EM_SPARCV9 = 43, // SPARC V9
     46       EM_X86_64 = 62   // AMD64
     47     };
     48 
     49     // ELF File classes
     50     enum {
     51       ELFCLASS32 = 1, // 32-bit object file
     52       ELFCLASS64 = 2  // 64-bit object file
     53     };
     54 
     55     // ELF Endianess
     56     enum {
     57       ELFDATA2LSB = 1, // Little-endian object file
     58       ELFDATA2MSB = 2  // Big-endian object file
     59     };
     60 
     61     explicit TargetELFWriterInfo(bool is64Bit_, bool isLittleEndian_);
     62     virtual ~TargetELFWriterInfo();
     63 
     64     unsigned short getEMachine() const { return EMachine; }
     65     unsigned getEFlags() const { return 0; }
     66     unsigned getEIClass() const { return is64Bit ? ELFCLASS64 : ELFCLASS32; }
     67     unsigned getEIData() const {
     68       return isLittleEndian ? ELFDATA2LSB : ELFDATA2MSB;
     69     }
     70 
     71     /// ELF Header and ELF Section Header Info
     72     unsigned getHdrSize() const { return is64Bit ? 64 : 52; }
     73     unsigned getSHdrSize() const { return is64Bit ? 64 : 40; }
     74 
     75     /// Symbol Table Info
     76     unsigned getSymTabEntrySize() const { return is64Bit ? 24 : 16; }
     77 
     78     /// getPrefELFAlignment - Returns the preferred alignment for ELF. This
     79     /// is used to align some sections.
     80     unsigned getPrefELFAlignment() const { return is64Bit ? 8 : 4; }
     81 
     82     /// getRelocationEntrySize - Entry size used in the relocation section
     83     unsigned getRelocationEntrySize() const {
     84       return is64Bit ? (hasRelocationAddend() ? 24 : 16)
     85                      : (hasRelocationAddend() ? 12 : 8);
     86     }
     87 
     88     /// getRelocationType - Returns the target specific ELF Relocation type.
     89     /// 'MachineRelTy' contains the object code independent relocation type
     90     virtual unsigned getRelocationType(unsigned MachineRelTy) const = 0;
     91 
     92     /// hasRelocationAddend - True if the target uses an addend in the
     93     /// ELF relocation entry.
     94     virtual bool hasRelocationAddend() const = 0;
     95 
     96     /// getDefaultAddendForRelTy - Gets the default addend value for a
     97     /// relocation entry based on the target ELF relocation type.
     98     virtual long int getDefaultAddendForRelTy(unsigned RelTy,
     99                                               long int Modifier = 0) const = 0;
    100 
    101     /// getRelTySize - Returns the size of relocatable field in bits
    102     virtual unsigned getRelocationTySize(unsigned RelTy) const = 0;
    103 
    104     /// isPCRelativeRel - True if the relocation type is pc relative
    105     virtual bool isPCRelativeRel(unsigned RelTy) const = 0;
    106 
    107     /// getJumpTableRelocationTy - Returns the machine relocation type used
    108     /// to reference a jumptable.
    109     virtual unsigned getAbsoluteLabelMachineRelTy() const = 0;
    110 
    111     /// computeRelocation - Some relocatable fields could be relocated
    112     /// directly, avoiding the relocation symbol emission, compute the
    113     /// final relocation value for this symbol.
    114     virtual long int computeRelocation(unsigned SymOffset, unsigned RelOffset,
    115                                        unsigned RelTy) const = 0;
    116   };
    117 
    118 } // end llvm namespace
    119 
    120 #endif // LLVM_TARGET_TARGETELFWRITERINFO_H
    121