libphobos: Define main function as extern(C) when compiling without D runtime (PR102476)
authorIain Buclaw <ibuclaw@gdcproject.org>
Fri, 24 Sep 2021 08:59:47 +0000 (10:59 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Thu, 30 Sep 2021 13:07:19 +0000 (15:07 +0200)
The default supplied main function as read when compiling with `-fmain'
has extern(D) linkage.  However this does not work when mixing this
option together with `-fno-druntime'.

PR d/102476

gcc/testsuite/ChangeLog:

* gdc.dg/pr102476.d: New test.

libphobos/ChangeLog:

* libdruntime/__main.di: Define main function as extern(C) when
compiling without D runtime.

gcc/testsuite/gdc.dg/pr102476.d [new file with mode: 0644]
libphobos/libdruntime/__main.di

diff --git a/gcc/testsuite/gdc.dg/pr102476.d b/gcc/testsuite/gdc.dg/pr102476.d
new file mode 100644 (file)
index 0000000..543716e
--- /dev/null
@@ -0,0 +1,3 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102476
+// { dg-do link }
+// { dg-options "-fmain -fno-druntime" }
index 8062bf4..ab1264b 100644 (file)
 
 module __main;
 
-int main(char[][])
+version (D_BetterC)
 {
-    return 0;
+    extern (C) int main(int, char**)
+    {
+        return 0;
+    }
+}
+else
+{
+    int main(char[][])
+    {
+        return 0;
+    }
 }