Provide __start_minfo/__stop_minfo for linkers that don't (PR d/87864)

Message ID ydd4l9rzm6z.fsf@CeBiTec.Uni-Bielefeld.DE
State New
Headers show
Series
  • Provide __start_minfo/__stop_minfo for linkers that don't (PR d/87864)
Related show

Commit Message

Rainer Orth Jan. 29, 2019, 12:24 p.m.
Solaris ld only gained support for section bracketing in Solaris 11.4.
Fortunately, in gdc it is only used for the minfo section, so it's easy
to provide a workaround by adding two additional startup files
drt{begin,end}.o which define __start_minfo and __stop_minfo.

This patch does just that.

I've raised a couple of questions in the PR already:

* I've introduced a new -dstartfiles option which triggers the use of
  libgphobos.spec even with -nophoboslib.  Since it's effectively
  internal to the build system, I'm not currently documenting it.

* I'm reading the spec file addition from a file: keeping it in a make
  variable would be extremely messy due to the necessary quoting.

* I've chosen to use -Wc instead of -Xcompiler throughout: it's way
  shorter when more options need to be passed and it can take several
  comma-separated options at once.

* libdruntime/gcc/drtstuff.c needs a copyright notice unless one wants
  to keep it in the public domain (also plausible).  Effectively
  something for Iain to decide.

Bootstrapped without regressions on i386-pc-solaris2.11 (Solaris 11.3),
no regressions compared to Solaris 11.4 test results.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2018-11-20  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	libphobos:
	PR d/87864
	* configure.ac [!DCFG_MINFO_BRACKETING] (DRTSTUFF_SPEC): New variable.
	Substitute it.
	* libdruntime/m4/druntime/os.m4 (DRUNTIME_OS_MINFO_BRACKETING):
	New automake conditional.
	* configure: Regenerate.
	* libdruntime/gcc/drtstuff.c: New file.
	* libdruntime/Makefile.am [!DRUNTIME_OS_MINFO_BRACKETING]
	(DRTSTUFF, toolexeclib_DATA): New variables.
	(gcc/drtbegin.lo, gcc/drtend.lo): New rules.
	(libgdruntime_la_LDFLAGS): Add -dstartfiles -Bgcc -B../src.
	(libgdruntime_la_DEPENDENCIES): New variable.
	* src/Makefile.am (libgphobos_la_LDFLAGS): Add -dstartfiles
	-B../libdruntime/gcc.
	* libdruntime/Makefile.in, src/Makefile.in: Regenerate.
	* Makefile.in, testsuite/Makefile.in: Regenerate.
	* libdruntime/rt/sections_elf_shared.d (Minfo_Bracketing): Don't
	assert.
	* src/drtstuff.spec: New file.
	* src/libgphobos.spec.in (DRTSTUFF_SPEC): Substitute.
	(*lib): Only pass SPEC_PHOBOS_DEPS without -debuglib, -defaultlib,
	-nophoboslib.
	* testsuite/testsuite_flags.in <--gdcldflags> (GDCLDFLAGS): Add
	-B${BUILD_DIR}/libdruntime/gcc.

	* libdruntime/Makefile.am (unittest_static_LDFLAGS): Use -Wc
	instead of -Xcompiler.
	(libgdruntime_t_la_LDFLAGS): Likewise.
	(unittest_LDFLAGS): Likewise.
	* src/Makefile.am (unittest_static_LDFLAGS): Likewise.
	(libgphobos_t_la_LDFLAGS): Likewise.
	(unittest_LDFLAGS): Likewise.

	gcc/d:
	PR d/87864
	* lang.opt (dstartfiles): New option.
	* d-spec.cc (need_spec): New variable.
	(lang_specific_driver) <OPT_dstartfiles>: Enable need_spec.
	(lang_specific_pre_link): Also load libgphobos.spec if need_spec.

	gcc/testsuite:
	PR d/87864
	* lib/gdc.exp (gdc_link_flags): Add path to drtbegin.o/drtend.o if
	present.

Comments

Johannes Pfau Jan. 31, 2019, 6:12 p.m. | #1
Looks good to me, although ultimately Iain has to decide of course.

One nitpick: wouldn't you have to somehow mark __start/__stop _minfo as 
hidden? This is important in the case where you have multiple shared 
libraries and each library should have its own __start/__stop symbold to 
braket the library's minfo section.

Also 'if !DRUNTIME_OS_MINFO_BRACKETING' might be the wrong 
condition/name in Makefile.am if we add back support for per-module 
constructor-based module registration (instead of calling 
_d_dso_registry once per shared library passing all ModuleInfos in that 
library, call another hook _d_register_module once per module and pass 
only one ModuleInfo). But we can fix that if we ever need to add back 
support for that second approach. (If this startfile/endfile approach is 
portable enough, we may be able to avoid that).

Best regards,
Johannes

Am 29.01.19 um 13:24 schrieb Rainer Orth:
> Solaris ld only gained support for section bracketing in Solaris 11.4.

> Fortunately, in gdc it is only used for the minfo section, so it's easy

> to provide a workaround by adding two additional startup files

> drt{begin,end}.o which define __start_minfo and __stop_minfo.

> 

> This patch does just that.

> 

> I've raised a couple of questions in the PR already:

> 

> * I've introduced a new -dstartfiles option which triggers the use of

>    libgphobos.spec even with -nophoboslib.  Since it's effectively

>    internal to the build system, I'm not currently documenting it.

> 

> * I'm reading the spec file addition from a file: keeping it in a make

>    variable would be extremely messy due to the necessary quoting.

> 

> * I've chosen to use -Wc instead of -Xcompiler throughout: it's way

>    shorter when more options need to be passed and it can take several

>    comma-separated options at once.

> 

> * libdruntime/gcc/drtstuff.c needs a copyright notice unless one wants

>    to keep it in the public domain (also plausible).  Effectively

>    something for Iain to decide.

> 

> Bootstrapped without regressions on i386-pc-solaris2.11 (Solaris 11.3),

> no regressions compared to Solaris 11.4 test results.

> 

> 	Rainer

>
Rainer Orth Feb. 1, 2019, 1:40 p.m. | #2
Hi Johannes,

> Looks good to me, although ultimately Iain has to decide of course.


fine, thanks.  However, if we cannot find an acceptable solution for the
lack of dlpi_tls_modid, the patch isn't of much use:

* Solaris 11.5 will have all of dlpi_tls_modid and section bracketing.

* Solaris 11.4 has ld section bracketing, but might or might not get
  dlpi_tls_modid by a patch.

* Solaris 11.3 lacks ld section bracketing, won't get dlpi_tls_modid,
  and also needs this patch to link with -lsocket -lnsl separately:

	[build] Fix libgphobos linking on Solaris 11
	https://gcc.gnu.org/ml/gcc-patches/2018-11/msg02248.html

