]>
git.saurik.com Git - apple/ld64.git/blob - src/ld/parsers/opaque_section_file.cpp
e60332b84c252c3552b030afc9b500f2fe31fd3b
1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2005-2009 Apple 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@
29 #include "opaque_section_file.h"
32 namespace opaque_section
{
36 class Atom
: public ld::Atom
{
38 virtual ld::File
* file() const { return (ld::File
*)&_file
; }
39 virtual const char* name() const { return _name
; }
40 virtual uint64_t size() const { return _size
; }
41 virtual uint64_t objectAddress() const { return 0; }
42 virtual void copyRawContent(uint8_t buffer
[]) const
43 { memcpy(buffer
, _content
, _size
); }
44 virtual void setScope(Scope
) { }
48 Atom(class File
& f
, const char* n
, const uint8_t* content
, uint64_t sz
);
53 const uint8_t* _content
;
58 class File
: public ld::File
61 File(const char* segmentName
, const char* sectionName
, const char* pth
,
62 const uint8_t fileContent
[], uint64_t fileLength
,
63 const char* symbolName
="sect_create")
64 : ld::File(pth
, 0, ld::File::Ordinal::NullOrdinal(), Other
),
65 _atom(*this, symbolName
, fileContent
, fileLength
),
66 _section(segmentName
, sectionName
, ld::Section::typeUnclassified
) { }
69 virtual bool forEachAtom(ld::File::AtomHandler
& h
) const { h
.doAtom(_atom
); return true; }
70 virtual bool justInTimeforEachAtom(const char* name
, ld::File::AtomHandler
&) const { return false; }
72 ld::Atom
* atom() { return &_atom
; }
80 Atom::Atom(File
& f
, const char* n
, const uint8_t* content
, uint64_t sz
)
81 : ld::Atom(f
._section
, ld::Atom::definitionRegular
, ld::Atom::combineNever
,
82 ld::Atom::scopeTranslationUnit
, ld::Atom::typeUnclassified
,
83 symbolTableNotIn
, true, false, false, ld::Atom::Alignment(0)),
84 _file(f
), _name(n
), _content(content
), _size(sz
) {}
88 // main function used by linker for -sectcreate
90 ld::File
* parse(const char* segmentName
, const char* sectionName
, const char* path
,
91 const uint8_t fileContent
[], uint64_t fileLength
,
92 const char* symbolName
)
94 return new File(segmentName
, sectionName
, path
, fileContent
, fileLength
, symbolName
);
98 } // namespace opaque_section