Hi,

This patch defines the default supplied main function as read when
compiling with `-fmain' as extern(C) when compiling without D runtime.

The default linkage is extern(D), however this does not work when mixing
`-fmain' together with `-fno-druntime'.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32, and
committed to mainline.

Regards
Iain

---
gcc/testsuite/ChangeLog:

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

libphobos/ChangeLog:

        PR d/102476
        * libdruntime/__main.di: Define main function as extern(C) when
        compiling without D runtime.
---
 gcc/testsuite/gdc.dg/pr102476.d |  3 +++
 libphobos/libdruntime/__main.di | 14 ++++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gdc.dg/pr102476.d

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

Reply via email to