• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- Core/UndefinedAtom.h - An Undefined Atom ---------------------------===//
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_CORE_UNDEFINED_ATOM_H
10 #define LLD_CORE_UNDEFINED_ATOM_H
11 
12 #include "lld/Core/Atom.h"
13 
14 namespace lld {
15 
16 /// An UndefinedAtom has no content.
17 /// It exists as a placeholder for a future atom.
18 class UndefinedAtom : public Atom {
19 public:
20   /// Whether this undefined symbol needs to be resolved,
21   /// or whether it can just evaluate to nullptr.
22   /// This concept is often called "weak", but that term
23   /// is overloaded to mean other things too.
24   enum CanBeNull {
25     /// Normal symbols must be resolved at build time
26     canBeNullNever,
27 
28     /// This symbol can be missing at runtime and will evaluate to nullptr.
29     /// That is, the static linker still must find a definition (usually
30     /// is some shared library), but at runtime, the dynamic loader
31     /// will allow the symbol to be missing and resolved to nullptr.
32     ///
33     /// On Darwin this is generated using a function prototype with
34     /// __attribute__((weak_import)).
35     /// On linux this is generated using a function prototype with
36     ///  __attribute__((weak)).
37     /// On Windows this feature is not supported.
38     canBeNullAtRuntime,
39 
40     /// This symbol can be missing at build time.
41     /// That is, the static linker will not error if a definition for
42     /// this symbol is not found at build time. Instead, the linker
43     /// will build an executable that lets the dynamic loader find the
44     /// symbol at runtime.
45     /// This feature is not supported on Darwin nor Windows.
46     /// On linux this is generated using a function prototype with
47     ///  __attribute__((weak)).
48     canBeNullAtBuildtime
49   };
50 
51   virtual CanBeNull canBeNull() const = 0;
52 
classof(const Atom * a)53   static bool classof(const Atom *a) {
54     return a->definition() == definitionUndefined;
55   }
56 
classof(const UndefinedAtom *)57   static bool classof(const UndefinedAtom *) { return true; }
58 
59 protected:
UndefinedAtom()60   UndefinedAtom() : Atom(definitionUndefined) {}
61 
62   ~UndefinedAtom() override = default;
63 };
64 
65 } // namespace lld
66 
67 #endif // LLD_CORE_UNDEFINED_ATOM_H
68