1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
22 * @APPLE_LICENSE_HEADER_END@
26 #ifndef __OBJECTFILE__
27 #define __OBJECTFILE__
35 namespace ObjectFile
{
49 ReaderOptions() : fFullyLoadArchives(false), fLoadObjcClassesInArchives(false), fFlatNamespace(false),
50 fStripDebugInfo(false), fTraceDylibs(false), fTraceIndirectDylibs(false), fTraceArchives(false) {}
52 bool fFullyLoadArchives
;
53 bool fLoadObjcClassesInArchives
;
57 bool fTraceIndirectDylibs
;
65 static Reader
* createReader(const char* path
, const ReaderOptions
& options
);
67 virtual const char* getPath() = 0;
68 virtual std::vector
<class Atom
*>& getAtoms() = 0;
69 virtual std::vector
<class Atom
*>* getJustInTimeAtomsFor(const char* name
) = 0;
70 virtual std::vector
<StabsInfo
>* getStabsDebugInfo() = 0;
72 // For Dynamic Libraries only
73 virtual const char* getInstallPath() { return NULL
; }
74 virtual uint32_t getTimestamp() { return 0; }
75 virtual uint32_t getCurrentVersion() { return 0; }
76 virtual uint32_t getCompatibilityVersion() { return 0; }
77 virtual std::vector
<const char*>* getDependentLibraryPaths() { return NULL
; }
78 virtual bool reExports(Reader
*) { return false; }
79 virtual bool isDefinitionWeak(const Atom
&){ return false; }
91 virtual const char* getName() const = 0;
92 virtual bool isContentReadable() const = 0;
93 virtual bool isContentWritable() const = 0;
94 virtual bool isContentExecutable() const = 0;
96 uint64_t getBaseAddress() const { return fBaseAddress
; }
97 void setBaseAddress(uint64_t addr
) { fBaseAddress
= addr
; }
98 virtual bool hasFixedAddress() const { return false; }
101 Segment() : fBaseAddress(0) {}
102 virtual ~Segment() {}
103 uint64_t fBaseAddress
;
111 unsigned int getIndex() { return fIndex
; }
112 uint64_t getBaseAddress() { return fBaseAddress
; }
113 void setBaseAddress(uint64_t addr
) { fBaseAddress
= addr
; }
117 Section() : fOther(NULL
), fBaseAddress(0), fIndex(0) {}
118 uint64_t fBaseAddress
;
126 virtual void write(uint64_t atomOffset
, const void* buffer
, uint64_t size
) = 0;
129 virtual ~ContentWriter() {}
135 enum Scope
{ scopeTranslationUnit
, scopeLinkageUnit
, scopeGlobal
};
136 enum WeakImportSetting
{ kWeakUnset
, kWeakImport
, kNonWeakImport
};
138 virtual Reader
* getFile() const = 0;
139 virtual const char* getName() const = 0;
140 virtual const char* getDisplayName() const = 0;
141 virtual Scope
getScope() const = 0;
142 virtual bool isTentativeDefinition() const = 0;
143 virtual bool isWeakDefinition() const = 0;
144 virtual bool isCoalesableByName() const = 0;
145 virtual bool isCoalesableByValue() const = 0;
146 virtual bool isZeroFill() const = 0;
147 virtual bool dontDeadStrip() const = 0;
148 virtual bool dontStripName() const = 0; // referenced dynamically
149 virtual bool isImportProxy() const = 0;
150 virtual uint64_t getSize() const = 0;
151 virtual std::vector
<ObjectFile::Reference
*>& getReferences() const = 0;
152 virtual bool mustRemainInSection() const = 0;
153 virtual const char* getSectionName() const = 0;
154 virtual Segment
& getSegment() const = 0;
155 virtual bool requiresFollowOnAtom() const = 0;
156 virtual Atom
& getFollowOnAtom() const = 0;
157 virtual std::vector
<StabsInfo
>* getStabsDebugInfo() const = 0;
158 virtual uint8_t getAlignment() const = 0;
159 virtual WeakImportSetting
getImportWeakness() const = 0;
160 virtual void copyRawContent(uint8_t buffer
[]) const = 0;
161 virtual void writeContent(bool finalLinkedImage
, ContentWriter
&) const = 0;
162 virtual void setScope(Scope
) = 0;
163 virtual void setImportWeakness(bool weakImport
) = 0;
166 uint64_t getSectionOffset() const { return fSectionOffset
; }
167 uint64_t getSegmentOffset() const { return fSegmentOffset
; }
168 uint64_t getAddress() const { return fSection
->getBaseAddress() + fSectionOffset
; }
169 unsigned int getSortOrder() const { return fSortOrder
; }
170 class Section
* getSection() const { return fSection
; }
172 void setSegmentOffset(uint64_t offset
) { fSegmentOffset
= offset
; }
173 void setSectionOffset(uint64_t offset
) { fSectionOffset
= offset
; }
174 void setSection(class Section
* sect
) { fSection
= sect
; }
175 unsigned int setSortOrder(unsigned int order
); // recursively sets follow-on atoms
178 Atom() : fSegmentOffset(0), fSectionOffset(0), fSortOrder(0), fSection(NULL
) {}
181 uint64_t fSegmentOffset
;
182 uint64_t fSectionOffset
;
183 unsigned int fSortOrder
;
184 class Section
* fSection
;
189 // recursively sets follow-on atoms
190 inline unsigned int Atom::setSortOrder(unsigned int order
)
192 if ( this->requiresFollowOnAtom() ) {
194 return this->getFollowOnAtom().setSortOrder(order
+1);
207 enum Kind
{ noFixUp
, pointer
, ppcFixupBranch24
, ppcFixupBranch14
,
208 ppcFixupPicBaseLow16
, ppcFixupPicBaseLow14
, ppcFixupPicBaseHigh16
,
209 ppcFixupAbsLow16
, ppcFixupAbsLow14
, ppcFixupAbsHigh16
, ppcFixupAbsHigh16AddLow
,
210 pointer32Difference
, pointer64Difference
, x86FixupBranch32
};
212 virtual bool isTargetUnbound() const = 0;
213 virtual bool isFromTargetUnbound() const = 0;
214 virtual bool requiresRuntimeFixUp(bool slideable
) const = 0;
215 virtual bool isWeakReference() const = 0;
216 virtual bool isLazyReference() const = 0;
217 virtual Kind
getKind() const = 0;
218 virtual uint64_t getFixUpOffset() const = 0;
219 virtual const char* getTargetName() const = 0;
220 virtual Atom
& getTarget() const = 0;
221 virtual uint64_t getTargetOffset() const = 0;
222 virtual bool hasFromTarget() const = 0;
223 virtual Atom
& getFromTarget() const = 0;
224 virtual const char* getFromTargetName() const = 0;
225 virtual uint64_t getFromTargetOffset() const = 0;
227 virtual void setTarget(Atom
&, uint64_t offset
) = 0;
228 virtual void setFromTarget(Atom
&) = 0;
229 virtual const char* getDescription() const = 0;
233 virtual ~Reference() {}
237 }; // namespace ObjectFile
240 #endif // __OBJECTFILE__