blob: a642b16c36b3c3a44c39dbc8eea0e3288fa8c190 [file] [log] [blame]
Stephen Hinesb53c8a52013-04-05 22:17:36 -07001/*
2 * Copyright 2011, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ELF_SECTION_PROGBITS_H
18#define ELF_SECTION_PROGBITS_H
19
20#include "ELFTypes.h"
21#include "ELFSectionBits.h"
22#include "ELFSectionHeader.h"
23#include "MemChunk.h"
24#include "StubLayout.h"
25
26template <unsigned Bitwidth>
27class ELFSectionProgBits : public ELFSectionBits<Bitwidth> {
28public:
29 ELF_TYPE_INTRO_TO_TEMPLATE_SCOPE(Bitwidth);
30
31private:
32 StubLayout *stubs;
33
34public:
35 template <typename Archiver>
36 static ELFSectionProgBits *read(Archiver &AR,
37 ELFObjectTy *owner,
38 ELFSectionHeaderTy const *sh);
39
40 StubLayout *getStubLayout() {
41 return stubs;
42 }
43
44 ELFSectionProgBits(int machine) {
45 switch(machine) {
46 case EM_ARM:
Xiaofei Wan72151aa2014-06-12 21:44:09 +080047 stubs = new StubLayoutARM();
Stephen Hinesb53c8a52013-04-05 22:17:36 -070048 break;
49
Dave Allison30e2a4c2014-03-28 14:23:09 -070050 case EM_AARCH64:
Xiaofei Wan72151aa2014-06-12 21:44:09 +080051 stubs = new StubLayoutAARCH64();
Dave Allison30e2a4c2014-03-28 14:23:09 -070052 break;
53
Stephen Hinesb53c8a52013-04-05 22:17:36 -070054 case EM_MIPS:
Xiaofei Wan72151aa2014-06-12 21:44:09 +080055 stubs = new StubLayoutMIPS();
56 break;
57
58 case EM_386:
59 stubs = new StubLayoutX86();
60 break;
61
62 case EM_X86_64:
63 stubs = new StubLayoutX86_64();
Stephen Hinesb53c8a52013-04-05 22:17:36 -070064 break;
65
66 default:
Xiaofei Wan72151aa2014-06-12 21:44:09 +080067 stubs = NULL;
Stephen Hinesb53c8a52013-04-05 22:17:36 -070068 }
69 }
70
71 ~ELFSectionProgBits() {
72 if (stubs)
73 delete stubs;
74 }
75
76private:
77 template <typename Archiver>
78 bool serialize(Archiver &AR) {
79 ELFSectionHeaderTy const *sh = this->sh;
80 MemChunk &chunk = this->chunk;
81
82 AR.seek(sh->getOffset(), true);
83 AR.prologue(sh->getSize());
84 AR.readBytes(chunk.getBuffer(), sh->getSize());
85 AR.epilogue(sh->getSize());
86
87 return AR;
88 }
89};
90
91#include "impl/ELFSectionProgBits.hxx"
92
93#endif // ELF_SECTION_PROGBITS_H