From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id 2C02A3858288 for ; Sat, 22 Oct 2022 14:25:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2C02A3858288 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1666448745; bh=mclwcMJze/+nD/qqZcvIlBlXhAyVmqlqEasORN91Cd0=; h=Subject:From:To:Date:In-Reply-To:References:From; b=VHkQfifikHmsT411mvC7pPQkgH0/cJB/i6Esxtg3ODuy2J1RUevcjyxQW5VXWn+xp EHF0yd+Zw5aSqBclOOxtTf4zIfi78vQ5eQkNdySbvmBTpHyEgTJmP352b0OvSi4wPz +IZsSMLK4DcsejyidBvLZSSu4iQhans5bmDGcD9M= Received: from localhost.localdomain (xry111.site [IPv6:2001:470:683e::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 9304065DD0; Sat, 22 Oct 2022 10:25:43 -0400 (EDT) Message-ID: <6ba3b8ba096fadec66822e2e1f712777b524f66c.camel@xry111.site> Subject: Re: static pie: confusion between _DYNAMIC, crt1.o, Scrt1.o From: Xi Ruoyao To: Samuel Thibault , libc-alpha@sourceware.org, glibc@packages.debian.org Date: Sat, 22 Oct 2022 22:25:42 +0800 In-Reply-To: <20221022140614.rnfd4d4nefjmizzi@begin> References: <20221022140614.rnfd4d4nefjmizzi@begin> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.0 MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD,LIKELY_SPAM_FROM,PDS_OTHER_BAD_TLD,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Sat, 2022-10-22 at 16:06 +0200, Samuel Thibault wrote: > Hello, >=20 > We're seeing a missing _DYNAMIC symbol here: >=20 > https://buildd.debian.org/status/fetch.php?pkg=3Dgnupg2&arch=3Dhurd-i386&= ver=3D2.2.40-1&stamp=3D1666261690&raw=3D0 >=20 > which is leaving me completely confused. >=20 >=20 > gcc -I/usr/include=C2=A0 -I/usr/include=C2=A0 -Wall -Wno-format-zero-leng= th - > Wno-pointer-sign -Wpointer-arith -g -O2 -ffile-prefix- > map=3D/<>=3D. -fstack-protector-strong -Wformat - > Werror=3Dformat-security=C2=A0 -Wl,-z,relro -Wl,-z,now -pie -static -o gp= gv > gpgv.o build-packet.o compress.o=C2=A0 free-packet.o getkey.o keydb.o > keyring.o seskey.o kbnode.o mainproc.o armor.o mdfilter.o textfilter.o > progress.o misc.o rmd160.o openfile.o keyid.o parse-packet.o cpr.o > plaintext.o sig-check.o keylist.o pkglue.o ecdh.o verify.o > ../kbx/libkeybox.a ../common/libcommon.a ../regexp/libregexp.a > ../common/libgpgrl.a -lz=C2=A0=C2=A0 -L/usr/lib/i386-gnu -lgcrypt - > L/usr/lib/i386-gnu -lgpg-error > [...] > /usr/bin/ld: /usr/lib/i386-gnu/libcrt.a(dl-reloc-static-pie.o): in > function `_dl_relocate_static_pie': > (.text+0x31): undefined reference to `_DYNAMIC' >=20 > So this is static pie (-pie -static) No it's not. The GCC option for static PIE is -static-pie (no whitespace between -static and -pie), not -pie -static. See the example: $ cc hw.c -pie -static $ file a.out=20 a.out: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 5.19.0, with debug_info, not stripped $ cc hw.c -static-pie=20 $ file a.out a.out: ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), static-pie linked, for GNU/Linux 5.19.0, with debug_info, not stripped > and I'm getting just the same > issue with a mere int main(void) {} built with -static -pie. >=20 >=20 > When debugging a bit on Debian Hurd: >=20 > $ gcc test.o -o test -pie -static -v > [...] > =C2=A0/usr/lib/gcc/i686-gnu/12/collect2 -plugin /usr/lib/gcc/i686- > gnu/12/liblto_plugin.so -plugin-opt=3D/usr/lib/gcc/i686-gnu/12/lto- > wrapper -plugin-opt=3D-fresolution=3D/tmp/ccR0YAaP.res -plugin-opt=3D-pas= s- > through=3D-lgcc -plugin-opt=3D-pass-through=3D-lgcc_eh -plugin-opt=3D-pas= s- > through=3D-lc --build-id -m elf_i386 --hash-style=3Dgnu --as-needed - > static -o test /usr/lib/gcc/i686-gnu/12/../../../i386-gnu/Scrt1.o > /usr/lib/gcc/i686-gnu/12/../../../i386-gnu/crti.o /usr/lib/gcc/i686- > gnu/12/crtbeginT.o -L/usr/lib/gcc/i686-gnu/12 -L/usr/lib/gcc/i686- > gnu/12/../../../i386-gnu -L/usr/lib/gcc/i686-gnu/12/../../.. - > L/lib/i386-gnu -L/usr/lib/i386-gnu test.o --start-group -lgcc -lgcc_eh > -lc --end-group /usr/lib/gcc/i686-gnu/12/crtend.o /usr/lib/gcc/i686- > gnu/12/../../../i386-gnu/crtn.o >=20 > So this is using Scrt1.o A static PIE should use rcrt1.o. If you pass the correct -static-pie option to GCC, GCC will use it. --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University