From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4934 Path: news.gmane.org!not-for-mail From: "writeonce@midipix.org" Newsgroups: gmane.linux.lib.musl.general Subject: Re: static musl-based gdb and -fPIC Date: Sun, 20 Apr 2014 17:39:37 -0400 Message-ID: <53543E99.1020407@midipix.org> References: <5353FDD0.6090903@midipix.org> <20140420203140.GA26358@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1398029994 1402 80.91.229.3 (20 Apr 2014 21:39:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 20 Apr 2014 21:39:54 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-4938-gllmg-musl=m.gmane.org@lists.openwall.com Sun Apr 20 23:39:50 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1WbzSn-0004FB-BE for gllmg-musl@plane.gmane.org; Sun, 20 Apr 2014 23:39:49 +0200 Original-Received: (qmail 9419 invoked by uid 550); 20 Apr 2014 21:39:48 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 9408 invoked from network); 20 Apr 2014 21:39:47 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 In-Reply-To: <20140420203140.GA26358@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:4934 Archived-At: On 04/20/2014 04:31 PM, Rich Felker wrote: > On Sun, Apr 20, 2014 at 01:03:12PM -0400, writeonce@midipix.org wrote: >> Greetings, >> >> While building a statically linked musl-based gdb, ld asked that >> libc.a be recompiled with -fPIC. > This is a bug in the gdb build process. Despite your request for a > static gdb, it's trying to build a shared library for something. > There's a way to disable it (IIRC --disable-gdbserver is a big hammer > that can do it, and there might be a more fine-grained approach) but > the real issue is that the build process is broken and doing something > that can't work. Thanks! The offending part was indeed in gdbserver. With --disable-gdbserver, -fPIC is no longer necessary. Looking into this, I thought the problem lied in gdb/gdbserver/Makefile.in LDFLAGS = @LDFLAGS@ INTERNAL_LDFLAGS = $(LDFLAGS) @RDYNAMIC@ however removing @RDYNAMIC@ did not solve the issue, so for the time being gdbserver will have to be disabled. For the record: python's Modules/posixmodule.c has a static implementation of posix_close that is incompatible with musl's. My first take on that was to make python use musl's posix_close, which resulted in a very subtle bug leading to a segmentation fault (not to mention all of those lost hours...) Renaming the module's posix_close to __posix_close solved the problem. The code that triggered the bug was import subprocess subprocess.Popen(['ls']) With the newer approach (__posix_close) everything seems to work fine. Thanks again, zg > >> After recompiling musl with the >> above flag, gdb built successfully. The reason I wanted to have a >> static gdb (other than the trivial ones) was to be able to debug a >> musl-based python. The distribution's gdb has a dynamic dependency >> on a glibc-based libpython, and the two friends don't play well >> together. >> >> Now that the static gdb is up and running, my questions are: >> >> 1) is there any reason not to "always" compile musl with -fPIC, at >> least on x86_64? > Compare the .lo and .o files. I think you'll find the .lo files are a > considerably more bloated and slower -- not as bad as on 32-bit x86, > but still undesirable. > > Some users will want to use -fPIC even for static linking to be able > to produce static PIE binaries, but this is not a mainstream usage > (there's not even any official toolchain support for it, just a local > hack I posted to the list a year or two back) and not something we > would want to impose on everyone. > >> 2) is there any reason to revert to the old build of libc.so? >> Although I rebuilt musl because of libc.a, it turns out that the >> -fPIC flag also helped libc.so become much smaller: 699299 bytes, >> instead of 2767910 bytes (musl v1.0.0, binutils v2.24). Any other >> factors to consider? > You must have done something else like disabling debugging info at the > same time. > > Rich > >