> One nitpick: wouldn't you have to somehow mark __start/__stop _minfo as

> hidden? This is important in the case where you have multiple shared

> libraries and each library should have its own __start/__stop symbold to

> braket the library's minfo section.


Here's what I see in libgdruntime.so with various linkers/approaches for
minfo bracketing, using readelf -s libgdruntime.so|grep __start:

* gld 2.31 on x86_64-pc-linux-gnu (native gld section bracketing):

     2: 000000000012b770     0 NOTYPE  LOCAL  DEFAULT   26 __start_minfo
  1763: 000000000012b770     0 NOTYPE  LOCAL  DEFAULT   26 __start_minfo

* Solaris ld on i386-pc-solaris2.11 (Solaris 11.4 where ld supports
  section bracketing natively):

   136: 00147f40   836 OBJECT  LOCAL  HIDDEN    28 __start_minfo

* Solaris ld on i386-pc-solaris2.11 (Solaris 11.3 with drtstuff patch):

   150: 0014731c     0 OBJECT  LOCAL  HIDDEN    40 __start_minfo

I guess it's enough that the symbols are local, irrespective of visibility.

> Also 'if !DRUNTIME_OS_MINFO_BRACKETING' might be the wrong condition/name

> in Makefile.am if we add back support for per-module constructor-based

> module registration (instead of calling _d_dso_registry once per shared

> library passing all ModuleInfos in that library, call another hook

> _d_register_module once per module and pass only one ModuleInfo). But we

> can fix that if we ever need to add back support for that second

> approach. (If this startfile/endfile approach is portable enough, we may be

> able to avoid that).


It seemed natural to me to call the automake conditional similarly to
the variable set by the DRUNTIME_OS_MINFO_BRACKETING macro.  But I'm of
course open to other names, although it's probably best to only think
about renaming once section bracketing gets other uses.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
Iain Buclaw Feb. 13, 2019, 8:16 p.m. | #3
On Tue, 29 Jan 2019 at 13:24, Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:
>

> Solaris ld only gained support for section bracketing in Solaris 11.4.

> Fortunately, in gdc it is only used for the minfo section, so it's easy

> to provide a workaround by adding two additional startup files

> drt{begin,end}.o which define __start_minfo and __stop_minfo.

>

> This patch does just that.

>

> I've raised a couple of questions in the PR already:

>

> * I've introduced a new -dstartfiles option which triggers the use of

>   libgphobos.spec even with -nophoboslib.  Since it's effectively

>   internal to the build system, I'm not currently documenting it.

>

> * I'm reading the spec file addition from a file: keeping it in a make

>   variable would be extremely messy due to the necessary quoting.

>

> * I've chosen to use -Wc instead of -Xcompiler throughout: it's way

>   shorter when more options need to be passed and it can take several

>   comma-separated options at once.

>

> * libdruntime/gcc/drtstuff.c needs a copyright notice unless one wants

>   to keep it in the public domain (also plausible).  Effectively

>   something for Iain to decide.

>

> Bootstrapped without regressions on i386-pc-solaris2.11 (Solaris 11.3),

> no regressions compared to Solaris 11.4 test results.

>

>         Rainer

>

> --

> -----------------------------------------------------------------------------

> Rainer Orth, Center for Biotechnology, Bielefeld University

>

>

> 2018-11-20  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

>

>         libphobos:

>         PR d/87864

>         * configure.ac [!DCFG_MINFO_BRACKETING] (DRTSTUFF_SPEC): New variable.

>         Substitute it.

>         * libdruntime/m4/druntime/os.m4 (DRUNTIME_OS_MINFO_BRACKETING):

>         New automake conditional.

>         * configure: Regenerate.

>         * libdruntime/gcc/drtstuff.c: New file.

>         * libdruntime/Makefile.am [!DRUNTIME_OS_MINFO_BRACKETING]

>         (DRTSTUFF, toolexeclib_DATA): New variables.

>         (gcc/drtbegin.lo, gcc/drtend.lo): New rules.

>         (libgdruntime_la_LDFLAGS): Add -dstartfiles -Bgcc -B../src.

>         (libgdruntime_la_DEPENDENCIES): New variable.

>         * src/Makefile.am (libgphobos_la_LDFLAGS): Add -dstartfiles

>         -B../libdruntime/gcc.

>         * libdruntime/Makefile.in, src/Makefile.in: Regenerate.

>         * Makefile.in, testsuite/Makefile.in: Regenerate.

>         * libdruntime/rt/sections_elf_shared.d (Minfo_Bracketing): Don't

>         assert.

>         * src/drtstuff.spec: New file.

>         * src/libgphobos.spec.in (DRTSTUFF_SPEC): Substitute.

>         (*lib): Only pass SPEC_PHOBOS_DEPS without -debuglib, -defaultlib,

>         -nophoboslib.

>         * testsuite/testsuite_flags.in <--gdcldflags> (GDCLDFLAGS): Add

>         -B${BUILD_DIR}/libdruntime/gcc.

>

>         * libdruntime/Makefile.am (unittest_static_LDFLAGS): Use -Wc

>         instead of -Xcompiler.

>         (libgdruntime_t_la_LDFLAGS): Likewise.

>         (unittest_LDFLAGS): Likewise.

>         * src/Makefile.am (unittest_static_LDFLAGS): Likewise.

>         (libgphobos_t_la_LDFLAGS): Likewise.

>         (unittest_LDFLAGS): Likewise.

>

>         gcc/d:

>         PR d/87864

>         * lang.opt (dstartfiles): New option.

>         * d-spec.cc (need_spec): New variable.

>         (lang_specific_driver) <OPT_dstartfiles>: Enable need_spec.

>         (lang_specific_pre_link): Also load libgphobos.spec if need_spec.

>

>         gcc/testsuite:

>         PR d/87864

>         * lib/gdc.exp (gdc_link_flags): Add path to drtbegin.o/drtend.o if

>         present.

>


I'd say go for it.  I see that there's a tab that found its way into
lib/gdc.exp, and there's a copyright notice that needs fixing up.

