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 namespace mcld {
16
initObjectFormat(ObjectBuilder & pBuilder,unsigned int pBitClass)17 void ELFExecFileFormat::initObjectFormat(ObjectBuilder& pBuilder,
18 unsigned int pBitClass) {
19 // FIXME: make sure ELF executable files has these sections.
20 f_pDynSymTab = pBuilder.CreateSection(".dynsym",
21 LDFileFormat::NamePool,
22 llvm::ELF::SHT_DYNSYM,
23 llvm::ELF::SHF_ALLOC,
24 pBitClass / 8);
25 f_pDynStrTab = pBuilder.CreateSection(".dynstr",
26 LDFileFormat::NamePool,
27 llvm::ELF::SHT_STRTAB,
28 llvm::ELF::SHF_ALLOC,
29 0x1);
30 f_pInterp = pBuilder.CreateSection(".interp",
31 LDFileFormat::Note,
32 llvm::ELF::SHT_PROGBITS,
33 llvm::ELF::SHF_ALLOC,
34 0x1);
35 f_pHashTab = pBuilder.CreateSection(".hash",
36 LDFileFormat::NamePool,
37 llvm::ELF::SHT_HASH,
38 llvm::ELF::SHF_ALLOC,
39 pBitClass / 8);
40 f_pDynamic =
41 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 =
72 pBuilder.CreateSection(".plt",
73 LDFileFormat::Target,
74 llvm::ELF::SHT_PROGBITS,
75 llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
76 pBitClass / 8);
77 f_pGOTPLT =
78 pBuilder.CreateSection(".got.plt",
79 LDFileFormat::Target,
80 llvm::ELF::SHT_PROGBITS,
81 llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
82 pBitClass / 8);
83 f_pEhFrameHdr = pBuilder.CreateSection(".eh_frame_hdr",
84 LDFileFormat::EhFrameHdr,
85 llvm::ELF::SHT_PROGBITS,
86 llvm::ELF::SHF_ALLOC,
87 0x4);
88 f_pGNUHashTab = pBuilder.CreateSection(".gnu.hash",
89 LDFileFormat::NamePool,
90 llvm::ELF::SHT_GNU_HASH,
91 llvm::ELF::SHF_ALLOC,
92 pBitClass / 8);
93 }
94
95 } // namespace mcld
96