Richard Henderson <r...@redhat.com> writes: > On 11/21/2011 09:23 AM, Rainer Orth wrote: >> Richard Henderson <r...@redhat.com> writes: >> >>> This is only ok if the compiler and library are build with default options. >>> If you use --with-arch=corei7-avx then we may well use AVX insns all through >>> the library, not just in the one interface that will only be used if the >>> user of the library is using avx. >>> >>> Can you auto-foo this based on CC+CFLAGS? E.g. compile-time tests for the >>> various __SSE__ / __AVX__ macros? >> >> Probably, but it occured to me that it might be easier to just apply the >> mapfile to x86_avx.o unconditionally before linking libitm.la. > > Possibly. Though you'd want to do the same thing for x86_sse.o too. > Again, that file is only used if the main program uses SSE.
The ld -r route for x86_avx.o has failed completely due to several libtool bugs, so I'm back to your suggestion. I didn't check for __SSE__, though: Solaris 10 is the first release where both as and ld have hwcap support, and it requires SSE-capable hardware to run. The following patch has been bootstrapped without regressions on i386-pc-solaris2.11 with as/ld, gas/ld, and gas/gld and fixes the hwcap-related execution failures in the first case. Besides, I've configured libitm with CFLAGS='-g -O2 -mavx' and verified that LDFLAGS_HWCAP is cleared/not applied in this case. I've kept the LIBITM_CHECK_LINKER_HWCAP test and the __AVX__ check separate since the former is generic (with the exception of the mapfile name), while the latter is strictly libitm-specific. Ok for mainline? Rainer 2011-11-18 Rainer Orth <r...@cebitec.uni-bielefeld.de> * clearcap.map: New file. * acinclude.m4 (LIBITM_CHECK_LINKER_HWCAP): New test. * configure.ac: Call it. Clear HWCAP_LDFLAGS if defaulting to -mavx. * Makefile.am (AM_LDFLAGS): Add $(HWCAP_LDFLAGS) * configure: Regenerate. * Makefile.in: Regenerate. * testsuite/Makefile.in: Regenerate.
# HG changeset patch # Parent 645b88e3e02144a637127f3a7c4842ef8afb2bcb Clear hardware capabilities on libitm.so with Sun ld diff --git a/libitm/Makefile.am b/libitm/Makefile.am --- a/libitm/Makefile.am +++ b/libitm/Makefile.am @@ -21,7 +21,7 @@ AM_CFLAGS = $(XCFLAGS) AM_CXXFLAGS = $(XCFLAGS) -std=gnu++0x -funwind-tables -fno-exceptions \ -fno-rtti $(abi_version) AM_CCASFLAGS = $(XCFLAGS) -AM_LDFLAGS = $(XLDFLAGS) $(SECTION_LDFLAGS) $(OPT_LDFLAGS) +AM_LDFLAGS = $(XLDFLAGS) $(SECTION_LDFLAGS) $(OPT_LDFLAGS) $(HWCAP_LDFLAGS) toolexeclib_LTLIBRARIES = libitm.la nodist_toolexeclib_HEADERS = libitm.spec diff --git a/libitm/acinclude.m4 b/libitm/acinclude.m4 --- a/libitm/acinclude.m4 +++ b/libitm/acinclude.m4 @@ -261,6 +261,36 @@ AC_DEFUN([LIBITM_CHECK_LINKER_FEATURES], dnl +dnl Check if the linker used supports linker maps to clear hardware +dnl capabilities. This is only supported by Sun ld at the moment. +dnl +dnl Defines: +dnl HWCAP_LDFLAGS='-Wl,-M,clearcap.map' if possible +dnl LD (as a side effect of testing) +dnl +AC_DEFUN([LIBITM_CHECK_LINKER_HWCAP], [ + test -z "$HWCAP_LDFLAGS" && HWCAP_LDFLAGS='' + AC_REQUIRE([AC_PROG_LD]) + + ac_save_LDFLAGS="$LDFLAGS" + LDFLAGS="$LFLAGS -Wl,-M,$srcdir/clearcap.map" + + AC_MSG_CHECKING([for ld that supports -Wl,-M,mapfile]) + AC_TRY_LINK([], [return 0;], [ac_hwcap_ldflags=yes],[ac_hwcap_ldflags=no]) + if test "$ac_hwcap_ldflags" = "yes"; then + HWCAP_LDFLAGS="-Wl,-M,$srcdir/clearcap.map $HWCAP_LDFLAGS" + fi + AC_MSG_RESULT($ac_hwcap_ldflags) + + LDFLAGS="$ac_save_LDFLAGS" + + AC_SUBST(HWCAP_LDFLAGS) + + AM_CONDITIONAL(HAVE_HWCAP, test $ac_hwcap_ldflags != no) +]) + + +dnl dnl Add version tags to symbols in shared library (or not), additionally dnl marking other symbols as private/local (or not). dnl diff --git a/libitm/clearcap.map b/libitm/clearcap.map new file mode 100644 --- /dev/null +++ b/libitm/clearcap.map @@ -0,0 +1,14 @@ +# Clear hardware capabilities emitted by Sun as: calls to the x86_avx.c +# functions are only emitted with -mavx. +# +# The v1 mapfile syntax has no support for clearing specific capabilities, +# so clear everything. +# +hwcap_1 = V0x0 OVERRIDE; +# +# If we can assume mapfile v2 syntax, we can specificially clear AVX. +# +#$mapfile_version 2 +#CAPABILITY { +# HW -= AVX; +#}; diff --git a/libitm/configure.ac b/libitm/configure.ac --- a/libitm/configure.ac +++ b/libitm/configure.ac @@ -1,5 +1,5 @@ # Process this file with autoreconf to produce a configure script. -# Copyright (C) 2011 Free Software Foundation, Inc. +# Copyright (C) 2011, 2012 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -208,12 +208,17 @@ GCC_LINUX_FUTEX(:) # See if we support thread-local storage. GCC_CHECK_TLS -# See what sort of export controls are availible. +# See what sort of export controls are available. LIBITM_CHECK_ATTRIBUTE_VISIBILITY LIBITM_CHECK_ATTRIBUTE_DLLEXPORT LIBITM_CHECK_ATTRIBUTE_ALIAS + +# Check linker hardware capability support. +LIBITM_CHECK_LINKER_HWCAP +# If defaulting to -mavx, don't clear hwcaps. +AC_CHECK_DECL([__AVX__], [HWCAP_LDFLAGS='']) + LIBITM_ENABLE_SYMVERS - if test $enable_symvers = gnu; then AC_DEFINE(LIBITM_GNU_SYMBOL_VERSIONING, 1, [Define to 1 if GNU symbol versioning is used for libitm.])
-- ----------------------------------------------------------------------------- Rainer Orth, Center for Biotechnology, Bielefeld University