Hi Iain, > On Tue, 29 Jan 2019 at 13:24, Rainer Orth <r...@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 <r...@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}