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