Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
3.2 KiB

  1. //===- llvm/Support/IncludeFile.h - Ensure Linking Of Library ---*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines the FORCE_DEFINING_FILE_TO_BE_LINKED and DEFINE_FILE_FOR
  11. // macros.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_SUPPORT_INCLUDEFILE_H
  15. #define LLVM_SUPPORT_INCLUDEFILE_H
  16. /// This macro is the public interface that IncludeFile.h exports. This gives
  17. /// us the option to implement the "link the definition" capability in any
  18. /// manner that we choose. All header files that depend on a specific .cpp
  19. /// file being linked at run time should use this macro instead of the
  20. /// IncludeFile class directly.
  21. ///
  22. /// For example, foo.h would use:<br/>
  23. /// <tt>FORCE_DEFINING_FILE_TO_BE_LINKED(foo)</tt><br/>
  24. ///
  25. /// And, foo.cp would use:<br/>
  26. /// <tt>DEFINING_FILE_FOR(foo)</tt><br/>
  27. #ifdef __GNUC__
  28. // If the `used' attribute is available, use it to create a variable
  29. // with an initializer that will force the linking of the defining file.
  30. #define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \
  31. namespace llvm { \
  32. extern const char name ## LinkVar; \
  33. __attribute__((used)) static const char *const name ## LinkObj = \
  34. &name ## LinkVar; \
  35. }
  36. #else
  37. // Otherwise use a constructor call.
  38. #define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \
  39. namespace llvm { \
  40. extern const char name ## LinkVar; \
  41. static const IncludeFile name ## LinkObj ( &name ## LinkVar ); \
  42. }
  43. #endif
  44. /// This macro is the counterpart to FORCE_DEFINING_FILE_TO_BE_LINKED. It should
  45. /// be used in a .cpp file to define the name referenced in a header file that
  46. /// will cause linkage of the .cpp file. It should only be used at extern level.
  47. #define DEFINING_FILE_FOR(name) \
  48. namespace llvm { const char name ## LinkVar = 0; }
  49. namespace llvm {
  50. /// This class is used in the implementation of FORCE_DEFINING_FILE_TO_BE_LINKED
  51. /// macro to make sure that the implementation of a header file is included
  52. /// into a tool that uses the header. This is solely
  53. /// to overcome problems linking .a files and not getting the implementation
  54. /// of compilation units we need. This is commonly an issue with the various
  55. /// Passes but also occurs elsewhere in LLVM. We like to use .a files because
  56. /// they link faster and provide the smallest executables. However, sometimes
  57. /// those executables are too small, if the program doesn't reference something
  58. /// that might be needed, especially by a loaded share object. This little class
  59. /// helps to resolve that problem. The basic strategy is to use this class in
  60. /// a header file and pass the address of a variable to the constructor. If the
  61. /// variable is defined in the header file's corresponding .cpp file then all
  62. /// tools/libraries that \#include the header file will require the .cpp as
  63. /// well.
  64. /// For example:<br/>
  65. /// <tt>extern int LinkMyCodeStub;</tt><br/>
  66. /// <tt>static IncludeFile LinkMyModule(&LinkMyCodeStub);</tt><br/>
  67. /// @brief Class to ensure linking of corresponding object file.
  68. struct IncludeFile {
  69. explicit IncludeFile(const void *);
  70. };
  71. }
  72. #endif