blob: 2032e0cea0575f144e088db40fd329b34667c964 [file] [log] [blame]
Joey Goulyceb16de2014-01-03 23:12:02 +00001//===- lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp --------------===//
2//
3// The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10///
11/// \file Converts from in-memory normalized mach-o to in-memory Atoms.
12///
13/// +------------+
14/// | normalized |
15/// +------------+
16/// |
17/// |
18/// v
19/// +-------+
20/// | Atoms |
21/// +-------+
22
23#include "MachONormalizedFile.h"
24#include "File.h"
25#include "Atoms.h"
26
27#include "lld/Core/LLVM.h"
28
29#include "llvm/Support/MachO.h"
30
31using namespace llvm::MachO;
32
33namespace lld {
34namespace mach_o {
35namespace normalized {
36
37static ErrorOr<std::unique_ptr<lld::File>>
38normalizedObjectToAtoms(const NormalizedFile &normalizedFile, StringRef path) {
39 std::unique_ptr<MachOFile> file(new MachOFile(path));
40
41 for (auto &sym : normalizedFile.globalSymbols) {
42 file->addDefinedAtom(sym.name,
43 normalizedFile.sections[sym.sect - 1].content);
44 }
45
46 assert(normalizedFile.localSymbols.empty() &&
47 "local symbols not supported yet!");
48 assert(normalizedFile.undefinedSymbols.empty() &&
49 "undefined symbols not supported yet!");
50
51 return std::unique_ptr<File>(std::move(file));
52}
53
54ErrorOr<std::unique_ptr<lld::File>>
55normalizedToAtoms(const NormalizedFile &normalizedFile, StringRef path) {
56 switch (normalizedFile.fileType) {
57 case MH_OBJECT:
58 return normalizedObjectToAtoms(normalizedFile, path);
59 default:
60 llvm_unreachable("unhandled MachO file type!");
61 }
62}
63
64} // namespace normalized
65} // namespace mach_o
66} // namespace lld