I'd make another change after this, and move / remove the
rt/sections_*.d modules to gcc/sections/*.d, as those modules mirrored
from upstream are all very specific to the dmd compiler itself, and I
don't think will be able to use sections_osx or sections_win32
verbatim in the same way as sections_elf_shared.

-- 
Iain
Rainer Orth Feb. 14, 2019, 10:13 a.m. | #4
Hi Iain,

> On Tue, 29 Jan 2019 at 13:24, Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:

>>

>> Solaris ld only gained support for section bracketing in Solaris 11.4.

>> Fortunately, in gdc it is only used for the minfo section, so it's easy

>> to provide a workaround by adding two additional startup files

>> drt{begin,end}.o which define __start_minfo and __stop_minfo.

>>

>> This patch does just that.

>>

>> I've raised a couple of questions in the PR already:

>>

>> * I've introduced a new -dstartfiles option which triggers the use of

>>   libgphobos.spec even with -nophoboslib.  Since it's effectively

>>   internal to the build system, I'm not currently documenting it.

>>

>> * I'm reading the spec file addition from a file: keeping it in a make

>>   variable would be extremely messy due to the necessary quoting.

>>

>> * I've chosen to use -Wc instead of -Xcompiler throughout: it's way

>>   shorter when more options need to be passed and it can take several

>>   comma-separated options at once.

>>

>> * libdruntime/gcc/drtstuff.c needs a copyright notice unless one wants

>>   to keep it in the public domain (also plausible).  Effectively

>>   something for Iain to decide.

>>

>> Bootstrapped without regressions on i386-pc-solaris2.11 (Solaris 11.3),

>> no regressions compared to Solaris 11.4 test results.

>>

>>         Rainer

>>

>> --

>> -----------------------------------------------------------------------------

>> Rainer Orth, Center for Biotechnology, Bielefeld University

>>

>>

>> 2018-11-20  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

>>

>>         libphobos:

>>         PR d/87864

>>         * configure.ac [!DCFG_MINFO_BRACKETING] (DRTSTUFF_SPEC): New variable.

>>         Substitute it.

>>         * libdruntime/m4/druntime/os.m4 (DRUNTIME_OS_MINFO_BRACKETING):

>>         New automake conditional.

>>         * configure: Regenerate.

>>         * libdruntime/gcc/drtstuff.c: New file.

>>         * libdruntime/Makefile.am [!DRUNTIME_OS_MINFO_BRACKETING]

>>         (DRTSTUFF, toolexeclib_DATA): New variables.

>>         (gcc/drtbegin.lo, gcc/drtend.lo): New rules.

>>         (libgdruntime_la_LDFLAGS): Add -dstartfiles -Bgcc -B../src.

>>         (libgdruntime_la_DEPENDENCIES): New variable.

>>         * src/Makefile.am (libgphobos_la_LDFLAGS): Add -dstartfiles

>>         -B../libdruntime/gcc.

>>         * libdruntime/Makefile.in, src/Makefile.in: Regenerate.

>>         * Makefile.in, testsuite/Makefile.in: Regenerate.

>>         * libdruntime/rt/sections_elf_shared.d (Minfo_Bracketing): Don't

>>         assert.

>>         * src/drtstuff.spec: New file.

>>         * src/libgphobos.spec.in (DRTSTUFF_SPEC): Substitute.

>>         (*lib): Only pass SPEC_PHOBOS_DEPS without -debuglib, -defaultlib,

>>         -nophoboslib.

>>         * testsuite/testsuite_flags.in <--gdcldflags> (GDCLDFLAGS): Add

>>         -B${BUILD_DIR}/libdruntime/gcc.

>>

>>         * libdruntime/Makefile.am (unittest_static_LDFLAGS): Use -Wc

>>         instead of -Xcompiler.

>>         (libgdruntime_t_la_LDFLAGS): Likewise.

>>         (unittest_LDFLAGS): Likewise.

>>         * src/Makefile.am (unittest_static_LDFLAGS): Likewise.

>>         (libgphobos_t_la_LDFLAGS): Likewise.

>>         (unittest_LDFLAGS): Likewise.

>>

>>         gcc/d:

>>         PR d/87864

>>         * lang.opt (dstartfiles): New option.

>>         * d-spec.cc (need_spec): New variable.

>>         (lang_specific_driver) <OPT_dstartfiles>: Enable need_spec.

>>         (lang_specific_pre_link): Also load libgphobos.spec if need_spec.

>>

>>         gcc/testsuite:

>>         PR d/87864

>>         * lib/gdc.exp (gdc_link_flags): Add path to drtbegin.o/drtend.o if

>>         present.

>>

>

> I'd say go for it.  I see that there's a tab that found its way into

> lib/gdc.exp, and there's a copyright notice that needs fixing up.


that tab is both due the gcc convention (GCS actually) of using tabs
instead of 8 spaces, unlike D, and Emacs' tcl mode that follows it.
I've now fixed it up to be consistent with the rest of gdc.exp.

For the drtstuff.c copyright notice, I've taken GPLv3+runtime exception,
just like the libgcc/crtstuff.c one where this snippet effectively comes
from.  Since this file is gdc-only, I guess that's ok?

I'm running an i686-pc-linux-gnu bootstrap right now where this patch
should be a no-op, just to make sure again that it doesn't break
anything.  Unless you see some error or there's a problem with the
choice of license, I'm going to check it in afterwards.

> I'd make another change after this, and move / remove the

> rt/sections_*.d modules to gcc/sections/*.d, as those modules mirrored

> from upstream are all very specific to the dmd compiler itself, and I

> don't think will be able to use sections_osx or sections_win32

> verbatim in the same way as sections_elf_shared.


Certainly makes sense.  ldc has its own sections_ldc.d, probably for
similar reasons.

Thanks.
	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
# HG changeset patch
# Parent  515fd28a96b46b13faa0d384d100083e2feb710a
Provide __start_minfo/__stop_minfo for linkers that don't (PR d/87864)

diff --git a/gcc/d/d-spec.cc b/gcc/d/d-spec.cc
--- a/gcc/d/d-spec.cc
+++ b/gcc/d/d-spec.cc
@@ -72,6 +72,9 @@ static phobos_action phobos_library = PH
    standard libraries.  */
 static bool need_phobos = true;
 
