[llvm-commits] [dragonegg] r154925 - in /dragonegg/trunk: Makefile include/dragonegg/Internals.h include/x86/dragonegg/Target.h src/Aliasing.cpp src/Backend.cpp src/Cache.cpp src/Constants.cpp src/Convert.cpp src/Debug.cpp src/DefaultABI.cpp src/Trees.cpp src/Types.cpp src/arm/Target.cpp src/x86/ABIHack.inc src/x86/Target.cpp utils/empty.c utils/lang_plugin.c
Duncan Sands
baldrick at free.fr
Tue Apr 17 06:04:14 PDT 2012
Author: baldrick
Date: Tue Apr 17 08:04:14 2012
New Revision: 154925
URL: http://llvm.org/viewvc/llvm-project?rev=154925&view=rev
Log:
GCC-4.7 may be built with either a C or a C++ compiler. If it was with a C
compiler then symbols we access in it need to be wrapped in "extern C",
otherwise they need to be mangled so must not be wrapped in "extern C".
Detect how gcc-4.7 was built via a horrible hack and build the plugin
appropriately.
Added:
dragonegg/trunk/utils/empty.c
dragonegg/trunk/utils/lang_plugin.c
Modified:
dragonegg/trunk/Makefile
dragonegg/trunk/include/dragonegg/Internals.h
dragonegg/trunk/include/x86/dragonegg/Target.h
dragonegg/trunk/src/Aliasing.cpp
dragonegg/trunk/src/Backend.cpp
dragonegg/trunk/src/Cache.cpp
dragonegg/trunk/src/Constants.cpp
dragonegg/trunk/src/Convert.cpp
dragonegg/trunk/src/Debug.cpp
dragonegg/trunk/src/DefaultABI.cpp
dragonegg/trunk/src/Trees.cpp
dragonegg/trunk/src/Types.cpp
dragonegg/trunk/src/arm/Target.cpp
dragonegg/trunk/src/x86/ABIHack.inc
dragonegg/trunk/src/x86/Target.cpp
Modified: dragonegg/trunk/Makefile
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/Makefile?rev=154925&r1=154924&r2=154925&view=diff
==============================================================================
--- dragonegg/trunk/Makefile (original)
+++ dragonegg/trunk/Makefile Tue Apr 17 08:04:14 2012
@@ -40,15 +40,17 @@
LOADABLE_MODULE_OPTIONS=-shared -Wl,-O1 -Wl,--version-script=$(TOP_DIR)/exports.map
endif
-GCC_PLUGIN_DIR:=$(shell $(GCC) -print-file-name=plugin)
+LLVM_VERSION:=$(shell $(LLVM_CONFIG) --version)
+
GCC_VERSION:=$(shell $(GCC) -dumpversion).0
-GCC_MAJOR=$(word 1, $(subst ., ,$(GCC_VERSION)))
-GCC_MINOR=$(word 2, $(subst ., ,$(GCC_VERSION)))
-GCC_MICRO=$(word 3, $(subst ., ,$(GCC_VERSION)))
-GCC_LANGUAGES=$(shell $(GCC) -v 2>&1 | grep '^Configured with:' | sed 's/^.*--enable-languages=\([^ ]*\).*/\1/')
-TARGET_TRIPLE:=$(shell $(GCC) -dumpmachine)
+GCC_MAJOR:=$(word 1, $(subst ., ,$(GCC_VERSION)))
+GCC_MINOR:=$(word 2, $(subst ., ,$(GCC_VERSION)))
+GCC_MICRO:=$(word 3, $(subst ., ,$(GCC_VERSION)))
-LLVM_VERSION:=$(shell $(LLVM_CONFIG) --version)
+GCC_LANGUAGES:=$(shell $(GCC) -v 2>&1 | grep '^Configured with:' | sed 's/^.*--enable-languages=\([^ ]*\).*/\1/')
+GCC_PLUGIN_DIR:=$(shell $(GCC) -print-file-name=plugin)
+
+TARGET_TRIPLE:=$(shell $(GCC) -dumpmachine)
PLUGIN=dragonegg.so
PLUGIN_OBJECTS=Aliasing.o Backend.o Cache.o Constants.o Convert.o Debug.o \
@@ -66,7 +68,7 @@
-MD -MP \
-DIN_GCC -DLLVM_VERSION=\"$(LLVM_VERSION)\" \
-DGCC_MAJOR=$(GCC_MAJOR) -DGCC_MINOR=$(GCC_MINOR) \
- -DGCC_MICRO=$(GCC_MICRO) \
+ -DGCC_MICRO=$(GCC_MICRO) -DGCC_LANG=\"$(GCC_LANG)\" \
-I$(INCLUDE_DIR) -isystem$(GCC_PLUGIN_DIR)/include
ifdef DISABLE_VERSION_CHECK
CPP_OPTIONS+=-DDISABLE_VERSION_CHECK
@@ -91,6 +93,49 @@
default: $(PLUGIN)
+
+# gcc-4.6 and earlier are built as C, gcc-4.8 and later are built as C++, while
+# gcc-4.7 may be built as C or as C++. The plugin accesses symbols inside gcc
+# so needs to know if they are mangled or not. Determine the gcc build language
+# and store it in GCC_LANG.
+
+GCC_LANG_PLUGIN:=lang_plugin.so
+GCC_LANG_TARGET:=
+ifeq ($(GCC_MAJOR),4)
+
+ifeq ($(GCC_MINOR),5)
+# gcc-4.5
+GCC_LANG:="C"
+else ifeq ($(GCC_MINOR),6)
+# gcc-4.6
+GCC_LANG:="C"
+else ifeq ($(GCC_MINOR),7)
+# gcc-4.7, may have been built as C or C++
+GCC_LANG_TARGET:=check_build_language
+
+$(GCC_LANG_PLUGIN): $(TOP_DIR)/utils/lang_plugin.c
+ @echo Compiling utils/$(<F)
+ $(QUIET)$(CC) -o $@ $< $(LOADABLE_MODULE_OPTIONS) \
+ -I$(GCC_PLUGIN_DIR)/include
+
+# Try to load a simple plugin that attempts to use a non-mangled symbol
+# from gcc. If it works then gcc was built as C. Otherwise either gcc
+# was built as C++ (or something went wrong with the test).
+check_build_language:: $(GCC_LANG_PLUGIN)
+ $(eval GCC_LANG := $(shell $(GCC) -fplugin=./$(GCC_LANG_PLUGIN) -S \
+ utils/empty.c 2> /dev/null && echo "C" || echo "C++"))
+ @echo "GCC was built as $(GCC_LANG)"
+else
+# gcc-4.8 and later
+GCC_LANG:="C++"
+endif
+
+else
+# gcc-5.0 and later
+GCC_LANG:="C++"
+endif
+
+
$(TARGET_UTIL_OBJECTS): %.o : $(TOP_DIR)/utils/%.cpp
@echo Compiling utils/$*.cpp
$(QUIET)$(CXX) -c -DTARGET_TRIPLE=\"$(TARGET_TRIPLE)\" \
@@ -101,7 +146,7 @@
$(QUIET)$(CXX) -o $@ $^ $(shell $(LLVM_CONFIG) --libs support) \
$(LD_OPTIONS)
-%.o : $(SRC_DIR)/%.cpp $(TARGET_UTIL)
+%.o : $(SRC_DIR)/%.cpp $(GCC_LANG_TARGET) $(TARGET_UTIL)
@echo Compiling $*.cpp
$(QUIET)$(CXX) -c $(TARGET_HEADERS) $(CPP_OPTIONS) $(CXXFLAGS) $<
@@ -142,7 +187,8 @@
check:: check-validator check-compilator
clean::
- $(QUIET)rm -f *.o *.d $(PLUGIN) $(TARGET_UTIL) $(LIT_SITE_CONFIG)
+ $(QUIET)rm -f *.o *.d $(GCC_LANG_PLUGIN) $(PLUGIN) $(TARGET_UTIL) \
+ $(LIT_SITE_CONFIG)
-include $(ALL_OBJECTS:.o=.d)
Modified: dragonegg/trunk/include/dragonegg/Internals.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/include/dragonegg/Internals.h?rev=154925&r1=154924&r2=154925&view=diff
==============================================================================
--- dragonegg/trunk/include/dragonegg/Internals.h (original)
+++ dragonegg/trunk/include/dragonegg/Internals.h Tue Apr 17 08:04:14 2012
@@ -37,9 +37,8 @@
union gimple_statement_d;
union tree_node;
-extern "C" {
+extern GCC_LANG {
extern void debug_gimple_stmt(union gimple_statement_d *);
-extern void debug_tree(union tree_node *);
}
namespace llvm {
Modified: dragonegg/trunk/include/x86/dragonegg/Target.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/include/x86/dragonegg/Target.h?rev=154925&r1=154924&r2=154925&view=diff
==============================================================================
--- dragonegg/trunk/include/x86/dragonegg/Target.h (original)
+++ dragonegg/trunk/include/x86/dragonegg/Target.h Tue Apr 17 08:04:14 2012
@@ -46,7 +46,7 @@
`inreg` parameter attribute */
#define LLVM_TARGET_ENABLE_REGPARM
-extern "C" int ix86_regparm;
+extern GCC_LANG int ix86_regparm;
#define LLVM_TARGET_INIT_REGPARM(local_regparm, local_fp_regparm, type) \
{ \
Modified: dragonegg/trunk/src/Aliasing.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Aliasing.cpp?rev=154925&r1=154924&r2=154925&view=diff
==============================================================================
--- dragonegg/trunk/src/Aliasing.cpp (original)
+++ dragonegg/trunk/src/Aliasing.cpp Tue Apr 17 08:04:14 2012
@@ -34,7 +34,7 @@
#include <map>
// GCC headers
-extern "C" {
+extern GCC_LANG {
#include "config.h"
// Stop GCC declaring 'getopt' as it can clash with the system's declaration.
#undef HAVE_DECL_GETOPT
Modified: dragonegg/trunk/src/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Backend.cpp?rev=154925&r1=154924&r2=154925&view=diff
==============================================================================
--- dragonegg/trunk/src/Backend.cpp (original)
+++ dragonegg/trunk/src/Backend.cpp Tue Apr 17 08:04:14 2012
@@ -50,7 +50,7 @@
#include <gmp.h>
// GCC headers
-extern "C" {
+extern GCC_LANG {
#include "config.h"
// Stop GCC declaring 'getopt' as it can clash with the system's declaration.
#undef HAVE_DECL_GETOPT
@@ -85,7 +85,7 @@
#endif
// TODO: In GCC, add targhooks.h to the list of plugin headers and remove this.
-extern "C" tree default_mangle_decl_assembler_name (tree, tree);
+extern GCC_LANG tree default_mangle_decl_assembler_name (tree, tree);
// Non-zero if libcalls should not be simplified.
int flag_no_simplify_libcalls;
@@ -2284,12 +2284,14 @@
pass_info.pos_op = PASS_POS_REPLACE;
register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &pass_info);
+#if (GCC_MINOR < 7)
// Turn off pass_ipa_type_escape.
pass_info.pass = &pass_simple_ipa_null.pass;
pass_info.reference_pass_name = "type-escape-var";
pass_info.ref_pass_instance_number = 0;
pass_info.pos_op = PASS_POS_REPLACE;
register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &pass_info);
+#endif
// Turn off pass_ipa_pta.
pass_info.pass = &pass_simple_ipa_null.pass;
@@ -2298,12 +2300,14 @@
pass_info.pos_op = PASS_POS_REPLACE;
register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &pass_info);
+#if (GCC_MINOR < 7)
// Turn off pass_ipa_struct_reorg.
pass_info.pass = &pass_simple_ipa_null.pass;
pass_info.reference_pass_name = "ipa_struct_reorg";
pass_info.ref_pass_instance_number = 0;
pass_info.pos_op = PASS_POS_REPLACE;
register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &pass_info);
+#endif
}
// Replace the LTO gimple pass with a pass that converts same-body aliases and
Modified: dragonegg/trunk/src/Cache.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Cache.cpp?rev=154925&r1=154924&r2=154925&view=diff
==============================================================================
--- dragonegg/trunk/src/Cache.cpp (original)
+++ dragonegg/trunk/src/Cache.cpp Tue Apr 17 08:04:14 2012
@@ -34,7 +34,7 @@
#include <gmp.h>
// GCC headers
-extern "C" {
+extern GCC_LANG {
#include "config.h"
// Stop GCC declaring 'getopt' as it can clash with the system's declaration.
#undef HAVE_DECL_GETOPT
@@ -111,7 +111,7 @@
// Include the garbage collector header.
-extern "C" {
+extern GCC_LANG {
#if (GCC_MINOR > 5)
#include "dragonegg/gt-cache-4.6.h"
#else
Modified: dragonegg/trunk/src/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Constants.cpp?rev=154925&r1=154924&r2=154925&view=diff
==============================================================================
--- dragonegg/trunk/src/Constants.cpp (original)
+++ dragonegg/trunk/src/Constants.cpp Tue Apr 17 08:04:14 2012
@@ -38,7 +38,7 @@
#include <gmp.h>
// GCC headers
-extern "C" {
+extern GCC_LANG {
#include "config.h"
// Stop GCC declaring 'getopt' as it can clash with the system's declaration.
#undef HAVE_DECL_GETOPT
Modified: dragonegg/trunk/src/Convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Convert.cpp?rev=154925&r1=154924&r2=154925&view=diff
==============================================================================
--- dragonegg/trunk/src/Convert.cpp (original)
+++ dragonegg/trunk/src/Convert.cpp Tue Apr 17 08:04:14 2012
@@ -40,7 +40,7 @@
#include <gmp.h>
// GCC headers
-extern "C" {
+extern GCC_LANG {
#include "config.h"
// Stop GCC declaring 'getopt' as it can clash with the system's declaration.
#undef HAVE_DECL_GETOPT
Modified: dragonegg/trunk/src/Debug.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Debug.cpp?rev=154925&r1=154924&r2=154925&view=diff
==============================================================================
--- dragonegg/trunk/src/Debug.cpp (original)
+++ dragonegg/trunk/src/Debug.cpp Tue Apr 17 08:04:14 2012
@@ -30,7 +30,7 @@
#include <gmp.h>
// GCC headers
-extern "C" {
+extern GCC_LANG {
#include "config.h"
// Stop GCC declaring 'getopt' as it can clash with the system's declaration.
#undef HAVE_DECL_GETOPT
Modified: dragonegg/trunk/src/DefaultABI.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/DefaultABI.cpp?rev=154925&r1=154924&r2=154925&view=diff
==============================================================================
--- dragonegg/trunk/src/DefaultABI.cpp (original)
+++ dragonegg/trunk/src/DefaultABI.cpp Tue Apr 17 08:04:14 2012
@@ -27,7 +27,7 @@
#include <gmp.h>
// GCC headers
-extern "C" {
+extern GCC_LANG {
#include "config.h"
// Stop GCC declaring 'getopt' as it can clash with the system's declaration.
#undef HAVE_DECL_GETOPT
Modified: dragonegg/trunk/src/Trees.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Trees.cpp?rev=154925&r1=154924&r2=154925&view=diff
==============================================================================
--- dragonegg/trunk/src/Trees.cpp (original)
+++ dragonegg/trunk/src/Trees.cpp Tue Apr 17 08:04:14 2012
@@ -28,7 +28,7 @@
#include <gmp.h>
// GCC headers
-extern "C" {
+extern GCC_LANG {
#include "config.h"
// Stop GCC declaring 'getopt' as it can clash with the system's declaration.
#undef HAVE_DECL_GETOPT
Modified: dragonegg/trunk/src/Types.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Types.cpp?rev=154925&r1=154924&r2=154925&view=diff
==============================================================================
--- dragonegg/trunk/src/Types.cpp (original)
+++ dragonegg/trunk/src/Types.cpp Tue Apr 17 08:04:14 2012
@@ -35,7 +35,7 @@
#include <map>
// GCC headers
-extern "C" {
+extern GCC_LANG {
#include "config.h"
// Stop GCC declaring 'getopt' as it can clash with the system's declaration.
#undef HAVE_DECL_GETOPT
Modified: dragonegg/trunk/src/arm/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/arm/Target.cpp?rev=154925&r1=154924&r2=154925&view=diff
==============================================================================
--- dragonegg/trunk/src/arm/Target.cpp (original)
+++ dragonegg/trunk/src/arm/Target.cpp Tue Apr 17 08:04:14 2012
@@ -32,7 +32,7 @@
#include <gmp.h>
// GCC headers
-extern "C" {
+extern GCC_LANG {
#include "config.h"
// Stop GCC declaring 'getopt' as it can clash with the system's declaration.
#undef HAVE_DECL_GETOPT
Modified: dragonegg/trunk/src/x86/ABIHack.inc
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/x86/ABIHack.inc?rev=154925&r1=154924&r2=154925&view=diff
==============================================================================
--- dragonegg/trunk/src/x86/ABIHack.inc (original)
+++ dragonegg/trunk/src/x86/ABIHack.inc Tue Apr 17 08:04:14 2012
@@ -25,7 +25,7 @@
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
-extern "C" {
+extern GCC_LANG {
#include "config.h"
#include "system.h"
#include "coretypes.h"
Modified: dragonegg/trunk/src/x86/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/x86/Target.cpp?rev=154925&r1=154924&r2=154925&view=diff
==============================================================================
--- dragonegg/trunk/src/x86/Target.cpp (original)
+++ dragonegg/trunk/src/x86/Target.cpp Tue Apr 17 08:04:14 2012
@@ -31,7 +31,7 @@
#include <gmp.h>
// GCC headers
-extern "C" {
+extern GCC_LANG {
#include "config.h"
// Stop GCC declaring 'getopt' as it can clash with the system's declaration.
#undef HAVE_DECL_GETOPT
Added: dragonegg/trunk/utils/empty.c
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/utils/empty.c?rev=154925&view=auto
==============================================================================
(empty)
Added: dragonegg/trunk/utils/lang_plugin.c
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/utils/lang_plugin.c?rev=154925&view=auto
==============================================================================
--- dragonegg/trunk/utils/lang_plugin.c (added)
+++ dragonegg/trunk/utils/lang_plugin.c Tue Apr 17 08:04:14 2012
@@ -0,0 +1,12 @@
+#include "gcc-plugin.h"
+
+int plugin_is_GPL_compatible;
+
+/* Use a symbol defined inside gcc. */
+extern int toplev_main (int argc, char **argv);
+int (*use) (int argc, char **argv) = toplev_main;
+
+int plugin_init(struct plugin_name_args *plugin_info,
+ struct plugin_gcc_version *version) {
+ return 0;
+}
More information about the llvm-commits
mailing list