summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-06-07 20:35:46 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-06-07 20:35:46 +0000
commit1707fcb7dbbfaa59f3144fb8629f273ae8ab73ee (patch)
treecd4bc7304aaf6ea688d365665d545c67314507a9
parent54cb2d853318496b9412bca7a1ed542934a0a509 (diff)
downloadbcm5719-llvm-1707fcb7dbbfaa59f3144fb8629f273ae8ab73ee.tar.gz
bcm5719-llvm-1707fcb7dbbfaa59f3144fb8629f273ae8ab73ee.zip
For PR780:
This change was suggested by Chris so that we can select an alternate (or even no-op) implementation of the link assurance. I'm committing this for your review, Chris. If the names and definitions are okay, I'll adjust all the .h and .cpp files in a later patch. llvm-svn: 28712
-rw-r--r--llvm/include/llvm/Support/IncludeFile.h39
-rw-r--r--llvm/include/llvm/System/IncludeFile.h39
2 files changed, 62 insertions, 16 deletions
diff --git a/llvm/include/llvm/Support/IncludeFile.h b/llvm/include/llvm/Support/IncludeFile.h
index 2e4f12dbbf8..8e96f7571f6 100644
--- a/llvm/include/llvm/Support/IncludeFile.h
+++ b/llvm/include/llvm/Support/IncludeFile.h
@@ -7,12 +7,39 @@
//
//===----------------------------------------------------------------------===//
//
-// This file defines the IncludeFile class.
+// This file defines the FORCE_DEFINING_FILE_TO_BE_LINKED and DEFINE_FILE_FOR
+// macros.
//
//===----------------------------------------------------------------------===//
-/// This class is used as a facility to make sure that the implementation of a
-/// header file is included into a tool that uses the header. This is solely
+#ifndef LLVM_SUPPORT_INCLUDEFILE_H
+#define LLVM_SUPPORT_INCLUDEFILE_H
+
+/// This macro is the public interface that IncludeFile.h exports. This gives
+/// us the option to implement the "link the definition" capability in any
+/// manner that we choose. All header files that depend on a specific .cpp
+/// file being linked at run time should use this macro instead of the
+/// IncludeFile class directly.
+///
+/// For example, foo.h would use:<br/>
+/// <tt>FORCE_DEFINING_FILE_TO_BE_LINKED(foo)</tt><br/>
+///
+/// And, foo.cp would use:<br/>
+/// <tt>DEFINING_FILE_FOR(foo)</tt><br/>
+#define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \
+ extern char name ## LinkVar; \
+ static IncludeFile name ## LinkObj ( &name ## LinkVar )
+
+/// This macro is the counterpart to FORCE_DEFINING_FILE_TO_BE_LINKED. It should
+/// be used in a .cpp file to define the name referenced in a header file that
+/// will cause linkage of the .cpp file. It should only be used at extern level.
+#define DEFINING_FILE_FOR(name) char name
+
+namespace llvm {
+
+/// This class is used in the implementation of FORCE_DEFINING_FILE_TO_BE_LINKED
+/// macro to make sure that the implementation of a header file is included
+/// into a tool that uses the header. This is solely
/// to overcome problems linking .a files and not getting the implementation
/// of compilation units we need. This is commonly an issue with the various
/// Passes but also occurs elsewhere in LLVM. We like to use .a files because
@@ -27,14 +54,10 @@
/// <tt>extern int LinkMyCodeStub;</tt><br/>
/// <tt>static IncludeFile LinkMyModule(&LinkMyCodeStub);</tt><br/>
/// @brief Class to ensure linking of corresponding object file.
-
-#ifndef LLVM_SUPPORT_INCLUDEFILE_H
-#define LLVM_SUPPORT_INCLUDEFILE_H
-
-namespace llvm {
struct IncludeFile {
IncludeFile(void *);
};
+
}
#endif
diff --git a/llvm/include/llvm/System/IncludeFile.h b/llvm/include/llvm/System/IncludeFile.h
index 2e4f12dbbf8..8e96f7571f6 100644
--- a/llvm/include/llvm/System/IncludeFile.h
+++ b/llvm/include/llvm/System/IncludeFile.h
@@ -7,12 +7,39 @@
//
//===----------------------------------------------------------------------===//
//
-// This file defines the IncludeFile class.
+// This file defines the FORCE_DEFINING_FILE_TO_BE_LINKED and DEFINE_FILE_FOR
+// macros.
//
//===----------------------------------------------------------------------===//
-/// This class is used as a facility to make sure that the implementation of a
-/// header file is included into a tool that uses the header. This is solely
+#ifndef LLVM_SUPPORT_INCLUDEFILE_H
+#define LLVM_SUPPORT_INCLUDEFILE_H
+
+/// This macro is the public interface that IncludeFile.h exports. This gives
+/// us the option to implement the "link the definition" capability in any
+/// manner that we choose. All header files that depend on a specific .cpp
+/// file being linked at run time should use this macro instead of the
+/// IncludeFile class directly.
+///
+/// For example, foo.h would use:<br/>
+/// <tt>FORCE_DEFINING_FILE_TO_BE_LINKED(foo)</tt><br/>
+///
+/// And, foo.cp would use:<br/>
+/// <tt>DEFINING_FILE_FOR(foo)</tt><br/>
+#define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \
+ extern char name ## LinkVar; \
+ static IncludeFile name ## LinkObj ( &name ## LinkVar )
+
+/// This macro is the counterpart to FORCE_DEFINING_FILE_TO_BE_LINKED. It should
+/// be used in a .cpp file to define the name referenced in a header file that
+/// will cause linkage of the .cpp file. It should only be used at extern level.
+#define DEFINING_FILE_FOR(name) char name
+
+namespace llvm {
+
+/// This class is used in the implementation of FORCE_DEFINING_FILE_TO_BE_LINKED
+/// macro to make sure that the implementation of a header file is included
+/// into a tool that uses the header. This is solely
/// to overcome problems linking .a files and not getting the implementation
/// of compilation units we need. This is commonly an issue with the various
/// Passes but also occurs elsewhere in LLVM. We like to use .a files because
@@ -27,14 +54,10 @@
/// <tt>extern int LinkMyCodeStub;</tt><br/>
/// <tt>static IncludeFile LinkMyModule(&LinkMyCodeStub);</tt><br/>
/// @brief Class to ensure linking of corresponding object file.
-
-#ifndef LLVM_SUPPORT_INCLUDEFILE_H
-#define LLVM_SUPPORT_INCLUDEFILE_H
-
-namespace llvm {
struct IncludeFile {
IncludeFile(void *);
};
+
}
#endif
OpenPOWER on IntegriCloud