]>
git.saurik.com Git - apple/ld64.git/blob - src/SectCreate.cpp
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@
26 #include "ObjectFile.h"
28 namespace SectCreate
{
31 class Segment
: public ObjectFile::Segment
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; }
44 class Reader
: public ObjectFile::Reader
47 Reader(const char* segmentName
, const char* sectionName
, const char* path
, const uint8_t fileContent
[], uint64_t fileLength
);
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
; }
57 std::vector
<class ObjectFile::Atom
*> fAtoms
;
61 class Atom
: public ObjectFile::Atom
{
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;
88 virtual void setScope(Scope
) { }
89 virtual void setImportWeakness(bool) { }
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
) {}
100 const char* fSectionName
;
101 const uint8_t* fFileContent
;
102 uint64_t fFileLength
;
104 static std::vector
<ObjectFile::Reference
*> fgEmptyReferenceList
;
108 std::vector
<ObjectFile::Reference
*> Atom::fgEmptyReferenceList
;
112 Reader::Reader(const char* segmentName
, const char* sectionName
, const char* path
, const uint8_t fileContent
[], uint64_t fileLength
)
115 fAtoms
.push_back(new Atom(*this, *(new Segment(segmentName
)), sectionName
, fileContent
, fileLength
));
123 const char* Atom::getDisplayName() const
125 static char name
[64];
126 sprintf(name
, "-sectcreate %s %s", fSegment
.getName(), fSectionName
);
131 void Atom::copyRawContent(uint8_t buffer
[]) const
133 memcpy(buffer
, fFileContent
, fFileLength
);
136 void Atom::writeContent(bool finalLinkedImage
, ObjectFile::ContentWriter
& writer
) const
138 writer
.write(0, fFileContent
, fFileLength
);
142 Reader
* MakeReader(const char* segmentName
, const char* sectionName
, const char* path
, const uint8_t fileContent
[], uint64_t fileLength
)
144 return new Reader(segmentName
, sectionName
, path
, fileContent
, fileLength
);