Home | History | Annotate | Download | only in LD
      1 //===- ELFExecFileFormat.cpp ----------------------------------------------===//
      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 #include <mcld/LD/ELFExecFileFormat.h>
     10 #include <mcld/LD/LDSection.h>
     11 #include <mcld/Object/ObjectBuilder.h>
     12 
     13 #include <llvm/Support/ELF.h>
     14 
     15 using namespace mcld;
     16 
     17 void ELFExecFileFormat::initObjectFormat(ObjectBuilder& pBuilder,
     18                                          unsigned int pBitClass)
     19 {
     20   // FIXME: make sure ELF executable files has these sections.
     21   f_pDynSymTab    = pBuilder.CreateSection(".dynsym",
     22                                            LDFileFormat::NamePool,
     23                                            llvm::ELF::SHT_DYNSYM,
     24                                            llvm::ELF::SHF_ALLOC,
     25                                            pBitClass / 8);
     26   f_pDynStrTab    = pBuilder.CreateSection(".dynstr",
     27                                            LDFileFormat::NamePool,
     28                                            llvm::ELF::SHT_STRTAB,
     29                                            llvm::ELF::SHF_ALLOC,
     30                                            0x1);
     31   f_pInterp       = pBuilder.CreateSection(".interp",
     32                                            LDFileFormat::Note,
     33                                            llvm::ELF::SHT_PROGBITS,
     34                                            llvm::ELF::SHF_ALLOC,
     35                                            0x1);
     36   f_pHashTab      = pBuilder.CreateSection(".hash",
     37                                            LDFileFormat::NamePool,
     38                                            llvm::ELF::SHT_HASH,
     39                                            llvm::ELF::SHF_ALLOC,
     40                                            pBitClass / 8);
     41   f_pDynamic      = pBuilder.CreateSection(".dynamic",
     42                                            LDFileFormat::NamePool,
     43                                            llvm::ELF::SHT_DYNAMIC,
     44                                            llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
     45                                            pBitClass / 8);
     46   f_pRelaDyn      = pBuilder.CreateSection(".rela.dyn",
     47                                            LDFileFormat::Relocation,
     48                                            llvm::ELF::SHT_RELA,
     49                                            llvm::ELF::SHF_ALLOC,
     50                                            pBitClass / 8);
     51   f_pRelaPlt      = pBuilder.CreateSection(".rela.plt",
     52                                            LDFileFormat::Relocation,
     53                                            llvm::ELF::SHT_RELA,
     54                                            llvm::ELF::SHF_ALLOC,
     55                                            pBitClass / 8);
     56   f_pRelDyn       = pBuilder.CreateSection(".rel.dyn",
     57                                            LDFileFormat::Relocation,
     58                                            llvm::ELF::SHT_REL,
     59                                            llvm::ELF::SHF_ALLOC,
     60                                            pBitClass / 8);
     61   f_pRelPlt       = pBuilder.CreateSection(".rel.plt",
     62                                            LDFileFormat::Relocation,
     63                                            llvm::ELF::SHT_REL,
     64                                            llvm::ELF::SHF_ALLOC,
     65                                            pBitClass / 8);
     66   f_pGOT          = pBuilder.CreateSection(".got",
     67                                            LDFileFormat::Target,
     68                                            llvm::ELF::SHT_PROGBITS,
     69                                            llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
     70                                            pBitClass / 8);
     71   f_pPLT          = pBuilder.CreateSection(".plt",
     72                                            LDFileFormat::Target,
     73                                            llvm::ELF::SHT_PROGBITS,
     74                                            llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
     75                                            pBitClass / 8);
     76   f_pGOTPLT       = pBuilder.CreateSection(".got.plt",
     77                                            LDFileFormat::Target,
     78                                            llvm::ELF::SHT_PROGBITS,
     79                                            llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
     80                                            pBitClass / 8);
     81   f_pEhFrameHdr   = pBuilder.CreateSection(".eh_frame_hdr",
     82                                            LDFileFormat::EhFrameHdr,
     83                                            llvm::ELF::SHT_PROGBITS,
     84                                            llvm::ELF::SHF_ALLOC,
     85                                            0x4);
     86   f_pGNUHashTab   = pBuilder.CreateSection(".gnu.hash",
     87                                            LDFileFormat::NamePool,
     88                                            llvm::ELF::SHT_GNU_HASH,
     89                                            llvm::ELF::SHF_ALLOC,
     90                                            pBitClass / 8);
     91 }
     92