]>
git.saurik.com Git - apple/ld64.git/blob - src/SectCreate.cpp
a77a78746b179be87e60808f9b3740b2a2d4bcf6
1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2005-2006 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@
27 #include "ObjectFile.h"
29 namespace SectCreate
{
32 class Segment
: public ObjectFile::Segment
35 Segment(const char* name
) { fName
= name
; }
36 virtual const char* getName() const { return fName
; }
37 virtual bool isContentReadable() const { return true; }
38 virtual bool isContentWritable() const { return false; }
39 virtual bool isContentExecutable() const { return false; }
45 class Reader
: public ObjectFile::Reader
48 Reader(const char* segmentName
, const char* sectionName
, const char* path
, const uint8_t fileContent
[], uint64_t fileLength
);
51 virtual const char* getPath() { return fPath
; }
52 virtual time_t getModificationTime() { return 0; }
53 virtual DebugInfoKind
getDebugInfoKind() { return ObjectFile::Reader::kDebugInfoNone
; }
54 virtual std::vector
<class ObjectFile::Atom
*>& getAtoms() { return fAtoms
; }
55 virtual std::vector
<class ObjectFile::Atom
*>* getJustInTimeAtomsFor(const char* name
) { return NULL
; }
56 virtual std::vector
<Stab
>* getStabs() { return NULL
; }
60 std::vector
<class ObjectFile::Atom
*> fAtoms
;
64 class Atom
: public ObjectFile::Atom
{
66 virtual ObjectFile::Reader
* getFile() const { return &fOwner
; }
67 virtual bool getTranslationUnitSource(const char** dir
, const char** name
) const { return false; }
68 virtual const char* getName() const { return NULL
; }
69 virtual const char* getDisplayName() const;
70 virtual Scope
getScope() const { return ObjectFile::Atom::scopeTranslationUnit
; }
71 virtual DefinitionKind
getDefinitionKind() const { return kRegularDefinition
; }
72 virtual SymbolTableInclusion
getSymbolTableInclusion() const { return ObjectFile::Atom::kSymbolTableNotIn
; }
73 virtual bool dontDeadStrip() const { return true; }
74 virtual bool isZeroFill() 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::LineInfo
>* getLineInfo() const { return NULL
; }
83 virtual uint8_t getAlignment() const { return 4; }
84 virtual void copyRawContent(uint8_t buffer
[]) const;
86 virtual void setScope(Scope
) { }
91 Atom(Reader
& owner
, Segment
& segment
, const char* sectionName
, const uint8_t fileContent
[], uint64_t fileLength
)
92 : fOwner(owner
), fSegment(segment
), fSectionName(sectionName
), fFileContent(fileContent
), fFileLength(fileLength
) { }
97 const char* fSectionName
;
98 const uint8_t* fFileContent
;
101 static std::vector
<ObjectFile::Reference
*> fgEmptyReferenceList
;
105 std::vector
<ObjectFile::Reference
*> Atom::fgEmptyReferenceList
;
109 Reader::Reader(const char* segmentName
, const char* sectionName
, const char* path
, const uint8_t fileContent
[], uint64_t fileLength
)
112 fAtoms
.push_back(new Atom(*this, *(new Segment(segmentName
)), sectionName
, fileContent
, fileLength
));
120 const char* Atom::getDisplayName() const
122 static char name
[64];
123 sprintf(name
, "-sectcreate %s %s", fSegment
.getName(), fSectionName
);
128 void Atom::copyRawContent(uint8_t buffer
[]) const
130 memcpy(buffer
, fFileContent
, fFileLength
);
133 Reader
* MakeReader(const char* segmentName
, const char* sectionName
, const char* path
, const uint8_t fileContent
[], uint64_t fileLength
)
135 return new Reader(segmentName
, sectionName
, path
, fileContent
, fileLength
);