]> git.saurik.com Git - apple/ld64.git/blame - src/ld/parsers/opaque_section_file.cpp
ld64-128.2.tar.gz
[apple/ld64.git] / src / ld / parsers / opaque_section_file.cpp
CommitLineData
a645023d
A
1/* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
2 *
3 * Copyright (c) 2005-2009 Apple Inc. All rights reserved.
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
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
12 * file.
13 *
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.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24
25
26#include <vector>
27
28#include "ld.hpp"
29#include "opaque_section_file.h"
30
31
32namespace opaque_section {
33
34
35
36class Atom : public ld::Atom {
37public:
38 virtual ld::File* file() const { return (ld::File*)&_file; }
39 virtual bool translationUnitSource(const char** dir, const char** ) const
40 { return false; }
41 virtual const char* name() const { return _name; }
42 virtual uint64_t size() const { return _size; }
43 virtual uint64_t objectAddress() const { return 0; }
44 virtual void copyRawContent(uint8_t buffer[]) const
45 { memcpy(buffer, _content, _size); }
46 virtual void setScope(Scope) { }
47
48protected:
49 friend class File;
50 Atom(class File& f, const char* n, const uint8_t* content, uint64_t sz);
51 virtual ~Atom() {}
52
53 class File& _file;
54 const char* _name;
55 const uint8_t* _content;
56 uint64_t _size;
57};
58
59
60class File : public ld::File
61{
62public:
63 File(const char* segmentName, const char* sectionName, const char* pth,
64 const uint8_t fileContent[], uint64_t fileLength, uint32_t ord,
65 const char* symbolName="sect_create")
66 : ld::File(pth, 0, ord),
67 _atom(*this, symbolName, fileContent, fileLength),
68 _section(segmentName, sectionName, ld::Section::typeUnclassified) { }
69 virtual ~File() { }
70
71 virtual bool forEachAtom(ld::File::AtomHandler& h) const { h.doAtom(_atom); return true; }
72 virtual bool justInTimeforEachAtom(const char* name, ld::File::AtomHandler&) const { return false; }
73
74 ld::Atom* atom() { return &_atom; }
75private:
76 friend class Atom;
77
78 Atom _atom;
79 ld::Section _section;
80};
81
82Atom::Atom(File& f, const char* n, const uint8_t* content, uint64_t sz)
83 : ld::Atom(f._section, ld::Atom::definitionRegular, ld::Atom::combineNever,
84 ld::Atom::scopeTranslationUnit, ld::Atom::typeUnclassified,
85 symbolTableNotIn, true, false, false, ld::Atom::Alignment(0)),
86 _file(f), _name(n), _content(content), _size(sz) {}
87
88
89//
90// main function used by linker for -sectcreate
91//
92ld::File* parse(const char* segmentName, const char* sectionName, const char* path,
93 const uint8_t fileContent[], uint64_t fileLength, uint32_t ordinal,
94 const char* symbolName)
95{
96 return new File(segmentName, sectionName, path, fileContent, fileLength, ordinal, symbolName);
97}
98
99
100} // namespace opaque_section
101
102
103
104
105
106