[llvm-commits] Include extern "C" ints to help registration global ctors

Scott Graham scott.llvm at h4ck3r.net
Wed Nov 12 10:06:36 PST 2008


Hi

This patch adds extern "C" ints to the .cpp files that use
RegisterTarget, as well as 2 files that use "Registrator"s. These are
to be used by the MSVC builds (separate patch by Óscar), as the Win32
linker does not include libs that are otherwise unreferenced, even if
global constructors in the lib have side-effects.

It seems this list wants patches inline, not attached? Apologies if
it's supposed to be the other way.

scott


Index: lib/Target/XCore/XCoreTargetMachine.cpp
===================================================================
--- lib/Target/XCore/XCoreTargetMachine.cpp	(revision 59091)
+++ lib/Target/XCore/XCoreTargetMachine.cpp	(working copy)
@@ -18,6 +18,13 @@
 #include "llvm/Target/TargetMachineRegistry.h"
 using namespace llvm;

+/// XCoreTargetMachineModule - Note that this is used on hosts that cannot link
+/// in a library unless there are references into the library.  In particular,
+/// it seems that it is not possible to get things to work on Win32 without
+/// this.  Though it is unused, do not remove it.
+extern "C" int XCoreTargetMachineModule;
+int XCoreTargetMachineModule = 0;
+
 namespace {
   // Register the target.
   RegisterTarget<XCoreTargetMachine> X("xcore", "  XCore");
Index: lib/Target/PIC16/PIC16TargetMachine.cpp
===================================================================
--- lib/Target/PIC16/PIC16TargetMachine.cpp	(revision 59091)
+++ lib/Target/PIC16/PIC16TargetMachine.cpp	(working copy)
@@ -21,6 +21,13 @@

 using namespace llvm;

+/// PIC16TargetMachineModule - Note that this is used on hosts that cannot link
+/// in a library unless there are references into the library.  In particular,
+/// it seems that it is not possible to get things to work on Win32 without
+/// this.  Though it is unused, do not remove it.
+extern "C" int PIC16TargetMachineModule;
+int PIC16TargetMachineModule = 0;
+
 namespace {
   // Register the targets
   RegisterTarget<PIC16TargetMachine> X("pic16", "PIC16 14-bit [experimental]");
Index: lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp
===================================================================
--- lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp	(revision 59091)
+++ lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp	(working copy)
@@ -41,3 +41,6 @@
     }
   } Registrator;
 }
+
+extern "C" int X86AsmPrinterForceLink;
+int X86AsmPrinterForceLink = 0;
Index: lib/Target/CBackend/CBackend.cpp
===================================================================
--- lib/Target/CBackend/CBackend.cpp	(revision 59091)
+++ lib/Target/CBackend/CBackend.cpp	(working copy)
@@ -48,6 +48,13 @@
 #include <sstream>
 using namespace llvm;

+/// CBackendTargetMachineModule - Note that this is used on hosts
that cannot link
+/// in a library unless there are references into the library.  In particular,
+/// it seems that it is not possible to get things to work on Win32 without
+/// this.  Though it is unused, do not remove it.
+extern "C" int CBackendTargetMachineModule;
+int CBackendTargetMachineModule = 0;
+
 // Register the target.
 static RegisterTarget<CTargetMachine> X("c", "C backend");

Index: lib/Target/CellSPU/SPUTargetMachine.cpp
===================================================================
--- lib/Target/CellSPU/SPUTargetMachine.cpp	(revision 59091)
+++ lib/Target/CellSPU/SPUTargetMachine.cpp	(working copy)
@@ -21,6 +21,13 @@

 using namespace llvm;

+/// CellSPUTargetMachineModule - Note that this is used on hosts that
cannot link
+/// in a library unless there are references into the library.  In particular,
+/// it seems that it is not possible to get things to work on Win32 without
+/// this.  Though it is unused, do not remove it.
+extern "C" int CellSPUTargetMachineModule;
+int CellSPUTargetMachineModule = 0;
+
 namespace {
   // Register the targets
   RegisterTarget<SPUTargetMachine>
Index: lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
===================================================================
--- lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp	(revision 59091)
+++ lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp	(working copy)
@@ -1112,3 +1112,7 @@
     }
   } Registrator;
 }
+
+extern "C" int PowerPCAsmPrinterForceLink;
+int PowerPCAsmPrinterForceLink = 0;
+
Index: lib/Target/PowerPC/PPCTargetMachine.cpp
===================================================================
--- lib/Target/PowerPC/PPCTargetMachine.cpp	(revision 59091)
+++ lib/Target/PowerPC/PPCTargetMachine.cpp	(working copy)
@@ -21,6 +21,13 @@
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;

+/// PowerPCTargetMachineModule - Note that this is used on hosts that
cannot link
+/// in a library unless there are references into the library.  In particular,
+/// it seems that it is not possible to get things to work on Win32 without
+/// this.  Though it is unused, do not remove it.
+extern "C" int PowerPCTargetMachineModule;
+int PowerPCTargetMachineModule = 0;
+
 // Register the targets
 static RegisterTarget<PPC32TargetMachine>
 X("ppc32", "PowerPC 32");
