From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 85937 invoked by alias); 25 Aug 2015 16:58:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 85913 invoked by uid 89); 25 Aug 2015 16:58:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.2 required=5.0 tests=AWL,BAYES_50,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_PASS,URIBL_BLACK autolearn=no version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: bes.se.axis.com Received: from bes.se.axis.com (HELO bes.se.axis.com) (195.60.68.10) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Aug 2015 16:58:35 +0000 Received: from localhost (localhost [127.0.0.1]) by bes.se.axis.com (Postfix) with ESMTP id 409A72E41C; Tue, 25 Aug 2015 18:58:33 +0200 (CEST) Received: from bes.se.axis.com ([IPv6:::ffff:127.0.0.1]) by localhost (bes.se.axis.com [::ffff:127.0.0.1]) (amavisd-new, port 10024) with LMTP id XFXAgAr8-BOX; Tue, 25 Aug 2015 18:58:32 +0200 (CEST) Received: from boulder.se.axis.com (boulder.se.axis.com [10.0.2.104]) by bes.se.axis.com (Postfix) with ESMTP id 9BB232E3DD; Tue, 25 Aug 2015 18:58:32 +0200 (CEST) Received: from boulder.se.axis.com (localhost [127.0.0.1]) by postfix.imss71 (Postfix) with ESMTP id 5678B116A; Tue, 25 Aug 2015 18:58:32 +0200 (CEST) Received: from thoth.se.axis.com (thoth.se.axis.com [10.0.2.173]) by boulder.se.axis.com (Postfix) with ESMTP id 4AC3FCF4; Tue, 25 Aug 2015 18:58:32 +0200 (CEST) Received: from ignucius.se.axis.com (ignucius.se.axis.com [10.88.21.50]) by thoth.se.axis.com (Postfix) with ESMTP id 46C1D34005; Tue, 25 Aug 2015 18:58:32 +0200 (CEST) Received: from ignucius.se.axis.com (localhost [127.0.0.1]) by ignucius.se.axis.com (8.12.8p1/8.12.8/Debian-2woody1) with ESMTP id t7PGwVBc005213; Tue, 25 Aug 2015 18:58:32 +0200 Received: (from hp@localhost) by ignucius.se.axis.com (8.12.8p1/8.12.8/Debian-2woody1) id t7PGwUk5005209; Tue, 25 Aug 2015 18:58:30 +0200 Date: Tue, 25 Aug 2015 17:09:00 -0000 Message-Id: <201508251658.t7PGwUk5005209@ignucius.se.axis.com> From: Hans-Peter Nilsson To: uweigand@de.ibm.com CC: ian@airs.com, fxcoudert@gmail.com, gcc-patches@gcc.gnu.org, ubizjak@gmail.com, fortran@gcc.gnu.org In-reply-to: <20150825125905.7F12F247E@oc7340732750.ibm.com> (message from Ulrich Weigand on Tue, 25 Aug 2015 14:59:05 +0200) Subject: Re: Fix libbacktrace -fPIC breakage from "Use libbacktrace in libgfortran" MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=iso-8859-1 Content-Transfer-Encoding: 8BIT X-SW-Source: 2015-08/txt/msg01525.txt.bz2 TL;DR: See last... > From: Ulrich Weigand > Date: Tue, 25 Aug 2015 14:59:05 +0200 > However, the compiler actually does accept -fPIC. If the flag is > present, we attempt to generate relocatable code, but only to the > extent the compiler can do that without support for run-time > relocations. The most significant restriction is that statically > initializing a global variable to a pointer will not work. > (This is useful for some special cases of self-relocating code. > Such code normally can work around this restriction.) Still, things like that is why I chose to emit a hard error for -fPIC/-fpic where it's not supported for *all* code... > Now, with the patch above, libbacktrace is still compiled with > -fPIC on SPU, but some files do in fact contain just such global > initializers, causing compilation to fail: > > gcc-head/src/libbacktrace/elf.c:241:27: error: creating run-time relocation for '*.LC2' > static const char * const debug_section_names[DEBUG_MAX] = > ^ > The other GCC run-time libraries rely on libtool to figure out > that even though -fPIC works, dynamic libraries are still not > supported on the platform, and thus compile everything for > static linking (i.e. without -fPIC). That's not what I see, at least not the "figuring out" part. (They mostly use libtool as-is; some test tuples, but some test version-script support and add it then.) > I'm wondering if we couldn't use the same libtool mechanism here: > if the architecture does not support dynamic linking at all, no > target library will be built as shared library, and thus there is > no need to build libbacktrace with -fPIC either. (My understanding > is that we need to build libbacktrace with -fPIC because it might > get linked into some other shared target library.) Yes, that's what the comment in the patch context says, as happens for libgfortran. > The libbacktrace configure script actually incorporates all the > libtool init code that makes this determination, and sets the > shell variable "can_build_shared" to "no" on SPU. Would it be > valid to use this variable in the test whether to use -fPIC? > (I'm not sure which of the many libtool variables are intended > to be used outside, and which are private ...) I momentarily pondered this too, when I found the libtool PIC-test-code grepping libtool/configure, but I chose the simpler TRY_COMPILE test partly for the same maybe-internal-variable reason. A visit to the libtool documentation shows can_build_shared is for some reason not listed among the documented variables and a STFW doesn't yield more information for the first few pages of hits (just some indexed random libtool copies). On the other hand, libtool.m4 is in the top directory, so we know if we switch to some version without can_build_shared. I'll leave that to you to sort out, but if you chose to use $can_build_shared, consider also setting PIC_FLAG to $pic_flag (instead of plain -fPIC). In the meantime I'll commit my patch as it solves *some* of the breakage; for targets erroring on -fPIC. ...but reading the libtool documention I think I found a much better solution: Let's just add -prefer-pic when compiling libbacktrace. It leaves everything to libtool. Can you please test this? libbacktrace: * configure.ac: Use libtool option -prefer-pic, not -fPIC. * configure: Regenerate. diff -upr /expvol/pp_slask/hp/checkout/gcchead/gcc/libbacktrace/configure.ac libbacktrace/configure.ac --- libbacktrace/configure.ac 2015-05-29 17:23:20.000000000 +0200 +++ libbacktrace/configure.ac 2015-08-24 17:31:18.000000000 +0200 @@ -163,10 +163,11 @@ fi # When building as a target library, shared libraries may want to link # this in. We don't want to provide another shared library to -# complicate dependencies. Instead, we just compile with -fPIC. +# complicate dependencies. Instead, we prefer PIC, if the target +# supports that through libtool. PIC_FLAG= if test -n "${with_target_subdir}"; then - PIC_FLAG=-fPIC + PIC_FLAG=-prefer-pic fi # Similarly, use -fPIC with --enable-host-shared: AC_ARG_ENABLE(host-shared, brgds, H-P