[PATCH] Add implicit C linkage for win32-specific entry points

2013-05-04 Thread Jacek Caban

Hi,

This is another version of my old patch, changed to use target hooks as 
requested by Steven Bosscher.


Tested on i686-w64-mingw32, x86_64-w64-mingw32 and 
x86_64-unknown-linux-gnu, bootstrapped on x86_64-unknown-linux-gnu.


Disclaimer: the patch is in public domain.

(because I don't have copyright assignment done).


gcc/c-family/ChangeLog:
c-target.def: New hook

gcc/ChangeLog:
config/config.gcc: Use new winnt-c.c target hooks
config/t-winnt: New file
config/winnt-c.c: New file
doc/tm.texi.in: Document new hook
doc/tm.texi: Regenerated

gcc/cp/Changelog:
decl.c: Use new cxx_implicit_extern_c hook

gcc/testsuite/ChangeLog:
g++.dg/abi/main.C: Added implicit C linkage tests
---
 gcc/c-family/c-target.def   |  7 +++
 gcc/config.gcc  |  5 -
 gcc/config/t-winnt  | 22 ++
 gcc/config/winnt-c.c| 39 
+++

 gcc/cp/decl.c   |  5 -
 gcc/doc/tm.texi |  4 
 gcc/doc/tm.texi.in  |  2 ++
 gcc/testsuite/g++.dg/abi/main.C | 24 
 8 files changed, 106 insertions(+), 2 deletions(-)
 create mode 100644 gcc/config/t-winnt
 create mode 100644 gcc/config/winnt-c.c
 create mode 100644 gcc/testsuite/g++.dg/abi/main.C


diff --git a/gcc/c-family/c-target.def b/gcc/c-family/c-target.def
index 80042df..b9efae5 100644
--- a/gcc/c-family/c-target.def
+++ b/gcc/c-family/c-target.def
@@ -102,5 +102,12 @@ DEFHOOK
  than just the compiler.,
  const char *, (void),
  hook_constcharptr_void_null)
+
+DEFHOOK
+(cxx_implicit_extern_c,
+ Define this hook to add target-specific C++ implicit extern C functions.\
+ An example of such function is WinMain on Win32 targets.,
+ bool, (const char*),
+ NULL)
  
 HOOK_VECTOR_END (C90_EMPTY_HACK)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 5a205df..0cf61b0 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1475,6 +1475,9 @@ x86_64-*-cygwin*)
 i[34567]86-*-mingw* | x86_64-*-mingw*)
 	tm_file=${tm_file} i386/unix.h i386/bsd.h i386/gas.h dbxcoff.h i386/cygming.h
 	xm_file=i386/xm-mingw32.h
+	c_target_objs=${c_target_objs} winnt-c.o
+	cxx_target_objs=${cxx_target_objs} winnt-c.o
+	target_has_targetcm=yes
 	case ${target} in
 		x86_64-*-* | *-w64-*)
 			need_64bit_isa=yes
@@ -1514,7 +1517,7 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
 			;;
 	esac
 	tm_file=${tm_file} i386/mingw-stdint.h
-	tmake_file=${tmake_file} i386/t-cygming t-slibgcc
+	tmake_file=${tmake_file} t-winnt i386/t-cygming t-slibgcc
 case ${target} in
x86_64-w64-*)
		tmake_file=${tmake_file} i386/t-mingw-w64
