From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13498 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: static linking problem Date: Sun, 2 Dec 2018 16:16:19 -0500 Message-ID: <20181202211619.GW23599@brightrain.aerifal.cx> References: <20181202001821.GV23599@brightrain.aerifal.cx> <20181202181503.GT21289@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1543785284 31068 195.159.176.226 (2 Dec 2018 21:14:44 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 2 Dec 2018 21:14:44 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) Cc: "musl@lists.openwall.com" To: argante Original-X-From: musl-return-13514-gllmg-musl=m.gmane.org@lists.openwall.com Sun Dec 02 22:14:40 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 1gTZ4X-0007vK-L0 for gllmg-musl@m.gmane.org; Sun, 02 Dec 2018 22:14:37 +0100 Original-Received: (qmail 10130 invoked by uid 550); 2 Dec 2018 21:16:46 -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 10108 invoked from network); 2 Dec 2018 21:16:45 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:13498 Archived-At: On Sun, Dec 02, 2018 at 07:25:56PM +0000, argante wrote: > > ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ > On Sunday, 2 December 2018 19:15, Szabolcs Nagy wrote: > > > * argante argante@ [2018-12-02 17:20:15 +0000]: > > > > > ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ > > > On Sunday, 2 December 2018 01:18, Rich Felker dalias@ wrote: > > > > > > > On Sat, Dec 01, 2018 at 10:07:53PM +0000, argante wrote: > > > > > > > > > /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). > > > > > ./configure \ > > > CFLAGS="-Os -g0" \ > > > CXXFLAGS="${CFLAGS}" \ > > > --enable-languages=c,c++ \ > > > > --enable-default-pie \ > > > > ^^^^^^^^^^^^^^^^^^^^^ > > > > > I still can't understand why musl-cross ldd works correctly, and new toolchain shows such a strange result. Did I overlook something? I even tried -Wl,--no-dynamic-linker. > > > > what do you mean strange? > > > > it seems to work exactly as expected. > > > I checked Alpine, where there is also a default pie. Indeed, ldd behaves the same: > > # gcc -v > Using built-in specs. > COLLECT_GCC=gcc > COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-alpine-linux-musl/6.4.0/lto-wrapper > Target: x86_64-alpine-linux-musl > Configured with: /home/buildozer/aports/main/gcc/src/gcc-6.4.0/configure --prefix=/usr > .... > --enable-__cxa_atexit --enable-default-pie --enable-cloog-backend --enable- > ^^^^^^^^^^^^^^^^^^^^ > Thread model: posix > gcc version 6.4.0 (Alpine 6.4.0) > > # gcc -static test.c > # ldd a.out > ldd (0x7f02ef28d000) > > > ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ > On Sunday, 2 December 2018 01:18, Rich Felker wrote: > > > On Sat, Dec 01, 2018 at 10:07:53PM +0000, argante wrote: > > > > 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. > > > yes, this is musl ldd. > > > but Gentoo: > > # gcc -v > Using built-in specs. > COLLECT_GCC=/usr/x86_64-gentoo-linux-musl/gcc-bin/7.3.0/gcc > COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-gentoo-linux-musl/7.3.0/lto-wrapper > Target: x86_64-gentoo-linux-musl > Configured with: /var/tmp/portage/sys-devel/gcc-7.3.0-r3/work/gcc-7.3.0/configure --host=x86_64-gentoo-linux-musl --build=x86_64-gentoo-linux-musl --prefix=/usr > > .... > > --without-isl --disable-libsanitizer --enable-default-pie --enable-default-ssp > ^^^^^^^^^^^^^^^^^^^^ > Thread model: posix > gcc version 7.3.0 (Gentoo Hardened 7.3.0-r3 p1.4) > > > # gcc -static test.c > # ldd a.out > ldd: a.out: Not a valid dynamic program > # ls -l /usr/bin/ldd > lrwxrwxrwx 1 root root 24 Nov 13 21:27 /usr/bin/ldd -> /lib/ld-musl-x86_64.so.1 > > or: > > # gcc -c -fPIE test.c > # gcc -static -pie test.o > # ldd a.out > ldd: a.out: Not a valid dynamic program > # readelf -l a.out > > Elf file type is EXEC (Executable file) > Entry point 0x40014d > There are 4 program headers, starting at offset 64 > > Program Headers: > Type Offset VirtAddr PhysAddr > FileSiz MemSiz Flags Align > LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000 > 0x000000000000133c 0x000000000000133c R E 0x200000 > LOAD 0x0000000000001fd8 0x0000000000601fd8 0x0000000000601fd8 > 0x0000000000000130 0x0000000000000840 RW 0x200000 > GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000 > 0x0000000000000000 0x0000000000000000 RW 0x10 > GNU_RELRO 0x0000000000001fd8 0x0000000000601fd8 0x0000000000601fd8 > 0x0000000000000028 0x0000000000000028 R 0x1 > > Section to Segment mapping: > Segment Sections... > 00 .init .text .fini .rodata .eh_frame > 01 .ctors .dtors .data.rel.ro .data .bss > 02 > 03 .ctors .dtors .data.rel.ro > > > > that's why it seemed surprising to me. There is absolutely nothing wrong here. This is what a static pie looks like. I don't know what you expect but your expectations are wrong. Rich