1 //===- ELFDynObjFileFormat.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/ELFDynObjFileFormat.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 ELFDynObjFileFormat::initObjectFormat(ObjectBuilder& pBuilder,
18 unsigned int pBitClass) {
19 f_pDynSymTab = pBuilder.CreateSection(".dynsym",
20 LDFileFormat::NamePool,
21 llvm::ELF::SHT_DYNSYM,
22 llvm::ELF::SHF_ALLOC,
23 pBitClass / 8);
24 f_pDynStrTab = pBuilder.CreateSection(".dynstr",
25 LDFileFormat::NamePool,
26 llvm::ELF::SHT_STRTAB,
27 llvm::ELF::SHF_ALLOC,
28 0x1);
29 f_pInterp = pBuilder.CreateSection(".interp",
30 LDFileFormat::Note,
31 llvm::ELF::SHT_PROGBITS,
32 llvm::ELF::SHF_ALLOC,
33 0x1);
34 f_pHashTab = pBuilder.CreateSection(".hash",
35 LDFileFormat::NamePool,
36 llvm::ELF::SHT_HASH,
37 llvm::ELF::SHF_ALLOC,
38 pBitClass / 8);
39 f_pDynamic =
40 pBuilder.CreateSection(".dynamic",
41 LDFileFormat::NamePool,
42 llvm::ELF::SHT_DYNAMIC,
43 llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
44 pBitClass / 8);
45 f_pRelaDyn = pBuilder.CreateSection(".rela.dyn",
46 LDFileFormat::Relocation,
47 llvm::ELF::SHT_RELA,
48 llvm::ELF::SHF_ALLOC,
49 pBitClass / 8);
50 f_pRelaPlt = pBuilder.CreateSection(".rela.plt",
51 LDFileFormat::Relocation,
52 llvm::ELF::SHT_RELA,
53 llvm::ELF::SHF_ALLOC,
54 pBitClass / 8);
55 f_pRelDyn = pBuilder.CreateSection(".rel.dyn",
56 LDFileFormat::Relocation,
57 llvm::ELF::SHT_REL,
58 llvm::ELF::SHF_ALLOC,
59 pBitClass / 8);
60 f_pRelPlt = pBuilder.CreateSection(".rel.plt",
61 LDFileFormat::Relocation,
62 llvm::ELF::SHT_REL,
63 llvm::ELF::SHF_ALLOC,
64 pBitClass / 8);
65 f_pGOT = pBuilder.CreateSection(".got",
66 LDFileFormat::Target,
67 llvm::ELF::SHT_PROGBITS,
68 llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
69 pBitClass / 8);
70 f_pPLT =
71 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 =
77 pBuilder.CreateSection(".got.plt",
78 LDFileFormat::Target,
79 llvm::ELF::SHT_PROGBITS,
80 llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE,
81 pBitClass / 8);
82 f_pEhFrameHdr = pBuilder.CreateSection(".eh_frame_hdr",
83 LDFileFormat::EhFrameHdr,
84 llvm::ELF::SHT_PROGBITS,
85 llvm::ELF::SHF_ALLOC,
86 0x4);
87 f_pGNUHashTab = pBuilder.CreateSection(".gnu.hash",
88 LDFileFormat::NamePool,
89 llvm::ELF::SHT_GNU_HASH,
90 llvm::ELF::SHF_ALLOC,
91 pBitClass / 8);
92 }
93
94 } // namespace mcld
95