diff --git a/gcc/config/t-winnt b/gcc/config/t-winnt
new file mode 100644
index 000..4cc3339
--- /dev/null
+++ b/gcc/config/t-winnt
@@ -0,0 +1,22 @@
+# Copyright (C) 2004, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# http://www.gnu.org/licenses/.
+
+winnt-c.o: config/winnt-c.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
+  $(C_TARGET_H) $(C_TARGET_DEF_H)
+	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) \
+	  $ $(OUTPUT_OPTION)
diff --git a/gcc/config/winnt-c.c b/gcc/config/winnt-c.c
new file mode 100644
index 000..da0f49c
--- /dev/null
+++ b/gcc/config/winnt-c.c
@@ -0,0 +1,39 @@
+/* Default C-family target hooks initializer.
+   Copyright (C) 2011
+   Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+http://www.gnu.org/licenses/.  */
+
+#include config.h
+#include system.h
+#include coretypes.h
+#include c-family/c-target.h
+#include c-family/c-target-def.h
+
+static bool
+winnt_implicit_extern_c (const char *ident)
+{
+  return !strcmp(ident, wmain)
+  || !strcmp(ident, DllMain)
+  || !strcmp(ident, WinMain)
+  || 

Re: Ping: [PATCH] Add implicit C linkage for win32-specific entry points

2012-06-15 Thread Eric Botcazou
 Jacek Caban sent this:

 http://gcc.gnu.org/ml/gcc-patches/2012-03/msg01987.html

 in response to this:

 http://gcc.gnu.org/ml/gcc-patches/2012-03/msg01986.html

 But it never got reviewed.  Could you review and commit?

No, I don't have approval rights here, you need a Windows maintainer (Kai).

-- 
Eric Botcazou


Re: Ping: [PATCH] Add implicit C linkage for win32-specific entry points

2012-06-15 Thread Kai Tietz
2012/6/15 Eric Botcazou ebotca...@adacore.com:
 Jacek Caban sent this:

 http://gcc.gnu.org/ml/gcc-patches/2012-03/msg01987.html

 in response to this:

 http://gcc.gnu.org/ml/gcc-patches/2012-03/msg01986.html

 But it never got reviewed.  Could you review and commit?

 No, I don't have approval rights here, you need a Windows maintainer (Kai).

 --
 Eric Botcazou

The patch is from my point of view ok.  We need here for the
introduction of CPP_IMPLICIT_TARGET_CLANG and its use in cp/decl.c the
approval of a C++ maintainer (jason?).
One nit I have about the ChangeLog entry.  The C++ change needs a
separate ChangeLog entry under cp/.

Regards,
Kai


Ping: [PATCH] Add implicit C linkage for win32-specific entry points

2012-06-14 Thread NightStrike
Eric,

Jacek Caban sent this:

http://gcc.gnu.org/ml/gcc-patches/2012-03/msg01987.html

in response to this:

http://gcc.gnu.org/ml/gcc-patches/2012-03/msg01986.html

But it never got reviewed.  Could you review and commit?


[PATCH] Add implicit C linkage for win32-specific entry points

2012-03-31 Thread Jacek Caban
This is my first patch to GCC, so please let me know if I did something 
wrong. This patch fixes common annoyance on w64-mingw32 targets, where 
once needs to add explicit C linkage to make C++ app work with wmain 
entry point.


* decl.c: Allow custom target implicit C linkage
* mingw-w64.h: Specify entry points with implicit C linkage
* main.C: Added implicit C linkage tests
---
 gcc/config/i386/mingw-w64.h |6 ++
 gcc/cp/decl.c   |8 ++--
 gcc/testsuite/g++.dg/ext/main.C |   24 
 3 files changed, 36 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/main.C


diff --git a/gcc/config/i386/mingw-w64.h b/gcc/config/i386/mingw-w64.h
index a45ce28..1ce940a 100644
--- a/gcc/config/i386/mingw-w64.h
+++ b/gcc/config/i386/mingw-w64.h
@@ -85,3 +85,9 @@ along with GCC; see the file COPYING3.  If not see
   %{static:-Bstatic} %{!static:-Bdynamic} \
   %{shared|mdll:  SUB_LINK_ENTRY  --enable-auto-image-base} \
   %(shared_libgcc_undefs)
+
+#define CPP_IMPLICIT_TARGET_CLANG(ident) \
+(  !strcmp(ident, wmain) \
+|| !strcmp(ident, DllMain) \
+|| !strcmp(ident, WinMain) \
+|| !strcmp(ident, wWinMain))
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index a89523d..307e5c1 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7290,12 +7290,16 @@ grokfndecl (tree ctype,
   else if (!ctype)
 DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ());
 
-  /* `main' and builtins have implicit 'C' linkage.  */
+  /* `main', builtins and some target specific functions have implicit 'C' linkage.  */
   if ((MAIN_NAME_P (declarator)
|| (IDENTIFIER_LENGTH (declarator)  10
 	IDENTIFIER_POINTER (declarator)[0] == '_'
 	IDENTIFIER_POINTER (declarator)[1] == '_'
-	strncmp (IDENTIFIER_POINTER (declarator)+2, builtin_, 8) == 0))
+	strncmp (IDENTIFIER_POINTER (declarator)+2, builtin_, 8) == 0)
+#ifdef CPP_IMPLICIT_TARGET_CLANG
+   || CPP_IMPLICIT_TARGET_CLANG(IDENTIFIER_POINTER (declarator))
+#endif
+   )
current_lang_name == lang_name_cplusplus
ctype == NULL_TREE
DECL_FILE_SCOPE_P (decl))
diff --git a/gcc/testsuite/g++.dg/ext/main.C b/gcc/testsuite/g++.dg/ext/main.C
new file mode 100644
index 000..4c5f1ea
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/main.C
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+
+/* Check if entry points get implicit C linkage. If they don't, compiler will
+ * error on incompatible declarations */
+
+int main();
+extern C int main();
+
+#ifdef __MINGW32__
+
+int wmain();
+extern C int wmain();
+
+int DllMain();
+extern C int DllMain();
+
+int WinMain();
+extern C int WinMain();
+
+int wWinMain();
+extern C int wWinMain();
+
+#endif
+



