From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13497 Path: news.gmane.org!.POSTED!not-for-mail From: argante Newsgroups: gmane.linux.lib.musl.general Subject: Re: static linking problem Date: Sun, 02 Dec 2018 19:25:56 +0000 Message-ID: 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: quoted-printable X-Trace: blaine.gmane.org 1543778654 2100 195.159.176.226 (2 Dec 2018 19:24:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 2 Dec 2018 19:24:14 +0000 (UTC) To: "musl@lists.openwall.com" Original-X-From: musl-return-13513-gllmg-musl=m.gmane.org@lists.openwall.com Sun Dec 02 20:24:10 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 1gTXLd-0000P1-2j for gllmg-musl@m.gmane.org; Sun, 02 Dec 2018 20:24:09 +0100 Original-Received: (qmail 20017 invoked by uid 550); 2 Dec 2018 19:26:18 -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 19998 invoked from network); 2 Dec 2018 19:26:17 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=proton; t=1543778759; bh=AfM5BEBPLm2AMO5lb+3w1+qTDz72Va1604f6jBkE1gk=; h=Date:To:From:Reply-To:Subject:In-Reply-To:References:Feedback-ID: From; b=I6wXZhiyc4v7gVUI+WvlEarljNLFM+qj1SrbRRsZQ1RyeG9SdNmETJ37K3/NyOFYJ eTMkWQNy7NHPWLI4xojC2d4bcOgwN7vcMVlmqpqEgu/smeNMSleaiBaQd2wPc75UkD sVKc4FhWS5BqS3N2w/pTz/AtsZFArs0SNUYXZTjDK08Hf10oHnCu+8fi6XZ3TrGzIP 6iTs5XavwAFSSRkLqBS6437XGMkQC9VsLjGD7m2A+yC8SQYOH8BRDLyVrPb+a/NxTj m+6pdGnUi9t4si+KluiagxYuHAHqMB14qK0LL/YYkO/0Sm32F1RkOmV4J2ACnUmq9G sydTRt1aY5MdQ== In-Reply-To: <20181202181503.GT21289@port70.net> Feedback-ID: sj1YN_iN560_iv4ir5EpCpCFj2RELVzNnBQpDIwMoUMNXowIBSidTdxSWFyLT3J_uOeJsE1taahISy929bGTAA==:Ext:ProtonMail Xref: news.gmane.org gmane.linux.lib.musl.general:13497 Archived-At: =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 Original Me= ssage =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 On Sunday, 2 December 2018 19:15, Szabolcs Nagy wrote: > * argante argante@ [2018-12-02 17:20:15 +0000]: > > > =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 Origina= l Message =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80= =90 > > 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 =3D> /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=3D"-Os -g0" \ > > CXXFLAGS=3D"${CFLAGS}" \ > > --enable-languages=3Dc,c++ \ > > --enable-default-pie \ > > ^^^^^^^^^^^^^^^^^^^^^ > > > I still can't understand why musl-cross ldd works correctly, and new to= olchain 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 th= e same: # gcc -v Using built-in specs. COLLECT_GCC=3Dgcc COLLECT_LTO_WRAPPER=3D/usr/libexec/gcc/x86_64-alpine-linux-musl/6.4.0/lto-w= rapper Target: x86_64-alpine-linux-musl Configured with: /home/buildozer/aports/main/gcc/src/gcc-6.4.0/configure --= prefix=3D/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 =09ldd (0x7f02ef28d000) =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 Original Me= ssage =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 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 > > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > > > 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=3D/usr/x86_64-gentoo-linux-musl/gcc-bin/7.3.0/gcc COLLECT_LTO_WRAPPER=3D/usr/libexec/gcc/x86_64-gentoo-linux-musl/7.3.0/lto-w= rapper Target: x86_64-gentoo-linux-musl Configured with: /var/tmp/portage/sys-devel/gcc-7.3.0-r3/work/gcc-7.3.0/con= figure --host=3Dx86_64-gentoo-linux-musl --build=3Dx86_64-gentoo-linux-musl= --prefix=3D/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. thx