| Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 1 | //===- lib/ReaderWriter/MachO/ExecutableAtoms.hpp -------------------------===// |
| 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 | |
| Rui Ueyama | 014192db | 2013-11-15 03:09:26 +0000 | [diff] [blame] | 10 | #ifndef LLD_READER_WRITER_MACHO_EXECUTABLE_ATOMS_H |
| 11 | #define LLD_READER_WRITER_MACHO_EXECUTABLE_ATOMS_H |
| Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 12 | |
| Nick Kledzik | 473933b | 2013-09-27 22:50:00 +0000 | [diff] [blame] | 13 | #include "llvm/Support/MachO.h" |
| Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 14 | |
| 15 | #include "lld/Core/DefinedAtom.h" |
| Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 16 | #include "lld/Core/File.h" |
| Rui Ueyama | 0ca149f | 2013-08-06 22:31:59 +0000 | [diff] [blame] | 17 | #include "lld/Core/LinkingContext.h" |
| Rui Ueyama | e05d380 | 2014-06-11 21:47:51 +0000 | [diff] [blame] | 18 | #include "lld/Core/Reference.h" |
| 19 | #include "lld/Core/Simple.h" |
| 20 | #include "lld/Core/UndefinedAtom.h" |
| Rafael Espindola | 1675d51 | 2014-06-12 17:12:28 +0000 | [diff] [blame] | 21 | #include "lld/ReaderWriter/MachOLinkingContext.h" |
| Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 22 | |
| 23 | namespace lld { |
| 24 | namespace mach_o { |
| 25 | |
| 26 | |
| 27 | // |
| 28 | // CRuntimeFile adds an UndefinedAtom for "_main" so that the Resolving |
| 29 | // phase will fail if "_main" is undefined. |
| 30 | // |
| 31 | class CRuntimeFile : public SimpleFile { |
| 32 | public: |
| Rui Ueyama | 170a1a8 | 2013-12-20 07:48:29 +0000 | [diff] [blame] | 33 | CRuntimeFile(const MachOLinkingContext &context) |
| Nick Kledzik | 2458bec | 2014-07-16 19:49:02 +0000 | [diff] [blame] | 34 | : SimpleFile("C runtime"), |
| 35 | _undefMain(*this, context.entrySymbolName()), |
| 36 | _undefBinder(*this, context.binderSymbolName()) { |
| Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 37 | // only main executables need _main |
| Tim Northover | d30a1f2 | 2014-06-20 15:59:00 +0000 | [diff] [blame] | 38 | if (context.outputMachOType() == llvm::MachO::MH_EXECUTE) { |
| Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 39 | this->addAtom(_undefMain); |
| Nick Kledzik | c314b46 | 2013-04-04 18:59:24 +0000 | [diff] [blame] | 40 | } |
| Nick Kledzik | 2458bec | 2014-07-16 19:49:02 +0000 | [diff] [blame] | 41 | // only dynamic binaries use stubs |
| 42 | if (context.needsStubsPass()) { |
| 43 | this->addAtom(_undefBinder); |
| 44 | } |
| Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 45 | } |
| Nick Kledzik | c314b46 | 2013-04-04 18:59:24 +0000 | [diff] [blame] | 46 | |
| Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 47 | private: |
| 48 | SimpleUndefinedAtom _undefMain; |
| Nick Kledzik | 2458bec | 2014-07-16 19:49:02 +0000 | [diff] [blame] | 49 | SimpleUndefinedAtom _undefBinder; |
| Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
| Rui Ueyama | 0ca149f | 2013-08-06 22:31:59 +0000 | [diff] [blame] | 52 | } // namespace mach_o |
| 53 | } // namespace lld |
| Nick Kledzik | abb6981 | 2012-05-31 22:34:00 +0000 | [diff] [blame] | 54 | |
| Rui Ueyama | 014192db | 2013-11-15 03:09:26 +0000 | [diff] [blame] | 55 | #endif // LLD_READER_WRITER_MACHO_EXECUTABLE_ATOMS_H |