1 //===- InputFiles.h ---------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLD_MACHO_INPUT_FILES_H
10 #define LLD_MACHO_INPUT_FILES_H
11 
12 #include "lld/Common/LLVM.h"
13 #include "llvm/ADT/DenseSet.h"
14 #include "llvm/BinaryFormat/MachO.h"
15 #include "llvm/Object/Archive.h"
16 #include "llvm/Support/MemoryBuffer.h"
17 #include <vector>
18 
19 namespace lld {
20 namespace macho {
21 
22 class InputSection;
23 class Symbol;
24 struct Reloc;
25 
26 class InputFile {
27 public:
28   enum Kind {
29     ObjKind,
30   };
31 
32   virtual ~InputFile() = default;
33 
34   Kind kind() const { return fileKind; }
35   StringRef getName() const { return mb.getBufferIdentifier(); }
36 
37   MemoryBufferRef mb;
38   std::vector<Symbol *> symbols;
39   std::vector<InputSection *> sections;
40   StringRef dylibName;
41 
42 protected:
43   InputFile(Kind kind, MemoryBufferRef mb) : mb(mb), fileKind(kind) {}
44 
45   std::vector<InputSection *> parseSections(ArrayRef<llvm::MachO::section_64>);
46 
47   void parseRelocations(const llvm::MachO::section_64 &,
48                         std::vector<Reloc> &relocs);
49 
50 private:
51   const Kind fileKind;
52 };
53 
54 // .o file
55 class ObjFile : public InputFile {
56 public:
57   explicit ObjFile(MemoryBufferRef mb);
58   static bool classof(const InputFile *f) { return f->kind() == ObjKind; }
59 };
60 
61 extern std::vector<InputFile *> inputFiles;
62 
63 llvm::Optional<MemoryBufferRef> readFile(StringRef path);
64 
65 } // namespace macho
66 
67 std::string toString(const macho::InputFile *file);
68 } // namespace lld
69 
70 #endif
71