From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13494 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: static linking problem Date: Sat, 1 Dec 2018 19:18:21 -0500 Message-ID: <20181202001821.GV23599@brightrain.aerifal.cx> References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1543709792 30794 195.159.176.226 (2 Dec 2018 00:16:32 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 2 Dec 2018 00:16:32 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) Cc: argante To: musl@lists.openwall.com Original-X-From: musl-return-13510-gllmg-musl=m.gmane.org@lists.openwall.com Sun Dec 02 01:16:28 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1gTFQw-0007sb-Fy for gllmg-musl@m.gmane.org; Sun, 02 Dec 2018 01:16:26 +0100 Original-Received: (qmail 5970 invoked by uid 550); 2 Dec 2018 00:18:35 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 5951 invoked from network); 2 Dec 2018 00:18:34 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:13494 Archived-At: On Sat, Dec 01, 2018 at 10:07:53PM +0000, argante wrote: > Hi, > > Does anyone have any idea why this is happening? The compiler (7.3.0) doesn't produce a statically linked binaries. > > # cat test.c > #include > int main() { printf("hello..\n"); return 0; } > # gcc -static test.c > # ldd a.out > ldd (0x7f67f767e000) > # readelf -d a.out > > Dynamic section at offset 0x1e88 contains 16 entries: > Tag Type Name/Value > 0x0000000000000010 (SYMBOLIC) 0x0 > 0x000000000000000c (INIT) 0x290 > 0x000000000000000d (FINI) 0x1207 > 0x0000000000000004 (HASH) 0x158 > 0x0000000000000005 (STRTAB) 0x180 > 0x0000000000000006 (SYMTAB) 0x168 > 0x000000000000000a (STRSZ) 1 (bytes) > 0x000000000000000b (SYMENT) 24 (bytes) > 0x0000000000000015 (DEBUG) 0x0 > 0x0000000000000003 (PLTGOT) 0x202000 > 0x0000000000000007 (RELA) 0x188 > 0x0000000000000008 (RELASZ) 264 (bytes) > 0x0000000000000009 (RELAENT) 24 (bytes) > 0x000000006ffffffb (FLAGS_1) Flags: PIE > 0x000000006ffffff9 (RELACOUNT) 11 > 0x0000000000000000 (NULL) 0x0 This does not indicate that the program is dynamic-linked, just that it's PIE. Use readelf -l and look for INTERP. If it's present, the program is dynamic linked. If it's absent, the program is static linked. > # /usr/local/musl/bin/musl-gcc -static test.c > # ldd a.out > ldd (0x7f5a608f9000) > # gcc -static -specs=/lib/musl-gcc.specs test.c > # ldd a.out > ldd (0x7fb6c936f000) Is this the musl ldd? I believe it will do this or similar, and that's a known bug or at least limitation. It should report that the program is not dynamic-linked. > # gcc -v > Using built-in specs. > COLLECT_GCC=gcc > COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-linux-musl/7.3.0/lto-wrapper > Target: x86_64-linux-musl > Configured with: ./configure CFLAGS='-Os -g0' CXXFLAGS= --enable-languages=c,c++ --disable-nls --disable-multilib --disable-werror --disable-libmudflap --disable-libsanitizer --disable-gnu-indirect-function --disable-libmpx --disable-libssp --disable-symver --disable-libgomp --disable-fixed-point --enable-tls --enable-deterministic-archives --enable-__cxa_atexit --enable-default-pie --build=x86_64-linux-musl > Thread model: posix > gcc version 7.3.0 (GCC) > > > without '-static' everything looks ok > > # gcc test.c > # ldd a.out > /lib/ld-musl-x86_64.so.1 (0x7ff0dca25000) > libc.so => /lib/ld-musl-x86_64.so.1 (0x7ff0dca25000) This is dynamic-linked, yes. But there's nothing wrong with your static-linked program. If you really don't want pie, use -no-pie or a toolchain that wasn't built to produce pie by default (gcc's --enable-default-pie option at configure time). Rich