2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 #ifndef __OBJECTFILE__
26 #define __OBJECTFILE__
34 namespace ObjectFile
{
48 ReaderOptions() : fFullyLoadArchives(false), fLoadObjcClassesInArchives(false), fFlatNamespace(false),
49 fStripDebugInfo(false), fTraceDylibs(false), fTraceIndirectDylibs(false), fTraceArchives(false) {}
51 bool fFullyLoadArchives
;
52 bool fLoadObjcClassesInArchives
;
56 bool fTraceIndirectDylibs
;
64 static Reader
* createReader(const char* path
, const ReaderOptions
& options
);
66 virtual const char* getPath() = 0;
67 virtual std::vector
<class Atom
*>& getAtoms() = 0;
68 virtual std::vector
<class Atom
*>* getJustInTimeAtomsFor(const char* name
) = 0;
69 virtual std::vector
<StabsInfo
>* getStabsDebugInfo() = 0;
71 // For Dynamic Libraries only
72 virtual const char* getInstallPath() { return NULL
; }
73 virtual uint32_t getTimestamp() { return 0; }
74 virtual uint32_t getCurrentVersion() { return 0; }
75 virtual uint32_t getCompatibilityVersion() { return 0; }
76 virtual std::vector
<const char*>* getDependentLibraryPaths() { return NULL
; }
77 virtual bool reExports(Reader
*) { return false; }
78 virtual bool isDefinitionWeak(const Atom
&){ return false; }
89 virtual const char* getName() const = 0;
90 virtual bool isContentReadable() const = 0;
91 virtual bool isContentWritable() const = 0;
92 virtual bool isContentExecutable() const = 0;
94 uint64_t getBaseAddress() const { return fBaseAddress
; }
95 void setBaseAddress(uint64_t addr
) { fBaseAddress
= addr
; }
98 Segment() : fBaseAddress(0) {}
99 uint64_t fBaseAddress
;
107 unsigned int getIndex() { return fIndex
; }
108 uint64_t getBaseAddress() { return fBaseAddress
; }
109 void setBaseAddress(uint64_t addr
) { fBaseAddress
= addr
; }
113 Section() : fOther(NULL
), fBaseAddress(0), fIndex(0) {}
114 uint64_t fBaseAddress
;
122 virtual void write(uint64_t atomOffset
, const void* buffer
, uint64_t size
) = 0;
128 enum Scope
{ scopeTranslationUnit
, scopeLinkageUnit
, scopeGlobal
};
129 enum WeakImportSetting
{ kWeakUnset
, kWeakImport
, kNonWeakImport
};
131 virtual Reader
* getFile() const = 0;
132 virtual const char* getName() const = 0;
133 virtual const char* getDisplayName() const = 0;
134 virtual Scope
getScope() const = 0;
135 virtual bool isTentativeDefinition() const = 0;
136 virtual bool isWeakDefinition() const = 0;
137 virtual bool isCoalesableByName() const = 0;
138 virtual bool isCoalesableByValue() const = 0;
139 virtual bool isZeroFill() const = 0;
140 virtual bool dontDeadStrip() const = 0;
141 virtual bool dontStripName() const = 0; // referenced dynamically
142 virtual bool isImportProxy() const = 0;
143 virtual uint64_t getSize() const = 0;
144 virtual std::vector
<ObjectFile::Reference
*>& getReferences() const = 0;
145 virtual bool mustRemainInSection() const = 0;
146 virtual const char* getSectionName() const = 0;
147 virtual Segment
& getSegment() const = 0;
148 virtual bool requiresFollowOnAtom() const = 0;
149 virtual Atom
& getFollowOnAtom() const = 0;
150 virtual std::vector
<StabsInfo
>* getStabsDebugInfo() const = 0;
151 virtual uint8_t getAlignment() const = 0;
152 virtual WeakImportSetting
getImportWeakness() const = 0;
153 virtual void copyRawContent(uint8_t buffer
[]) const = 0;
154 virtual void writeContent(bool finalLinkedImage
, ContentWriter
&) const = 0;
155 virtual void setScope(Scope
) = 0;
156 virtual void setImportWeakness(bool weakImport
) = 0;
159 uint64_t getSectionOffset() const { return fSectionOffset
; }
160 uint64_t getSegmentOffset() const { return fSegmentOffset
; }
161 uint64_t getAddress() const { return fSection
->getBaseAddress() + fSectionOffset
; }
162 unsigned int getSortOrder() const { return fSortOrder
; }
163 class Section
* getSection() const { return fSection
; }
165 void setSegmentOffset(uint64_t offset
) { fSegmentOffset
= offset
; }
166 void setSectionOffset(uint64_t offset
) { fSectionOffset
= offset
; }
167 void setSection(class Section
* sect
) { fSection
= sect
; }
168 unsigned int setSortOrder(unsigned int order
); // recursively sets follow-on atoms
171 Atom() : fSegmentOffset(0), fSectionOffset(0), fSortOrder(0), fSection(NULL
) {}
173 uint64_t fSegmentOffset
;
174 uint64_t fSectionOffset
;
175 unsigned int fSortOrder
;
176 class Section
* fSection
;
181 // recursively sets follow-on atoms
182 inline unsigned int Atom::setSortOrder(unsigned int order
)
184 if ( this->requiresFollowOnAtom() ) {
186 return this->getFollowOnAtom().setSortOrder(order
+1);
199 enum Kind
{ noFixUp
, pointer
, ppcFixupBranch24
, ppcFixupBranch14
,
200 ppcFixupPicBaseLow16
, ppcFixupPicBaseLow14
, ppcFixupPicBaseHigh16
,
201 ppcFixupAbsLow16
, ppcFixupAbsLow14
, ppcFixupAbsHigh16
, ppcFixupAbsHigh16AddLow
,
202 pointer32Difference
, pointer64Difference
, x86FixupBranch32
};
204 virtual bool isUnbound() const = 0;
205 virtual bool isWeakReference() const = 0;
206 virtual bool requiresRuntimeFixUp() const = 0;
207 virtual bool isLazyReference() const = 0;
208 virtual Kind
getKind() const = 0;
209 virtual uint64_t getFixUpOffset() const = 0;
210 virtual const char* getTargetName() const = 0;
211 virtual Atom
& getTarget() const = 0;
212 virtual uint64_t getTargetOffset() const = 0;
213 virtual Atom
& getFromTarget() const = 0;
214 virtual const char* getFromTargetName() const = 0;
215 virtual uint64_t getFromTargetOffset() const = 0;
217 virtual void setTarget(Atom
&) = 0;
218 virtual void setFromTarget(Atom
&) = 0;
219 virtual const char* getDescription() const = 0;
223 }; // namespace ObjectFile
226 #endif // __OBJECTFILE__