Re: [PATCH 3/8] intl: always picify

2021-02-10 Thread Alan Modra via Gcc-patches
On Mon, Feb 08, 2021 at 11:16:30AM +, Nick Alcock via Binutils wrote:
> intl/ChangeLog
> 2021-02-02  Nick Alcock  
> 
>   * aclocal.m4: include picflag.m4.
>   * configure.ac (PICFLAG): Add and substitute.
>   * Makefile.in (PICFLAG): New.
>   (COMPILE): Use it.
>   * configure: Regenerate.

OK for binutils.

-- 
Alan Modra
Australia Development Lab, IBM


[PATCH 3/8] intl: always picify

2021-02-08 Thread Nick Alcock via Gcc-patches
libintl is included in several shared libraries (at least
libinproctrace.so and libctf.so): unconditionally picify with code
borrowed from libiberty configure.  (It's not performance-critical, so
don't bother making separate PIC and non-PIC libraries like libiberty
does.)

Cc: gcc-patc...@gnu.org

intl/ChangeLog
2021-02-02  Nick Alcock  

* aclocal.m4: include picflag.m4.
* configure.ac (PICFLAG): Add and substitute.
* Makefile.in (PICFLAG): New.
(COMPILE): Use it.
* configure: Regenerate.
---
 intl/Makefile.in  |  3 +-
 intl/aclocal.m4   |  1 +
 intl/configure| 86 +++
 intl/configure.ac |  5 +++
 4 files changed, 94 insertions(+), 1 deletion(-)

diff --git a/intl/Makefile.in b/intl/Makefile.in
index 356c8ab9b65..96df727baea 100644
--- a/intl/Makefile.in
+++ b/intl/Makefile.in
@@ -49,8 +49,9 @@ CFLAGS = @CFLAGS@
 LDFLAGS = @LDFLAGS@
 LIBS = @LIBS@
 DEFS = -DHAVE_CONFIG_H
+PICFLAG = @PICFLAG@
 
-COMPILE = $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(DEFS-$@) $(INCLUDES)
+COMPILE = $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PICFLAG) $(DEFS) $(DEFS-$@) 
$(INCLUDES)
 
 HEADERS = \
   gmo.h \
diff --git a/intl/aclocal.m4 b/intl/aclocal.m4
index 473ec622323..0a42b42ea8c 100644
--- a/intl/aclocal.m4
+++ b/intl/aclocal.m4
@@ -26,6 +26,7 @@ m4_include([../config/lib-link.m4])
 m4_include([../config/lib-prefix.m4])
 m4_include([../config/nls.m4])
 m4_include([../config/override.m4])
+m4_include([../config/picflag.m4])
 m4_include([../config/po.m4])
 m4_include([../config/progtest.m4])
 m4_include([../config/stdint_h.m4])
diff --git a/intl/configure b/intl/configure
index d69767b7d21..6498a392570 100755
--- a/intl/configure
+++ b/intl/configure
@@ -624,6 +624,7 @@ ac_subst_vars='LTLIBOBJS
 LIBOBJS
 BISON3_NO
 BISON3_YES
+PICFLAG
 INCINTL
 LIBINTL_DEP
 MAINT
@@ -6793,6 +6794,91 @@ case $USE_INCLUDED_LIBINTL in
 ;;
 esac
 
+# intl is sometimes linked into shared libraries even without --enable-shared
+# (e.g. gdbsupport's inprocess agent): so always PICify, just in case.
+
+
+
+
+case "${host}" in
+# PIC is the default on some targets or must not be used.
+*-*-darwin*)
+   # For darwin, common symbols are not allowed in MH_DYLIB files
+   case "${CFLAGS}" in
+ # If we are using a compiler supporting mdynamic-no-pic
+ # and the option has been tested as safe to add, then cancel
+ # it here, since the code generated is incompatible with shared
+ # libs.
+ *-mdynamic-no-pic*) PICFLAG='-fno-common -mno-dynamic-no-pic' ;;
+ *) PICFLAG=-fno-common ;;
+   esac
+   ;;
+alpha*-dec-osf5*)
+   # PIC is the default.
+   ;;
+hppa*64*-*-hpux*)
+   # PIC is the default for 64-bit PA HP-UX.
+   ;;
+i[34567]86-*-cygwin* | x86_64-*-cygwin*)
+   ;;
+i[34567]86-*-mingw* | x86_64-*-mingw*)
+   ;;
+i[34567]86-*-interix[3-9]*)
+   # Interix 3.x gcc -fpic/-fPIC options generate broken code.
+   # Instead, we relocate shared libraries at runtime.
+   ;;
+i[34567]86-*-nto-qnx*)
+   # QNX uses GNU C++, but need to define -shared option too, otherwise
+   # it will coredump.
+   PICFLAG='-fPIC -shared'
+   ;;
+i[34567]86-pc-msdosdjgpp*)
+   # DJGPP does not support shared libraries at all.
+   ;;
+ia64*-*-hpux*)
+   # On IA64 HP-UX, PIC is the default but the pic flag
+   # sets the default TLS model and affects inlining.
+   PICFLAG=-fPIC
+   ;;
+mips-sgi-irix6*)
+   # PIC is the default.
+   ;;
+rs6000-ibm-aix* | powerpc-ibm-aix*)
+   # All AIX code is PIC.
+   ;;
+
+# Some targets support both -fPIC and -fpic, but prefer the latter.
+# FIXME: Why?
+i[34567]86-*-* | x86_64-*-*)
+   PICFLAG=-fpic
+   ;;
+# FIXME: Override -fPIC default in libgcc only?
+sh-*-linux* | sh[2346lbe]*-*-linux*)
+   PICFLAG=-fpic
+   ;;
+# FIXME: Simplify to sh*-*-netbsd*?
+sh-*-netbsdelf* | shl*-*-netbsdelf* | sh5-*-netbsd* | sh5l*-*-netbsd* | \
+  sh64-*-netbsd* | sh64l*-*-netbsd*)
+   PICFLAG=-fpic
+   ;;
+# Default to -fPIC unless specified otherwise.
+*)
+   PICFLAG=-fPIC
+   ;;
+esac
+
+# If the user explicitly uses -fpic/-fPIC, keep that.
+case "${CFLAGS}" in
+*-fpic*)
+   PICFLAG=-fpic
+   ;;
+*-fPIC*)
+   PICFLAG=-fPIC
+   ;;
+esac
+
+
+
 BISON3_YES='#'
 BISON3_NO=
 if test "$INTLBISON" != :; then
diff --git a/intl/configure.ac b/intl/configure.ac
index 6363e55e68a..5ec7b0944e2 100644
--- a/intl/configure.ac
+++ b/intl/configure.ac
@@ -47,6 +47,11 @@ case $USE_INCLUDED_LIBINTL in
 ;;
 esac
 
+# intl is sometimes linked into shared libraries even without --enable-shared
+# (e.g. gdbsupport's inprocess agent): so always PICify, just in case.
+GCC_PICFLAG
+AC_SUBST(PICFLAG)
+
 BISON3_YES='#'
 BISON3_NO=
 if test "$INTLBISON" != :; then
-- 
2.30.0.252.gc27e85e57d