]>
Commit | Line | Data |
---|---|---|
c2646906 A |
1 | /* |
2 | * Copyright (c) 2005 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
12 | * | |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | ||
24 | #include <vector> | |
25 | ||
26 | #include "ObjectFile.h" | |
27 | ||
28 | namespace SectCreate { | |
29 | ||
30 | ||
31 | class Segment : public ObjectFile::Segment | |
32 | { | |
33 | public: | |
34 | Segment(const char* name) { fName = name; } | |
35 | virtual const char* getName() const { return fName; } | |
36 | virtual bool isContentReadable() const { return true; } | |
37 | virtual bool isContentWritable() const { return false; } | |
38 | virtual bool isContentExecutable() const { return false; } | |
39 | private: | |
40 | const char* fName; | |
41 | }; | |
42 | ||
43 | ||
44 | class Reader : public ObjectFile::Reader | |
45 | { | |
46 | public: | |
47 | Reader(const char* segmentName, const char* sectionName, const char* path, const uint8_t fileContent[], uint64_t fileLength); | |
48 | virtual ~Reader(); | |
49 | ||
50 | virtual const char* getPath() { return fPath; } | |
51 | virtual std::vector<class ObjectFile::Atom*>& getAtoms() { return fAtoms; } | |
52 | virtual std::vector<class ObjectFile::Atom*>* getJustInTimeAtomsFor(const char* name) { return NULL; } | |
53 | virtual std::vector<ObjectFile::StabsInfo>* getStabsDebugInfo() { return NULL; } | |
54 | ||
55 | private: | |
56 | const char* fPath; | |
57 | std::vector<class ObjectFile::Atom*> fAtoms; | |
58 | }; | |
59 | ||
60 | ||
61 | class Atom : public ObjectFile::Atom { | |
62 | public: | |
63 | virtual ObjectFile::Reader* getFile() const { return &fOwner; } | |
64 | virtual const char* getName() const { return NULL; } | |
65 | virtual const char* getDisplayName() const; | |
66 | virtual Scope getScope() const { return ObjectFile::Atom::scopeTranslationUnit; } | |
67 | virtual bool isTentativeDefinition() const { return false; } | |
68 | virtual bool isWeakDefinition() const { return false; } | |
69 | virtual bool isCoalesableByName() const { return false; } | |
70 | virtual bool isCoalesableByValue() const { return false; } | |
71 | virtual bool isZeroFill() const { return false; } | |
72 | virtual bool dontDeadStrip() const { return true; } | |
73 | virtual bool dontStripName() const { return false; } | |
74 | virtual bool isImportProxy() const { return false; } | |
75 | virtual uint64_t getSize() const { return fFileLength; } | |
76 | virtual std::vector<ObjectFile::Reference*>& getReferences() const { return fgEmptyReferenceList; } | |
77 | virtual bool mustRemainInSection() const { return false; } | |
78 | virtual const char* getSectionName() const { return fSectionName; } | |
79 | virtual Segment& getSegment() const { return fSegment; } | |
80 | virtual bool requiresFollowOnAtom() const{ return false; } | |
81 | virtual ObjectFile::Atom& getFollowOnAtom() const { return *((ObjectFile::Atom*)NULL); } | |
82 | virtual std::vector<ObjectFile::StabsInfo>* getStabsDebugInfo() const { return NULL; } | |
83 | virtual uint8_t getAlignment() const { return 4; } | |
84 | virtual WeakImportSetting getImportWeakness() const { return ObjectFile::Atom::kWeakUnset; } | |
85 | virtual void copyRawContent(uint8_t buffer[]) const; | |
86 | virtual void writeContent(bool finalLinkedImage, ObjectFile::ContentWriter&) const; | |
87 | ||
88 | virtual void setScope(Scope) { } | |
89 | virtual void setImportWeakness(bool) { } | |
90 | ||
91 | protected: | |
92 | friend class Reader; | |
93 | ||
94 | Atom(Reader& owner, Segment& segment, const char* sectionName, const uint8_t fileContent[], uint64_t fileLength) | |
95 | : fOwner(owner), fSegment(segment), fSectionName(sectionName), fFileContent(fileContent), fFileLength(fileLength) {} | |
96 | virtual ~Atom() {} | |
97 | ||
98 | Reader& fOwner; | |
99 | Segment& fSegment; | |
100 | const char* fSectionName; | |
101 | const uint8_t* fFileContent; | |
102 | uint64_t fFileLength; | |
103 | ||
104 | static std::vector<ObjectFile::Reference*> fgEmptyReferenceList; | |
105 | }; | |
106 | ||
107 | ||
108 | std::vector<ObjectFile::Reference*> Atom::fgEmptyReferenceList; | |
109 | ||
110 | ||
111 | ||
112 | Reader::Reader(const char* segmentName, const char* sectionName, const char* path, const uint8_t fileContent[], uint64_t fileLength) | |
113 | : fPath(path) | |
114 | { | |
115 | fAtoms.push_back(new Atom(*this, *(new Segment(segmentName)), sectionName, fileContent, fileLength)); | |
116 | } | |
117 | ||
118 | Reader::~Reader() | |
119 | { | |
120 | } | |
121 | ||
122 | ||
123 | const char* Atom::getDisplayName() const | |
124 | { | |
125 | static char name[64]; | |
126 | sprintf(name, "-sectcreate %s %s", fSegment.getName(), fSectionName); | |
127 | return name; | |
128 | } | |
129 | ||
130 | ||
131 | void Atom::copyRawContent(uint8_t buffer[]) const | |
132 | { | |
133 | memcpy(buffer, fFileContent, fFileLength); | |
134 | } | |
135 | ||
136 | void Atom::writeContent(bool finalLinkedImage, ObjectFile::ContentWriter& writer) const | |
137 | { | |
138 | writer.write(0, fFileContent, fFileLength); | |
139 | } | |
140 | ||
141 | ||
142 | Reader* MakeReader(const char* segmentName, const char* sectionName, const char* path, const uint8_t fileContent[], uint64_t fileLength) | |
143 | { | |
144 | return new Reader(segmentName, sectionName, path, fileContent, fileLength); | |
145 | } | |
146 | ||
147 | ||
148 | ||
149 | }; | |
150 | ||
151 | ||
152 | ||
153 | ||
154 | ||
155 | ||
156 |