Index: lib/Target/ARM/ARMTargetMachine.cpp
===================================================================
--- lib/Target/ARM/ARMTargetMachine.cpp	(revision 59091)
+++ lib/Target/ARM/ARMTargetMachine.cpp	(working copy)
@@ -28,6 +28,13 @@
 static cl::opt<bool>
DisableIfConversion("disable-arm-if-conversion",cl::Hidden,
                               cl::desc("Disable if-conversion pass"));

+/// ARMTargetMachineModule - Note that this is used on hosts that cannot link
+/// in a library unless there are references into the library.  In particular,
+/// it seems that it is not possible to get things to work on Win32 without
+/// this.  Though it is unused, do not remove it.
+extern "C" int ARMTargetMachineModule;
+int ARMTargetMachineModule = 0;
+
 // Register the target.
 static RegisterTarget<ARMTargetMachine>   X("arm",   "ARM");
 static RegisterTarget<ThumbTargetMachine> Y("thumb", "Thumb");
Index: lib/Target/Alpha/AlphaTargetMachine.cpp
===================================================================
--- lib/Target/Alpha/AlphaTargetMachine.cpp	(revision 59091)
+++ lib/Target/Alpha/AlphaTargetMachine.cpp	(working copy)
@@ -21,6 +21,13 @@

 using namespace llvm;

+/// AlphaTargetMachineModule - Note that this is used on hosts that cannot link
+/// in a library unless there are references into the library.  In particular,
+/// it seems that it is not possible to get things to work on Win32 without
+/// this.  Though it is unused, do not remove it.
+extern "C" int AlphaTargetMachineModule;
+int AlphaTargetMachineModule = 0;
+
 // Register the targets
 static RegisterTarget<AlphaTargetMachine> X("alpha", "Alpha [experimental]");

Index: lib/Target/CppBackend/CPPBackend.cpp
===================================================================
--- lib/Target/CppBackend/CPPBackend.cpp	(revision 59091)
+++ lib/Target/CppBackend/CPPBackend.cpp	(working copy)
@@ -71,6 +71,13 @@
   cl::desc("Specify the name of the thing to generate"),
   cl::init("!bad!"));

+/// CppBackendTargetMachineModule - Note that this is used on hosts
that cannot link
+/// in a library unless there are references into the library.  In particular,
+/// it seems that it is not possible to get things to work on Win32 without
+/// this.  Though it is unused, do not remove it.
+extern "C" int CppBackendTargetMachineModule;
+int CppBackendTargetMachineModule = 0;
+
 // Register the target.
 static RegisterTarget<CPPTargetMachine> X("cpp", "C++ backend");

Index: lib/Target/MSIL/MSILWriter.cpp
===================================================================
--- lib/Target/MSIL/MSILWriter.cpp	(revision 59091)
+++ lib/Target/MSIL/MSILWriter.cpp	(working copy)
@@ -44,6 +44,12 @@
   };
 }

+/// MSILTargetMachineModule - Note that this is used on hosts that cannot link
+/// in a library unless there are references into the library.  In particular,
+/// it seems that it is not possible to get things to work on Win32 without
+/// this.  Though it is unused, do not remove it.
+extern "C" int MSILTargetMachineModule;
+int MSILTargetMachineModule = 0;

 static RegisterTarget<MSILTarget> X("msil", "MSIL backend");

Index: lib/Target/Sparc/SparcTargetMachine.cpp
===================================================================
--- lib/Target/Sparc/SparcTargetMachine.cpp	(revision 59091)
+++ lib/Target/Sparc/SparcTargetMachine.cpp	(working copy)
@@ -18,6 +18,13 @@
 #include "llvm/Target/TargetMachineRegistry.h"
 using namespace llvm;

+/// SparcTargetMachineModule - Note that this is used on hosts that cannot link
+/// in a library unless there are references into the library.  In particular,
+/// it seems that it is not possible to get things to work on Win32 without
+/// this.  Though it is unused, do not remove it.
+extern "C" int SparcTargetMachineModule;
+int SparcTargetMachineModule = 0;
+
 // Register the target.
 static RegisterTarget<SparcTargetMachine> X("sparc", "SPARC");

Index: lib/Target/Mips/MipsTargetMachine.cpp
===================================================================
--- lib/Target/Mips/MipsTargetMachine.cpp	(revision 59091)
+++ lib/Target/Mips/MipsTargetMachine.cpp	(working copy)
@@ -19,6 +19,13 @@
 #include "llvm/Target/TargetMachineRegistry.h"
 using namespace llvm;

+/// MipsTargetMachineModule - Note that this is used on hosts that cannot link
+/// in a library unless there are references into the library.  In particular,
+/// it seems that it is not possible to get things to work on Win32 without
+/// this.  Though it is unused, do not remove it.
+extern "C" int MipsTargetMachineModule;
+int MipsTargetMachineModule = 0;
+
 // Register the target.
 static RegisterTarget<MipsTargetMachine>    X("mips", "Mips");
 static RegisterTarget<MipselTargetMachine>  Y("mipsel", "Mipsel");




More information about the llvm-commits mailing list