mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-05 12:31:33 +00:00
Make llvmc work again.
Chris recently broke llvmc with his Makefile changes (r75379). That patch made the global change .o -> .a, which caused built-in llvmc plugins to stop working since plugin initialization in llvmc is based on static variables not referenced from the main executable. This patch implements auto-generated forced references to the plugin libraries. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74000 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
06509db630
commit
d80d8690af
@ -198,6 +198,7 @@ install-bytecode:: install-bytecode-local
|
|||||||
ifdef LLVMC_PLUGIN
|
ifdef LLVMC_PLUGIN
|
||||||
|
|
||||||
LIBRARYNAME := $(patsubst %,plugin_llvmc_%,$(LLVMC_PLUGIN))
|
LIBRARYNAME := $(patsubst %,plugin_llvmc_%,$(LLVMC_PLUGIN))
|
||||||
|
CPP.Flags += -DLLVMC_PLUGIN_NAME=$(LLVMC_PLUGIN)
|
||||||
REQUIRES_EH := 1
|
REQUIRES_EH := 1
|
||||||
|
|
||||||
# Build a dynamic library if the user runs `make` directly from the plugin
|
# Build a dynamic library if the user runs `make` directly from the plugin
|
||||||
|
82
include/llvm/CompilerDriver/ForceLinkage.h
Normal file
82
include/llvm/CompilerDriver/ForceLinkage.h
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
//===--- ForceLinkage.h - The LLVM Compiler Driver --------------*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open
|
||||||
|
// Source License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// A bit of preprocessor magic to force references to static libraries. Needed
|
||||||
|
// because plugin initialization is done via static variables.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_H
|
||||||
|
#define LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_H
|
||||||
|
|
||||||
|
#include "llvm/CompilerDriver/ForceLinkageMacros.h"
|
||||||
|
|
||||||
|
namespace llvmc {
|
||||||
|
|
||||||
|
// Declare all ForceLinkage$(PluginName) functions.
|
||||||
|
|
||||||
|
#ifdef LLVMC_BUILTIN_PLUGIN_1
|
||||||
|
LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LLVMC_BUILTIN_PLUGIN_2
|
||||||
|
LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_2);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LLVMC_BUILTIN_PLUGIN_3
|
||||||
|
LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_3);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LLVMC_BUILTIN_PLUGIN_4
|
||||||
|
LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_4);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LLVMC_BUILTIN_PLUGIN_5
|
||||||
|
LLVMC_FORCE_LINKAGE_DECL(LLVMC_BUILTIN_PLUGIN_5);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace force_linkage {
|
||||||
|
|
||||||
|
struct LinkageForcer {
|
||||||
|
|
||||||
|
LinkageForcer() {
|
||||||
|
|
||||||
|
// Call all ForceLinkage$(PluginName) functions.
|
||||||
|
#ifdef LLVMC_BUILTIN_PLUGIN_1
|
||||||
|
LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LLVMC_BUILTIN_PLUGIN_2
|
||||||
|
LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_2);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LLVMC_BUILTIN_PLUGIN_3
|
||||||
|
LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_3);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LLVMC_BUILTIN_PLUGIN_4
|
||||||
|
LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_4);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LLVMC_BUILTIN_PLUGIN_5
|
||||||
|
LLVMC_FORCE_LINKAGE_CALL(LLVMC_BUILTIN_PLUGIN_5);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // End namespace force_linkage.
|
||||||
|
|
||||||
|
// The only externally used bit.
|
||||||
|
void ForceLinkage() {
|
||||||
|
force_linkage::LinkageForcer dummy;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // End namespace llvmc.
|
||||||
|
|
||||||
|
#endif // LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_H
|
29
include/llvm/CompilerDriver/ForceLinkageMacros.h
Normal file
29
include/llvm/CompilerDriver/ForceLinkageMacros.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
//===--- ForceLinkageMacros.h - The LLVM Compiler Driver --------*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open
|
||||||
|
// Source License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// Preprocessor magic that forces references to static libraries - common
|
||||||
|
// macros used by both driver and plugins.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_MACROS_H
|
||||||
|
#define LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_MACROS_H
|
||||||
|
|
||||||
|
#define LLVMC_FORCE_LINKAGE_PREFIX(PluginName) ForceLinkage ## PluginName
|
||||||
|
|
||||||
|
#define LLVMC_FORCE_LINKAGE_FUN(PluginName) \
|
||||||
|
LLVMC_FORCE_LINKAGE_PREFIX(PluginName)
|
||||||
|
|
||||||
|
#define LLVMC_FORCE_LINKAGE_DECL(PluginName) \
|
||||||
|
void LLVMC_FORCE_LINKAGE_FUN(PluginName) ()
|
||||||
|
|
||||||
|
#define LLVMC_FORCE_LINKAGE_CALL(PluginName) \
|
||||||
|
LLVMC_FORCE_LINKAGE_FUN(PluginName) ()
|
||||||
|
|
||||||
|
#endif // LLVM_INCLUDE_COMPILER_DRIVER_FORCE_LINKAGE_MACROS_H
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "llvm/CompilerDriver/CompilationGraph.h"
|
#include "llvm/CompilerDriver/CompilationGraph.h"
|
||||||
#include "llvm/CompilerDriver/Error.h"
|
#include "llvm/CompilerDriver/Error.h"
|
||||||
|
#include "llvm/CompilerDriver/ForceLinkage.h"
|
||||||
#include "llvm/CompilerDriver/Plugin.h"
|
#include "llvm/CompilerDriver/Plugin.h"
|
||||||
|
|
||||||
#include "llvm/System/Path.h"
|
#include "llvm/System/Path.h"
|
||||||
@ -85,6 +86,8 @@ namespace {
|
|||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
try {
|
try {
|
||||||
|
ForceLinkage();
|
||||||
|
|
||||||
LanguageMap langMap;
|
LanguageMap langMap;
|
||||||
CompilationGraph graph;
|
CompilationGraph graph;
|
||||||
|
|
||||||
|
@ -8,15 +8,46 @@
|
|||||||
##===----------------------------------------------------------------------===##
|
##===----------------------------------------------------------------------===##
|
||||||
|
|
||||||
LEVEL = ../../..
|
LEVEL = ../../..
|
||||||
|
include $(LEVEL)/Makefile.config
|
||||||
|
|
||||||
TOOLNAME = $(LLVMC_BASED_DRIVER_NAME)
|
TOOLNAME = $(LLVMC_BASED_DRIVER_NAME)
|
||||||
LLVMLIBS = CompilerDriver.a
|
LLVMLIBS = CompilerDriver.a
|
||||||
|
|
||||||
ifneq ($(LLVMC_BUILTIN_PLUGINS),)
|
|
||||||
USEDLIBS += $(patsubst %,plugin_llvmc_%.a,$(LLVMC_BUILTIN_PLUGINS))
|
|
||||||
endif
|
|
||||||
|
|
||||||
LINK_COMPONENTS = support system
|
LINK_COMPONENTS = support system
|
||||||
REQUIRES_EH := 1
|
REQUIRES_EH := 1
|
||||||
|
|
||||||
|
# Preprocessor magic that generates references to static variables in built-in
|
||||||
|
# plugins.
|
||||||
|
# TODO: Move this to Makefile.rules? (also used by examples/{Skeleton, mcc16})
|
||||||
|
ifneq ($(LLVMC_BUILTIN_PLUGINS),)
|
||||||
|
|
||||||
|
USEDLIBS += $(patsubst %,plugin_llvmc_%.a,$(LLVMC_BUILTIN_PLUGINS))
|
||||||
|
|
||||||
|
LLVMC_BUILTIN_PLUGIN_1 = $(word 1, $(LLVMC_BUILTIN_PLUGINS))
|
||||||
|
LLVMC_BUILTIN_PLUGIN_2 = $(word 2, $(LLVMC_BUILTIN_PLUGINS))
|
||||||
|
LLVMC_BUILTIN_PLUGIN_3 = $(word 3, $(LLVMC_BUILTIN_PLUGINS))
|
||||||
|
LLVMC_BUILTIN_PLUGIN_4 = $(word 4, $(LLVMC_BUILTIN_PLUGINS))
|
||||||
|
LLVMC_BUILTIN_PLUGIN_5 = $(word 5, $(LLVMC_BUILTIN_PLUGINS))
|
||||||
|
|
||||||
|
ifneq ($(LLVMC_BUILTIN_PLUGIN_1),)
|
||||||
|
CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_1=$(LLVMC_BUILTIN_PLUGIN_1)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifneq ($(LLVMC_BUILTIN_PLUGIN_2),)
|
||||||
|
CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_2=$(LLVMC_BUILTIN_PLUGIN_2)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifneq ($(LLVMC_BUILTIN_PLUGIN_3),)
|
||||||
|
CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_3=$(LLVMC_BUILTIN_PLUGIN_3)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifneq ($(LLVMC_BUILTIN_PLUGIN_4),)
|
||||||
|
CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_4=$(LLVMC_BUILTIN_PLUGIN_4)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifneq ($(LLVMC_BUILTIN_PLUGIN_5),)
|
||||||
|
CPP.Flags += -DLLVMC_BUILTIN_PLUGIN_5=$(LLVMC_BUILTIN_PLUGIN_5)
|
||||||
|
endif
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
include $(LEVEL)/Makefile.common
|
include $(LEVEL)/Makefile.common
|
||||||
|
@ -1984,6 +1984,7 @@ void EmitRegisterPlugin(int Priority, std::ostream& O) {
|
|||||||
/// additional declarations.
|
/// additional declarations.
|
||||||
void EmitIncludes(std::ostream& O) {
|
void EmitIncludes(std::ostream& O) {
|
||||||
O << "#include \"llvm/CompilerDriver/CompilationGraph.h\"\n"
|
O << "#include \"llvm/CompilerDriver/CompilationGraph.h\"\n"
|
||||||
|
<< "#include \"llvm/CompilerDriver/ForceLinkageMacros.h\"\n"
|
||||||
<< "#include \"llvm/CompilerDriver/Plugin.h\"\n"
|
<< "#include \"llvm/CompilerDriver/Plugin.h\"\n"
|
||||||
<< "#include \"llvm/CompilerDriver/Tool.h\"\n\n"
|
<< "#include \"llvm/CompilerDriver/Tool.h\"\n\n"
|
||||||
|
|
||||||
@ -2106,7 +2107,13 @@ void EmitPluginCode(const PluginData& Data, std::ostream& O) {
|
|||||||
// Emit code for plugin registration.
|
// Emit code for plugin registration.
|
||||||
EmitRegisterPlugin(Data.Priority, O);
|
EmitRegisterPlugin(Data.Priority, O);
|
||||||
|
|
||||||
O << "} // End anonymous namespace.\n";
|
O << "} // End anonymous namespace.\n\n";
|
||||||
|
|
||||||
|
// Force linkage magic.
|
||||||
|
O << "namespace llvmc {\n";
|
||||||
|
O << "LLVMC_FORCE_LINKAGE_DECL(LLVMC_PLUGIN_NAME) {}\n";
|
||||||
|
O << "}\n";
|
||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user