+/* If true, do load libgphobos.spec even if not needed otherwise.  */
+static bool need_spec = false;
+
 void
 lang_specific_driver (cl_decoded_option **in_decoded_options,
 		      unsigned int *in_decoded_options_count,
@@ -144,6 +147,10 @@ lang_specific_driver (cl_decoded_option 
 
       switch (decoded_options[i].opt_index)
 	{
+	case OPT_dstartfiles:
+	  need_spec = true;
+	  break;
+
 	case OPT_nostdlib:
 	case OPT_nodefaultlibs:
 	  phobos_library = PHOBOS_NOLINK;
@@ -491,7 +498,7 @@ lang_specific_driver (cl_decoded_option 
 int
 lang_specific_pre_link (void)
 {
-  if (phobos_library != PHOBOS_NOLINK && need_phobos)
+  if ((phobos_library != PHOBOS_NOLINK && need_phobos) || need_spec)
     do_spec ("%:include(libgphobos.spec)");
 
   return 0;
diff --git a/gcc/d/lang.opt b/gcc/d/lang.opt
--- a/gcc/d/lang.opt
+++ b/gcc/d/lang.opt
@@ -162,6 +162,10 @@ defaultlib=
 Driver Joined
 Default library to use instead of phobos.
 
+dstartfiles
+Driver
+Do link the standard D startup files in the compilation.
+
 -verbose
 D Alias(v)
 
diff --git a/gcc/testsuite/lib/gdc.exp b/gcc/testsuite/lib/gdc.exp
--- a/gcc/testsuite/lib/gdc.exp
+++ b/gcc/testsuite/lib/gdc.exp
@@ -120,6 +120,10 @@ proc gdc_link_flags { paths } {
     if { $gccpath != "" } {
         # Path to libgphobos.spec.
         append flags "-B${gccpath}/libphobos/src "
+        # Path to drtbegin.o/drtend.o.
+        if { [file exists "${gccpath}/libphobos/libdruntime/gcc/drtbegin.o"] } {
+            append flags "-B${gccpath}/libphobos/libdruntime/gcc "
+        }
 
         if { [file exists "${gccpath}/libphobos/src/.libs/libgphobos.a"] \
              || [file exists "${gccpath}/libphobos/src/.libs/libgphobos.${shlib_ext}"] } {
diff --git a/libphobos/configure.ac b/libphobos/configure.ac
--- a/libphobos/configure.ac
+++ b/libphobos/configure.ac
@@ -143,6 +143,14 @@ DRUNTIME_LIBRARIES_DLOPEN
 DRUNTIME_LIBRARIES_ZLIB
 DRUNTIME_INSTALL_DIRECTORIES
 
+# Add drtbegin.o/drtend.o to startfile/endfile specs in libgphobos.spec
+if test "$DCFG_MINFO_BRACKETING" = "false"; then
+    DRTSTUFF_SPEC=$srcdir/src/drtstuff.spec
+else
+    DRTSTUFF_SPEC=/dev/null
+fi
+AC_SUBST_FILE(DRTSTUFF_SPEC)
+
 # Add dependencies for libgphobos.spec file
 SPEC_PHOBOS_DEPS="$LIBS"
 AC_SUBST(SPEC_PHOBOS_DEPS)
diff --git a/libphobos/libdruntime/Makefile.am b/libphobos/libdruntime/Makefile.am
--- a/libphobos/libdruntime/Makefile.am
+++ b/libphobos/libdruntime/Makefile.am
@@ -74,6 +74,20 @@ endif
 if DRUNTIME_OS_SOLARIS
     ALL_DRUNTIME_COMPILE_DSOURCES += $(DRUNTIME_DSOURCES_SOLARIS)
 endif
+
+# Provide __start_minfo, __stop_minfo if linker doesn't.
+if !DRUNTIME_OS_MINFO_BRACKETING
+    DRTSTUFF = gcc/drtbegin.o gcc/drtend.o
+
+    toolexeclib_DATA = $(DRTSTUFF)
+
+gcc/drtbegin.o: gcc/drtstuff.c
+	$(COMPILE) -DDRT_BEGIN -c -o $@ $<
+
+gcc/drtend.o: gcc/drtstuff.c
+	$(COMPILE) -DDRT_END -c -o $@ $<
+endif
+
 # Generated by configure
 ALL_DRUNTIME_COMPILE_DSOURCES += $(DRUNTIME_DSOURCES_GENERATED)
 
@@ -95,14 +109,16 @@ endif
 toolexeclib_LTLIBRARIES = libgdruntime.la
 libgdruntime_la_SOURCES = $(ALL_DRUNTIME_SOURCES)
 libgdruntime_la_LIBTOOLFLAGS =
-libgdruntime_la_LDFLAGS = -Xcompiler -nophoboslib -version-info $(libtool_VERSION)
+libgdruntime_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../src,-Bgcc \
+    -version-info $(libtool_VERSION)
 libgdruntime_la_LIBADD = $(LIBATOMIC) $(LIBBACKTRACE)
+libgdruntime_la_DEPENDENCIES = $(DRTSTUFF)
 
 # For static unittest, link objects directly
 unittest_static_SOURCES = ../testsuite/test_runner.d $(DRUNTIME_CSOURCES) \
     $(DRUNTIME_SSOURCES)
 unittest_static_LIBTOOLFLAGS =
-unittest_static_LDFLAGS = -Xcompiler -nophoboslib
+unittest_static_LDFLAGS = -Wc,-nophoboslib
 unittest_static_LDADD = $(DRUNTIME_TEST_OBJECTS) $(LIBATOMIC) $(LIBBACKTRACE)
 EXTRA_unittest_static_DEPENDENCIES = $(DRUNTIME_TEST_OBJECTS)
 
@@ -111,14 +127,14 @@ libgdruntime_t_la_SOURCES = $(DRUNTIME_C
 libgdruntime_t_la_LIBTOOLFLAGS =
 # Automake by default does not generate shared libs for non-installed
 # libraries. Use -rpath to force shared lib generation.
-libgdruntime_t_la_LDFLAGS = -Xcompiler -nophoboslib -rpath /foo -shared
+libgdruntime_t_la_LDFLAGS = -Wc,-nophoboslib -rpath /foo -shared
 libgdruntime_t_la_LIBADD = $(DRUNTIME_TEST_LOBJECTS) $(LIBATOMIC) $(LIBBACKTRACE)
 EXTRA_libgdruntime_t_la_DEPENDENCIES = $(DRUNTIME_TEST_LOBJECTS)
 
 # For unittest
 unittest_SOURCES = ../testsuite/test_runner.d
 unittest_LIBTOOLFLAGS =
-unittest_LDFLAGS = -Xcompiler -nophoboslib
+unittest_LDFLAGS = -Wc,-nophoboslib
 unittest_LDADD = libgdruntime_t.la
 
 # Extra install and clean rules.
diff --git a/libphobos/libdruntime/gcc/config.d.in b/libphobos/libdruntime/gcc/config.d.in
--- a/libphobos/libdruntime/gcc/config.d.in
+++ b/libphobos/libdruntime/gcc/config.d.in
@@ -35,9 +35,6 @@ enum ThreadModel
 
 enum ThreadModel GNU_Thread_Model = ThreadModel.@DCFG_THREAD_MODEL@;
 
-// Whether the linker provides __start_minfo and __stop_minfo symbols
-enum Minfo_Bracketing = @DCFG_MINFO_BRACKETING@;
-
 // Whether target has support for builtin atomics.
 enum GNU_Have_Atomics = @DCFG_HAVE_ATOMIC_BUILTINS@;
 
diff --git a/libphobos/libdruntime/gcc/drtstuff.c b/libphobos/libdruntime/gcc/drtstuff.c
new file mode 100644
--- /dev/null
+++ b/libphobos/libdruntime/gcc/drtstuff.c
@@ -0,0 +1,39 @@
+/* Provide minfo section bracketing for D executables and shared libraries
+   when the linker doesn't provide it.
+   Copyright (C) 2019 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.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* Avoid interference with targets without support for named sections.  */
+#ifdef __ELF__
+
+#ifdef DRT_BEGIN
+void *__start_minfo[]
+__attribute__((used, section("minfo"), aligned(sizeof(void *)))) = { };
+#endif
+
+#ifdef DRT_END
+void *__stop_minfo[]
+__attribute__((used, section("minfo"), aligned(sizeof(void *)))) = { };
+#endif
+
+#endif /* __ELF__ */
diff --git a/libphobos/libdruntime/rt/sections_elf_shared.d b/libphobos/libdruntime/rt/sections_elf_shared.d
--- a/libphobos/libdruntime/rt/sections_elf_shared.d
+++ b/libphobos/libdruntime/rt/sections_elf_shared.d
@@ -335,7 +335,6 @@ else
 ///////////////////////////////////////////////////////////////////////////////
 
 import gcc.config;
-static assert(Minfo_Bracketing, "Can't use _d_dso_registry interface");
 
 /*
  * This data structure is generated by the compiler, and then passed to
diff --git a/libphobos/m4/druntime/os.m4 b/libphobos/m4/druntime/os.m4
--- a/libphobos/m4/druntime/os.m4
+++ b/libphobos/m4/druntime/os.m4
@@ -180,5 +180,6 @@ AC_DEFUN([DRUNTIME_OS_MINFO_BRACKETING],
     [AC_MSG_RESULT([no])
      DCFG_MINFO_BRACKETING=false])
   AC_SUBST(DCFG_MINFO_BRACKETING)
+  AM_CONDITIONAL([DRUNTIME_OS_MINFO_BRACKETING], [test "$DCFG_MINFO_BRACKETING" = "true"])
   AC_LANG_POP([C])
 ])
diff --git a/libphobos/src/Makefile.am b/libphobos/src/Makefile.am
--- a/libphobos/src/Makefile.am
+++ b/libphobos/src/Makefile.am
@@ -57,14 +57,15 @@ toolexeclib_DATA = libgphobos.spec
 toolexeclib_LTLIBRARIES = libgphobos.la
 libgphobos_la_SOURCES = $(ALL_PHOBOS_SOURCES) $(ZLIB_SRC)
 libgphobos_la_LIBTOOLFLAGS =
-libgphobos_la_LDFLAGS = -Xcompiler -nophoboslib -version-info $(libtool_VERSION)
+libgphobos_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../libdruntime/gcc \
+    -version-info $(libtool_VERSION)
 libgphobos_la_LIBADD = ../libdruntime/libgdruntime.la
 libgphobos_la_DEPENDENCIES = libgphobos.spec
 
 # For static unittest, link objects directly
 unittest_static_SOURCES = ../testsuite/test_runner.d $(ZLIB_SRC)
 unittest_static_LIBTOOLFLAGS =
-unittest_static_LDFLAGS = -Xcompiler -nophoboslib -static-libtool-libs
+unittest_static_LDFLAGS = -Wc,-nophoboslib -static-libtool-libs
 unittest_static_LDADD = $(PHOBOS_TEST_OBJECTS) \
     ../libdruntime/libgdruntime.la
 EXTRA_unittest_static_DEPENDENCIES = $(PHOBOS_TEST_OBJECTS)
@@ -72,7 +73,7 @@ EXTRA_unittest_static_DEPENDENCIES = $(P
 # For unittest with dynamic library
 libgphobos_t_la_SOURCES = $(ZLIB_SRC)
 libgphobos_t_la_LIBTOOLFLAGS =
-libgphobos_t_la_LDFLAGS = -Xcompiler -nophoboslib -rpath /foo -shared
+libgphobos_t_la_LDFLAGS = -Wc,-nophoboslib -rpath /foo -shared
 libgphobos_t_la_LIBADD = $(PHOBOS_TEST_LOBJECTS) \
     ../libdruntime/libgdruntime.la
 EXTRA_libgphobos_t_la_DEPENDENCIES = $(PHOBOS_TEST_LOBJECTS)
@@ -80,7 +81,7 @@ EXTRA_libgphobos_t_la_DEPENDENCIES = $(P
 # For unittest
 unittest_SOURCES = ../testsuite/test_runner.d
 unittest_LIBTOOLFLAGS =
-unittest_LDFLAGS = -Xcompiler -nophoboslib -shared
+unittest_LDFLAGS = -Wc,-nophoboslib -shared
 unittest_LDADD = libgphobos_t.la ../libdruntime/libgdruntime.la
 
 # Extra install and clean rules.
diff --git a/libphobos/src/drtstuff.spec b/libphobos/src/drtstuff.spec
new file mode 100644
--- /dev/null
+++ b/libphobos/src/drtstuff.spec
@@ -0,0 +1,5 @@
+%rename startfile startfile_orig
+*startfile: %(startfile_orig) drtbegin.o%s
+
+%rename endfile endfile_orig
+*endfile: %(endfile_orig) drtend.o%s
diff --git a/libphobos/src/libgphobos.spec.in b/libphobos/src/libgphobos.spec.in
--- a/libphobos/src/libgphobos.spec.in
+++ b/libphobos/src/libgphobos.spec.in
@@ -4,5 +4,7 @@
 # order.
 #
 
+@DRTSTUFF_SPEC@
+
 %rename lib liborig_gdc_renamed
-*lib: @SPEC_PHOBOS_DEPS@ %(liborig_gdc_renamed)
+*lib: %{debuglib|defaultlib|nophoboslib: ; :@SPEC_PHOBOS_DEPS@} %(liborig_gdc_renamed)
diff --git a/libphobos/testsuite/testsuite_flags.in b/libphobos/testsuite/testsuite_flags.in
--- a/libphobos/testsuite/testsuite_flags.in
+++ b/libphobos/testsuite/testsuite_flags.in
@@ -40,6 +40,7 @@ case ${query} in
       ;;
     --gdcldflags)
       GDCLDFLAGS="-B${BUILD_DIR}/src
+                  -B${BUILD_DIR}/libdruntime/gcc
                   -L${BUILD_DIR}/libdruntime/.libs
                   -L${BUILD_DIR}/src/.libs"
       echo ${GDCLDFLAGS}
Iain Buclaw Feb. 14, 2019, 6:12 p.m. | #5
On Thu, 14 Feb 2019 at 11:13, Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:
>

> Hi Iain,

>

> > On Tue, 29 Jan 2019 at 13:24, Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:

> >>

> >> Solaris ld only gained support for section bracketing in Solaris 11.4.

> >> Fortunately, in gdc it is only used for the minfo section, so it's easy

> >> to provide a workaround by adding two additional startup files

> >> drt{begin,end}.o which define __start_minfo and __stop_minfo.

> >>

> >> This patch does just that.

> >>

> >> I've raised a couple of questions in the PR already:

> >>

> >> * I've introduced a new -dstartfiles option which triggers the use of

> >>   libgphobos.spec even with -nophoboslib.  Since it's effectively

> >>   internal to the build system, I'm not currently documenting it.

> >>

> >> * I'm reading the spec file addition from a file: keeping it in a make

> >>   variable would be extremely messy due to the necessary quoting.

> >>

> >> * I've chosen to use -Wc instead of -Xcompiler throughout: it's way

> >>   shorter when more options need to be passed and it can take several

> >>   comma-separated options at once.

> >>

> >> * libdruntime/gcc/drtstuff.c needs a copyright notice unless one wants

> >>   to keep it in the public domain (also plausible).  Effectively

> >>   something for Iain to decide.

> >>

> >> Bootstrapped without regressions on i386-pc-solaris2.11 (Solaris 11.3),

> >> no regressions compared to Solaris 11.4 test results.

> >>

> >>         Rainer

> >>

> >> --

> >> -----------------------------------------------------------------------------

> >> Rainer Orth, Center for Biotechnology, Bielefeld University

> >>

> >>

> >> 2018-11-20  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

> >>

> >>         libphobos:

> >>         PR d/87864

> >>         * configure.ac [!DCFG_MINFO_BRACKETING] (DRTSTUFF_SPEC): New variable.

> >>         Substitute it.

> >>         * libdruntime/m4/druntime/os.m4 (DRUNTIME_OS_MINFO_BRACKETING):

> >>         New automake conditional.

> >>         * configure: Regenerate.

> >>         * libdruntime/gcc/drtstuff.c: New file.

> >>         * libdruntime/Makefile.am [!DRUNTIME_OS_MINFO_BRACKETING]

> >>         (DRTSTUFF, toolexeclib_DATA): New variables.

> >>         (gcc/drtbegin.lo, gcc/drtend.lo): New rules.

> >>         (libgdruntime_la_LDFLAGS): Add -dstartfiles -Bgcc -B../src.

> >>         (libgdruntime_la_DEPENDENCIES): New variable.

> >>         * src/Makefile.am (libgphobos_la_LDFLAGS): Add -dstartfiles

> >>         -B../libdruntime/gcc.

> >>         * libdruntime/Makefile.in, src/Makefile.in: Regenerate.

> >>         * Makefile.in, testsuite/Makefile.in: Regenerate.

> >>         * libdruntime/rt/sections_elf_shared.d (Minfo_Bracketing): Don't

> >>         assert.

> >>         * src/drtstuff.spec: New file.

> >>         * src/libgphobos.spec.in (DRTSTUFF_SPEC): Substitute.

> >>         (*lib): Only pass SPEC_PHOBOS_DEPS without -debuglib, -defaultlib,

> >>         -nophoboslib.

> >>         * testsuite/testsuite_flags.in <--gdcldflags> (GDCLDFLAGS): Add

> >>         -B${BUILD_DIR}/libdruntime/gcc.

> >>

> >>         * libdruntime/Makefile.am (unittest_static_LDFLAGS): Use -Wc

> >>         instead of -Xcompiler.

> >>         (libgdruntime_t_la_LDFLAGS): Likewise.

> >>         (unittest_LDFLAGS): Likewise.

> >>         * src/Makefile.am (unittest_static_LDFLAGS): Likewise.

> >>         (libgphobos_t_la_LDFLAGS): Likewise.

> >>         (unittest_LDFLAGS): Likewise.

> >>

> >>         gcc/d:

> >>         PR d/87864

> >>         * lang.opt (dstartfiles): New option.

> >>         * d-spec.cc (need_spec): New variable.

> >>         (lang_specific_driver) <OPT_dstartfiles>: Enable need_spec.

> >>         (lang_specific_pre_link): Also load libgphobos.spec if need_spec.

> >>

> >>         gcc/testsuite:

> >>         PR d/87864

> >>         * lib/gdc.exp (gdc_link_flags): Add path to drtbegin.o/drtend.o if

> >>         present.

> >>

> >

> > I'd say go for it.  I see that there's a tab that found its way into

> > lib/gdc.exp, and there's a copyright notice that needs fixing up.

>

> that tab is both due the gcc convention (GCS actually) of using tabs

> instead of 8 spaces, unlike D, and Emacs' tcl mode that follows it.

> I've now fixed it up to be consistent with the rest of gdc.exp.

>


I didn't know that applied to dejagnu test scripts.  Feel free to
re-tab the file so it's consistent, I only noticed because of the
mixed 8 spaces/tabs.

> For the drtstuff.c copyright notice, I've taken GPLv3+runtime exception,

> just like the libgcc/crtstuff.c one where this snippet effectively comes

> from.  Since this file is gdc-only, I guess that's ok?

>


That's fine.  There is no rationale for gdc-specific parts of the D
runtime library to be under any other non-GPL license.

> I'm running an i686-pc-linux-gnu bootstrap right now where this patch

> should be a no-op, just to make sure again that it doesn't break

> anything.  Unless you see some error or there's a problem with the

> choice of license, I'm going to check it in afterwards.

>


OK, thanks.

-- 
Iain
Rainer Orth Feb. 18, 2019, 1:55 p.m. | #6
Hi Iain,

>> > I'd say go for it.  I see that there's a tab that found its way into

>> > lib/gdc.exp, and there's a copyright notice that needs fixing up.

>>

>> that tab is both due the gcc convention (GCS actually) of using tabs

>> instead of 8 spaces, unlike D, and Emacs' tcl mode that follows it.

>> I've now fixed it up to be consistent with the rest of gdc.exp.

>>

>

> I didn't know that applied to dejagnu test scripts.  Feel free to

> re-tab the file so it's consistent, I only noticed because of the

> mixed 8 spaces/tabs.


done now with the following ChangeLog entry:

2019-02-16  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	libphobos:
	* testsuite/lib/libphobos-dg.exp: Tabify.
	* testsuite/lib/libphobos.exp: Likewise.
	* testsuite/libphobos.cycles/cycles.exp: Likewise.
	* testsuite/libphobos.shared/shared.exp: Likewise.
	* testsuite/libphobos.unittests/unittests.exp: Likewise.

	gcc/testsuite:
	* gdc.dg/dg.exp: Tabify.
	* gdc.dg/lto/lto.exp: Likewise.
	* gdc.test/gdc-test.exp: Likewise.
	* lib/gdc-dg.exp: Likewise.
	* lib/gdc.exp: Likewise.

Given that diff -w came up empty, there's no point in posting the actual
patch.  Bootstrapped without regressions on i386-pc-solaris2.11 and
x86_64-pc-linux-gnu for good measure.

Thanks.
	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

Patch

# HG changeset patch
# Parent  2b02744cb551e91a3c5dc300f12ae168581adc34
Provide __start_minfo/__stop_minfo for linkers that don't (PR d/87864)

diff --git a/gcc/d/d-spec.cc b/gcc/d/d-spec.cc
--- a/gcc/d/d-spec.cc
+++ b/gcc/d/d-spec.cc
@@ -72,6 +72,9 @@  static phobos_action phobos_library = PH
    standard libraries.  */
 static bool need_phobos = true;
 
+/* If true, do load libgphobos.spec even if not needed otherwise.  */
+static bool need_spec = false;
+
 void
 lang_specific_driver (cl_decoded_option **in_decoded_options,
 		      unsigned int *in_decoded_options_count,
@@ -144,6 +147,10 @@  lang_specific_driver (cl_decoded_option 
 
       switch (decoded_options[i].opt_index)
 	{
+	case OPT_dstartfiles:
+	  need_spec = true;
+	  break;
+
 	case OPT_nostdlib:
 	case OPT_nodefaultlibs:
 	  phobos_library = PHOBOS_NOLINK;
@@ -491,7 +498,7 @@  lang_specific_driver (cl_decoded_option 
 int
 lang_specific_pre_link (void)
 {
-  if (phobos_library != PHOBOS_NOLINK && need_phobos)
+  if ((phobos_library != PHOBOS_NOLINK && need_phobos) || need_spec)
     do_spec ("%:include(libgphobos.spec)");
 
   return 0;
diff --git a/gcc/d/lang.opt b/gcc/d/lang.opt
--- a/gcc/d/lang.opt
+++ b/gcc/d/lang.opt
@@ -162,6 +162,10 @@  defaultlib=
 Driver Joined
 Default library to use instead of phobos.
 
+dstartfiles
+Driver
+Do link the standard D startup files in the compilation.
+
 -verbose
 D Alias(v)
 
diff --git a/gcc/testsuite/lib/gdc.exp b/gcc/testsuite/lib/gdc.exp
--- a/gcc/testsuite/lib/gdc.exp
+++ b/gcc/testsuite/lib/gdc.exp
@@ -119,6 +119,10 @@  proc gdc_link_flags { paths } {
     if { $gccpath != "" } {
         # Path to libgphobos.spec.
         append flags "-B${gccpath}/libphobos/src "
+	# Path to drtbegin.o/drtend.o.
+        if { [file exists "${gccpath}/libphobos/libdruntime/gcc/drtbegin.o"] } {
+            append flags "-B${gccpath}/libphobos/libdruntime/gcc "
+        }
 
         if { [file exists "${gccpath}/libphobos/src/.libs/libgphobos.a"] \
              || [file exists "${gccpath}/libphobos/src/.libs/libgphobos.${shlib_ext}"] } {
diff --git a/libphobos/configure.ac b/libphobos/configure.ac
--- a/libphobos/configure.ac
+++ b/libphobos/configure.ac
@@ -146,6 +146,14 @@  DRUNTIME_LIBRARIES_DLOPEN
 DRUNTIME_LIBRARIES_ZLIB
 DRUNTIME_INSTALL_DIRECTORIES
 
+# Add drtbegin.o/drtend.o to startfile/endfile specs in libgphobos.spec
+if test "$DCFG_MINFO_BRACKETING" = "false"; then
+    DRTSTUFF_SPEC=$srcdir/src/drtstuff.spec
+else
+    DRTSTUFF_SPEC=/dev/null
+fi
+AC_SUBST_FILE(DRTSTUFF_SPEC)
+
 # Add dependencies for libgphobos.spec file
 SPEC_PHOBOS_DEPS="$LIBS"
 AC_SUBST(SPEC_PHOBOS_DEPS)
diff --git a/libphobos/libdruntime/Makefile.am b/libphobos/libdruntime/Makefile.am
--- a/libphobos/libdruntime/Makefile.am
+++ b/libphobos/libdruntime/Makefile.am
@@ -74,6 +74,20 @@  endif
 if DRUNTIME_OS_SOLARIS
     ALL_DRUNTIME_COMPILE_DSOURCES += $(DRUNTIME_DSOURCES_SOLARIS)
 endif
+
+# Provide __start_minfo, __stop_minfo if linker doesn't.
+if !DRUNTIME_OS_MINFO_BRACKETING
+    DRTSTUFF = gcc/drtbegin.o gcc/drtend.o
+
+    toolexeclib_DATA = $(DRTSTUFF)
+
+gcc/drtbegin.o: gcc/drtstuff.c
+	$(COMPILE) -DDRT_BEGIN -c -o $@ $<
+
+gcc/drtend.o: gcc/drtstuff.c
+	$(COMPILE) -DDRT_END -c -o $@ $<
+endif
+
 # Generated by configure
 ALL_DRUNTIME_COMPILE_DSOURCES += $(DRUNTIME_DSOURCES_GENERATED)
 
@@ -104,14 +118,16 @@  endif
 toolexeclib_LTLIBRARIES = libgdruntime.la
 libgdruntime_la_SOURCES = $(ALL_DRUNTIME_SOURCES)
 libgdruntime_la_LIBTOOLFLAGS =
-libgdruntime_la_LDFLAGS = -Xcompiler -nophoboslib -version-info $(libtool_VERSION)
+libgdruntime_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../src,-Bgcc \
+    -version-info $(libtool_VERSION)
 libgdruntime_la_LIBADD = $(LIBATOMIC) $(LIBBACKTRACE)
+libgdruntime_la_DEPENDENCIES = $(DRTSTUFF)
 
 # For static unittest, link objects directly
 unittest_static_SOURCES = ../testsuite/test_runner.d $(DRUNTIME_CSOURCES) \
     $(DRUNTIME_SSOURCES)
 unittest_static_LIBTOOLFLAGS =
-unittest_static_LDFLAGS = -Xcompiler -nophoboslib
+unittest_static_LDFLAGS = -Wc,-nophoboslib
 unittest_static_LDADD = $(DRUNTIME_TEST_OBJECTS) $(LIBATOMIC) $(LIBBACKTRACE)
 EXTRA_unittest_static_DEPENDENCIES = $(DRUNTIME_TEST_OBJECTS)
 
@@ -120,14 +136,14 @@  libgdruntime_t_la_SOURCES = $(DRUNTIME_C
 libgdruntime_t_la_LIBTOOLFLAGS =
 # Automake by default does not generate shared libs for non-installed
 # libraries. Use -rpath to force shared lib generation.
-libgdruntime_t_la_LDFLAGS = -Xcompiler -nophoboslib -rpath /foo -shared
+libgdruntime_t_la_LDFLAGS = -Wc,-nophoboslib -rpath /foo -shared
 libgdruntime_t_la_LIBADD = $(DRUNTIME_TEST_LOBJECTS) $(LIBATOMIC) $(LIBBACKTRACE)
 EXTRA_libgdruntime_t_la_DEPENDENCIES = $(DRUNTIME_TEST_LOBJECTS)
 
 # For unittest
 unittest_SOURCES = ../testsuite/test_runner.d
 unittest_LIBTOOLFLAGS =
-unittest_LDFLAGS = -Xcompiler -nophoboslib
+unittest_LDFLAGS = -Wc,-nophoboslib
 unittest_LDADD = libgdruntime_t.la
 
 # Extra install and clean rules.
diff --git a/libphobos/libdruntime/gcc/drtstuff.c b/libphobos/libdruntime/gcc/drtstuff.c
new file mode 100644
--- /dev/null
+++ b/libphobos/libdruntime/gcc/drtstuff.c
@@ -0,0 +1,16 @@ 
+/* FIXME: Needs comment, copyright.  */
+
+/* Avoid interference with target without support for named sections.  */
+#ifdef __ELF__
+
+#ifdef DRT_BEGIN
+void *__start_minfo[]
+__attribute__((used, section("minfo"), aligned(sizeof(void *)))) = { };
+#endif
+
+#ifdef DRT_END
+void *__stop_minfo[]
+__attribute__((used, section("minfo"), aligned(sizeof(void *)))) = { };
+#endif
+
+#endif /* __ELF__ */
diff --git a/libphobos/libdruntime/rt/sections_elf_shared.d b/libphobos/libdruntime/rt/sections_elf_shared.d
--- a/libphobos/libdruntime/rt/sections_elf_shared.d
+++ b/libphobos/libdruntime/rt/sections_elf_shared.d
@@ -347,7 +347,6 @@  else
 ///////////////////////////////////////////////////////////////////////////////
 
 import gcc.config;
-static assert(Minfo_Bracketing, "Can't use _d_dso_registry interface");
 
 /*
  * This data structure is generated by the compiler, and then passed to
diff --git a/libphobos/m4/druntime/os.m4 b/libphobos/m4/druntime/os.m4
--- a/libphobos/m4/druntime/os.m4
+++ b/libphobos/m4/druntime/os.m4
@@ -180,6 +180,7 @@  AC_DEFUN([DRUNTIME_OS_MINFO_BRACKETING],
     [AC_MSG_RESULT([no])
      DCFG_MINFO_BRACKETING=false])
   AC_SUBST(DCFG_MINFO_BRACKETING)
+  AM_CONDITIONAL([DRUNTIME_OS_MINFO_BRACKETING], [test "$DCFG_MINFO_BRACKETING" = "true"])
   AC_LANG_POP([C])
 ])
 
diff --git a/libphobos/src/Makefile.am b/libphobos/src/Makefile.am
--- a/libphobos/src/Makefile.am
+++ b/libphobos/src/Makefile.am
@@ -57,14 +57,15 @@  toolexeclib_DATA = libgphobos.spec
 toolexeclib_LTLIBRARIES = libgphobos.la
 libgphobos_la_SOURCES = $(ALL_PHOBOS_SOURCES) $(ZLIB_SRC)
 libgphobos_la_LIBTOOLFLAGS =
-libgphobos_la_LDFLAGS = -Xcompiler -nophoboslib -version-info $(libtool_VERSION)
+libgphobos_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../libdruntime/gcc \
+    -version-info $(libtool_VERSION)
 libgphobos_la_LIBADD = ../libdruntime/libgdruntime.la
 libgphobos_la_DEPENDENCIES = libgphobos.spec
 
 # For static unittest, link objects directly
 unittest_static_SOURCES = ../testsuite/test_runner.d $(ZLIB_SRC)
 unittest_static_LIBTOOLFLAGS =
-unittest_static_LDFLAGS = -Xcompiler -nophoboslib -static-libtool-libs
+unittest_static_LDFLAGS = -Wc,-nophoboslib -static-libtool-libs
 unittest_static_LDADD = $(PHOBOS_TEST_OBJECTS) \
     ../libdruntime/libgdruntime.la
 EXTRA_unittest_static_DEPENDENCIES = $(PHOBOS_TEST_OBJECTS)
@@ -72,7 +73,7 @@  EXTRA_unittest_static_DEPENDENCIES = $(P
 # For unittest with dynamic library
 libgphobos_t_la_SOURCES = $(ZLIB_SRC)
 libgphobos_t_la_LIBTOOLFLAGS =
-libgphobos_t_la_LDFLAGS = -Xcompiler -nophoboslib -rpath /foo -shared
+libgphobos_t_la_LDFLAGS = -Wc,-nophoboslib -rpath /foo -shared
 libgphobos_t_la_LIBADD = $(PHOBOS_TEST_LOBJECTS) \
     ../libdruntime/libgdruntime.la
 EXTRA_libgphobos_t_la_DEPENDENCIES = $(PHOBOS_TEST_LOBJECTS)
@@ -80,7 +81,7 @@  EXTRA_libgphobos_t_la_DEPENDENCIES = $(P
 # For unittest
 unittest_SOURCES = ../testsuite/test_runner.d
 unittest_LIBTOOLFLAGS =
-unittest_LDFLAGS = -Xcompiler -nophoboslib -shared
+unittest_LDFLAGS = -Wc,-nophoboslib -shared
 unittest_LDADD = libgphobos_t.la ../libdruntime/libgdruntime.la
 
 # Extra install and clean rules.
diff --git a/libphobos/src/drtstuff.spec b/libphobos/src/drtstuff.spec
new file mode 100644
--- /dev/null
+++ b/libphobos/src/drtstuff.spec
@@ -0,0 +1,5 @@ 
+%rename startfile startfile_orig
+*startfile: %(startfile_orig) drtbegin.o%s
+
+%rename endfile endfile_orig
+*endfile: %(endfile_orig) drtend.o%s
diff --git a/libphobos/src/libgphobos.spec.in b/libphobos/src/libgphobos.spec.in
--- a/libphobos/src/libgphobos.spec.in
+++ b/libphobos/src/libgphobos.spec.in
@@ -6,6 +6,7 @@ 
 
 %rename link linkorig_gdc_renamed
 *link: %(linkorig_gdc_renamed) @OS_LINK_SPEC@
+@DRTSTUFF_SPEC@
 
 %rename lib liborig_gdc_renamed
-*lib: @SPEC_PHOBOS_DEPS@ %(liborig_gdc_renamed)
+*lib: %{debuglib|defaultlib|nophoboslib: ; :@SPEC_PHOBOS_DEPS@} %(liborig_gdc_renamed)
diff --git a/libphobos/testsuite/testsuite_flags.in b/libphobos/testsuite/testsuite_flags.in
--- a/libphobos/testsuite/testsuite_flags.in
+++ b/libphobos/testsuite/testsuite_flags.in
@@ -40,6 +40,7 @@  case ${query} in
       ;;
     --gdcldflags)
       GDCLDFLAGS="-B${BUILD_DIR}/src
+                  -B${BUILD_DIR}/libdruntime/gcc
                   -L${BUILD_DIR}/libdruntime/.libs
                   -L${BUILD_DIR}/src/.libs"
       echo ${GDCLDFLAGS}