Re: [PATCH] Add implicit C linkage for win32-specific entry points

2012-03-31 Thread Eric Botcazou
 This is my first patch to GCC, so please let me know if I did something
 wrong. This patch fixes common annoyance on w64-mingw32 targets, where
 once needs to add explicit C linkage to make C++ app work with wmain
 entry point.

   * decl.c: Allow custom target implicit C linkage
   * mingw-w64.h: Specify entry points with implicit C linkage
   * main.C: Added implicit C linkage tests

There are mutiple ChangeLog files in the tree and you need to write an entry 
for each of them, using a path relative to the directory where it is found:

gcc/ChangeLog
* config/i386/mingw-w64.h: ...

gcc/cp/ChangeLog:
* decl.c: ...

gcc/testsuite/ChangeLog:
* g++.dg/ext/main.C: ...

-- 
Eric Botcazou


[PATCH] Add implicit C linkage for win32-specific entry points

2012-03-31 Thread Jacek Caban

Fixed Changelog as requested by Eric. Thanks.


gcc/ChangeLog
* config/i386/mingw-w64.h: Specify entry points with implicit C linkage

gcc/cp/ChangeLog:
* decl.c: Allow custom target implicit C linkage

gcc/testsuite/ChangeLog:
* g++.dg/ext/main.C: Added implicit C linkage tests
---
 gcc/config/i386/mingw-w64.h |6 ++
 gcc/cp/decl.c   |8 ++--
 gcc/testsuite/g++.dg/ext/main.C |   24 
 3 files changed, 36 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/main.C


diff --git a/gcc/config/i386/mingw-w64.h b/gcc/config/i386/mingw-w64.h
index a45ce28..1ce940a 100644
--- a/gcc/config/i386/mingw-w64.h
+++ b/gcc/config/i386/mingw-w64.h
@@ -85,3 +85,9 @@ along with GCC; see the file COPYING3.  If not see
   %{static:-Bstatic} %{!static:-Bdynamic} \
   %{shared|mdll:  SUB_LINK_ENTRY  --enable-auto-image-base} \
   %(shared_libgcc_undefs)
+
+#define CPP_IMPLICIT_TARGET_CLANG(ident) \
+(  !strcmp(ident, wmain) \
+|| !strcmp(ident, DllMain) \
+|| !strcmp(ident, WinMain) \
+|| !strcmp(ident, wWinMain))
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index a89523d..307e5c1 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7290,12 +7290,16 @@ grokfndecl (tree ctype,
   else if (!ctype)
 DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ());
 
-  /* `main' and builtins have implicit 'C' linkage.  */
+  /* `main', builtins and some target specific functions have implicit 'C' linkage.  */
   if ((MAIN_NAME_P (declarator)
|| (IDENTIFIER_LENGTH (declarator)  10
 	IDENTIFIER_POINTER (declarator)[0] == '_'
 	IDENTIFIER_POINTER (declarator)[1] == '_'
-	strncmp (IDENTIFIER_POINTER (declarator)+2, builtin_, 8) == 0))
+	strncmp (IDENTIFIER_POINTER (declarator)+2, builtin_, 8) == 0)
+#ifdef CPP_IMPLICIT_TARGET_CLANG
+   || CPP_IMPLICIT_TARGET_CLANG(IDENTIFIER_POINTER (declarator))
+#endif
+   )
current_lang_name == lang_name_cplusplus
ctype == NULL_TREE
DECL_FILE_SCOPE_P (decl))
diff --git a/gcc/testsuite/g++.dg/ext/main.C b/gcc/testsuite/g++.dg/ext/main.C
new file mode 100644
index 000..4c5f1ea
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/main.C
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+
+/* Check if entry points get implicit C linkage. If they don't, compiler will
+ * error on incompatible declarations */
+
+int main();
+extern C int main();
+
+#ifdef __MINGW32__
+
+int wmain();
+extern C int wmain();
+
+int DllMain();
+extern C int DllMain();
+
+int WinMain();
+extern C int WinMain();
+
+int wWinMain();
+extern C int wWinMain();
+
+#endif
+