blob: b6d615ae20ed09e450e595ce3d8f8c417dc82f73 [file] [log] [blame]
Nick Kledzikabb69812012-05-31 22:34:00 +00001//===- 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 Ueyama014192db2013-11-15 03:09:26 +000010#ifndef LLD_READER_WRITER_MACHO_EXECUTABLE_ATOMS_H
11#define LLD_READER_WRITER_MACHO_EXECUTABLE_ATOMS_H
Nick Kledzikabb69812012-05-31 22:34:00 +000012
Nick Kledzik473933b2013-09-27 22:50:00 +000013#include "llvm/Support/MachO.h"
Nick Kledzikabb69812012-05-31 22:34:00 +000014
15#include "lld/Core/DefinedAtom.h"
Nick Kledzikabb69812012-05-31 22:34:00 +000016#include "lld/Core/File.h"
Rui Ueyama0ca149f2013-08-06 22:31:59 +000017#include "lld/Core/LinkingContext.h"
Rui Ueyamae05d3802014-06-11 21:47:51 +000018#include "lld/Core/Reference.h"
19#include "lld/Core/Simple.h"
20#include "lld/Core/UndefinedAtom.h"
Nick Kledzikabb69812012-05-31 22:34:00 +000021
22namespace lld {
23namespace mach_o {
24
25
26//
27// CRuntimeFile adds an UndefinedAtom for "_main" so that the Resolving
28// phase will fail if "_main" is undefined.
29//
30class CRuntimeFile : public SimpleFile {
31public:
Rui Ueyama170a1a82013-12-20 07:48:29 +000032 CRuntimeFile(const MachOLinkingContext &context)
33 : SimpleFile("C runtime"), _undefMain(*this, context.entrySymbolName()) {
Nick Kledzikabb69812012-05-31 22:34:00 +000034 // only main executables need _main
Nick Kledzik473933b2013-09-27 22:50:00 +000035 if (context.outputFileType() == llvm::MachO::MH_EXECUTE) {
Nick Kledzikabb69812012-05-31 22:34:00 +000036 this->addAtom(_undefMain);
Nick Kledzikc314b462013-04-04 18:59:24 +000037 }
Nick Kledzikabb69812012-05-31 22:34:00 +000038 }
Nick Kledzikc314b462013-04-04 18:59:24 +000039
Nick Kledzikabb69812012-05-31 22:34:00 +000040private:
41 SimpleUndefinedAtom _undefMain;
42};
43
Rui Ueyama0ca149f2013-08-06 22:31:59 +000044} // namespace mach_o
45} // namespace lld
Nick Kledzikabb69812012-05-31 22:34:00 +000046
Rui Ueyama014192db2013-11-15 03:09:26 +000047#endif // LLD_READER_WRITER_MACHO_EXECUTABLE_ATOMS_H