This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: differences in generated ldscripts for native and cross builds
- From: Thomas Schwinge <thomas at codesourcery dot com>
- To: Alan Modra <amodra at gmail dot com>
- Cc: Joseph Myers <joseph at codesourcery dot com>, "H.J. Lu" <hjl dot tools at gmail dot com>, Matthias Klose <doko at debian dot org>, binutils <binutils at sourceware dot org>
- Date: Sun, 6 Dec 2015 21:00:41 +0100
- Subject: Re: differences in generated ldscripts for native and cross builds
- Authentication-results: sourceware.org; auth=none
- References: <5617620A dot 1000207 at debian dot org> <20151009121555 dot GD4434 at bubble dot grove dot modra dot org> <20151011185623 dot GB5535 at vapier dot lan> <CAMe9rOpun+eOzmE=6xMdiGRaZtT-DzAjKy8gEnKwOqw1__Rrug at mail dot gmail dot com> <alpine dot DEB dot 2 dot 10 dot 1510121659430 dot 6267 at digraph dot polyomino dot org dot uk> <87lhb7aug1 dot fsf at schwinge dot name> <20151202085951 dot GF5966 at bubble dot grove dot modra dot org>
Hi!
On Wed, 2 Dec 2015 19:29:51 +1030, Alan Modra <amodra@gmail.com> wrote:
> On Tue, Oct 13, 2015 at 01:17:50PM +0200, Thomas Schwinge wrote:
> > On Mon, 12 Oct 2015 17:04:21 +0000, Joseph Myers <joseph@codesourcery.com> wrote:
> > > On Sun, 11 Oct 2015, H.J. Lu wrote:
> > >
> > > > >> Try adding --enable-initfini-array to the cross configuration. The
> > > > >> autoconf test for this option uses AC_RUN_IFELSE so only works on
> > > > >> native builds.
> > > > >
> > > > > can't we make this smarter ? this feature has been around for quite
> > > > > a long time now. seems crazy that the default is to disable these
> > > > > when cross-compiling.
> > > >
> > > > Yes, the default should be ON for Linux targets.
> > >
> > > Thomas, I think you had plans to work on that at some point....
> >
> > Yes, in 2012-07... :-| Unfortunately, that never happened, and is very
> > unlikely to be happening anytime soon.
> >
> > > As I said in <https://gcc.gnu.org/ml/gcc-patches/2013-11/msg00619.html> I
> > > think it should be on by default for ELF targets, not limited to GNU/Linux
> > > or GNU targets.
> >
> > Yes, per my notes,
> > <http://news.gmane.org/find-root.php?message_id=%3C20120118232441.GO18768%40tyan-ft48-01.lab.bos.redhat.com%3E>
> > and
> > <http://news.gmane.org/find-root.php?message_id=%3CPine.LNX.4.64.1311061831350.13465%40digraph.polyomino.org.uk%3E>
> > were two relevant discussion threads.
>
> I think it's time we defaulted to --enable-initfini-array, at least for
> binutils-2.27.
Makes sense to me (only for systems where it's supported, of course).
As it happens, while cleaning up old directories on one system, I found
this patch, from 2012-06-30 (so, status unclear, untested), just in case
this is of any help:
diff --git ld/aclocal.m4 ld/aclocal.m4
index 6585160..f51947a 100644
--- ld/aclocal.m4
+++ ld/aclocal.m4
@@ -993,6 +993,7 @@ m4_include([../bfd/acinclude.m4])
m4_include([../bfd/warning.m4])
m4_include([../config/acx.m4])
m4_include([../config/depstand.m4])
+m4_include([../config/elf.m4])
m4_include([../config/gettext-sister.m4])
m4_include([../config/largefile.m4])
m4_include([../config/lcmessage.m4])
diff --git ld/configure.in ld/configure.in
index b844927..4ad193c 100644
--- ld/configure.in
+++ ld/configure.in
@@ -194,6 +194,10 @@ AC_ARG_ENABLE(initfini-array,
[], [
AC_CACHE_CHECK(for .preinit_array/.init_array/.fini_array support,
gcc_cv_initfini_array, [dnl
+ # Set an optimistic default value for ELF targets.
+ ACX_ELF_TARGET_IFELSE([gcc_cv_initfini_array=yes],
+ [gcc_cv_initfini_array=no])
+ # If we can, do a run-time test.
if test "x${build}" = "x${target}" ; then
AC_RUN_IFELSE([AC_LANG_SOURCE([
static int x = -1;
@@ -201,10 +205,8 @@ int main (void) { return x; }
int foo (void) { x = 0; }
int (*fp) (void) __attribute__ ((section (".init_array"))) = foo;])],
[gcc_cv_initfini_array=yes], [gcc_cv_initfini_array=no],
- [gcc_cv_initfini_array=no])
- else
- gcc_cv_initfini_array=no
- fi])
+ [:])
+ fi])
enable_initfini_array=$gcc_cv_initfini_array
])
AC_SUBST(enable_initfini_array)
For reference, your patch:
> * configure.ac (--enable-initfini-array): Remove run test. Default
> to "yes". Change help string to --disable-initfini-array.
> * configure: Regenerate.
>
> diff --git a/ld/configure.ac b/ld/configure.ac
> index 188172d..d61beb2 100644
> --- a/ld/configure.ac
> +++ b/ld/configure.ac
> @@ -215,23 +215,11 @@ AC_SEARCH_LIBS([dlopen], [dl])
> AM_CONDITIONAL([ENABLE_PLUGINS], [test x$plugins = xyes])
>
> AC_ARG_ENABLE(initfini-array,
> - [ --enable-initfini-array use .init_array/.fini_array sections],
> - [], [
> -AC_CACHE_CHECK(for .preinit_array/.init_array/.fini_array support,
> - gcc_cv_initfini_array, [dnl
> - if test "x${build}" = "x${target}" ; then
> - AC_RUN_IFELSE([AC_LANG_SOURCE([
> -static int x = -1;
> -int main (void) { return x; }
> -int foo (void) { x = 0; }
> -int (*fp) (void) __attribute__ ((section (".init_array"))) = foo;])],
> - [gcc_cv_initfini_array=yes], [gcc_cv_initfini_array=no],
> - [gcc_cv_initfini_array=no])
> - else
> - gcc_cv_initfini_array=no
> - fi])
> - enable_initfini_array=$gcc_cv_initfini_array
> -])
> +[ --disable-initfini-array do not use .init_array/.fini_array sections],
> +[case "${enableval}" in
> + yes|no) ;;
> + *) AC_MSG_ERROR([invalid --enable-initfini-array argument]) ;;
> + esac], [enable_initfini_array=yes])
> AC_SUBST(enable_initfini_array)
> if test $enable_initfini_array = yes; then
> AC_DEFINE(HAVE_INITFINI_ARRAY, 1,
GrÃÃe
Thomas