From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 14116 invoked from network); 13 Nov 2022 00:58:19 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 13 Nov 2022 00:58:19 -0000 Received: (qmail 18286 invoked by uid 550); 13 Nov 2022 00:58:16 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 11391 invoked from network); 13 Nov 2022 00:47:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=THQ8Vxb734VCYh5kTmdDTgjyaB+VZ6s7mNHe36Vaj7Y=; b=Cd7BJPKIPVeT8FhWzYpI/wtg9lrY+reC28ZqCKKO2kBpCR17NYCPsizSGfMbqwAFaJ pEubughTNlsN80M1aeWGZK+jQetIXQqv7AJXdaBMoJz+CsMS9gzVq42FGVshggsypAIv Sa/x3Xn1WNYOG49abF2fmZCO+vTUkrJG23Qll4VPq1SlSIadwL0nDazVaaKkLRN3LbFT i6dYFQrCrEYf7iWIIY4/PjRGPbbyiqfOPNKcvhqbSKvYo+qrCHozQ3EnG943oSYmwD6q CWghe9xDxyZgbXj2KnTAdzYAznPxvptDRsyXKp8NHPl0d9dqYk4jfBDV3fgJIYQo+uIH e21A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=THQ8Vxb734VCYh5kTmdDTgjyaB+VZ6s7mNHe36Vaj7Y=; b=vpM2iKSFGbpJVww7QPvsEphnx4JKSvJSsOwQdMyvDBxSb1axfqZH/ph/UGuaOr5iva c0lzxgKev/4gUDf6n0Ry9fByUJfqFEnQypdb1Er76ZinbtGg7aratbtCjSkPdAeuLRtP WN8e4MCXwIHakBK/kFs7JBNFNwgn1BUPBvvINoA1pgS0lxnPof9Y0PoPcAHsi/udSDME D0lRX+4CBDVoXdntrwFQZp6ZHKOhcqwTyTxLIQiUH9CmAZj4KsIftwipvCUxykrEn43Y feUlXhQblbFQpPE79KGYtpSHnq/QRZNFMT5WkJufoeqYZQRXM7AhsoFHNBNx7UMXWvGZ 4v4Q== X-Gm-Message-State: ANoB5pkCsi1KPKtpLiJEb7Zc9OHsRxiOW0ZHmfyvqU/kVK+I5doj4Sls xT1RBCVb0TtgKyuyVo1ac5D4uR+5vnsCXc4LUos= X-Google-Smtp-Source: AA0mqf6GFbT+DLU3cKX8ErXensPNqgpyw9PbAaLPPSozhl65VULS5mY/smwdS1z+MHGM5zTljjB5s6mpANOMAL9ySYI= X-Received: by 2002:a05:6870:7393:b0:13b:9f17:5f89 with SMTP id z19-20020a056870739300b0013b9f175f89mr4240583oam.166.1668300417704; Sat, 12 Nov 2022 16:46:57 -0800 (PST) MIME-Version: 1.0 References: <20221113003813.GL29905@brightrain.aerifal.cx> In-Reply-To: <20221113003813.GL29905@brightrain.aerifal.cx> From: Rui Ueyama Date: Sun, 13 Nov 2022 08:46:46 +0800 Message-ID: To: Rich Felker Cc: musl@lists.openwall.com Content-Type: multipart/alternative; boundary="000000000000c6a75905ed4f75d6" Subject: Re: [musl] `musl-gcc -static` and lld/mold --000000000000c6a75905ed4f75d6 Content-Type: text/plain; charset="UTF-8" Let me try to create a patch. On Sun, Nov 13, 2022 at 8:38 AM Rich Felker wrote: > On Sun, Nov 13, 2022 at 08:11:29AM +0800, Rui Ueyama wrote: > > Hi, > > > > I think I found a musl-gcc issue. It looks like musl-gcc always appends > > `-dynamic-linker /lib/ld-musl-x86_64.so.1` even if `-static` is given. > That > > causes a created program to immediately crash on startup as you can see > > below: > > > > $ cat hello.c > > #include > > int main() { printf("Hello\n"); } > > > > $ musl-gcc -static -fuse-ld=lld hello.c -o hello > > > > $ ./hello > > Segmentation fault (core dumped) > > > > $ musl-gcc -static -fuse-ld=lld hello.c -o hello -Wl,-no-dynamic-linker > > $ ./hello > > Hello > > > > This also happens to my new linker, mold, as well. `-dynamic-linker` > option > > is passed to the linker, and lld and mold do what it is told to do, so I > > don't think it is a linker's bug. Rather, it's a compiler front end's bug > > that passes the unnecessary command line option. Can you not to append > > `-dynamic-linker` if `-static`? > > Yes, I think this should be fixed. It only works with bfd ld without > static pie (which we're also missing support for) because it just > ignores -dynamic-linker in the ET_EXEC case. > > Would you be willing to propose a candidate patch? I believe this has > been raised before in the context of static pie not working with > musl-gcc (it didn't exist when the wrapper was added) so ideally that > will get fixed too. > > Rich > --000000000000c6a75905ed4f75d6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Let me try to create a patch.

On Sun, Nov 13, 2022 at 8:38 = AM Rich Felker <dalias@libc.org&g= t; wrote:
On Sun= , Nov 13, 2022 at 08:11:29AM +0800, Rui Ueyama wrote:
> Hi,
>
> I think I found a musl-gcc issue. It looks like musl-gcc always append= s
> `-dynamic-linker /lib/ld-musl-x86_64.so.1` even if `-static` is given.= That
> causes a created program to immediately crash on startup as you can se= e
> below:
>
> $ cat hello.c
> #include <stdio.h>
> int main() { printf("Hello\n"); }
>
> $ musl-gcc -static -fuse-ld=3Dlld hello.c -o hello
>
> $ ./hello
> Segmentation fault (core dumped)
>
> $ musl-gcc -static -fuse-ld=3Dlld hello.c -o hello -Wl,-no-dynamic-lin= ker
> $ ./hello
> Hello
>
> This also happens to my new linker, mold, as well. `-dynamic-linker` o= ption
> is passed to the linker, and lld and mold do what it is told to do, so= I
> don't think it is a linker's bug. Rather, it's a compiler = front end's bug
> that passes the unnecessary command line option. Can you not to append=
> `-dynamic-linker` if `-static`?

Yes, I think this should be fixed. It only works with bfd ld without
static pie (which we're also missing support for) because it just
ignores -dynamic-linker in the ET_EXEC case.

Would you be willing to propose a candidate patch? I believe this has
been raised before in the context of static pie not working with
musl-gcc (it didn't exist when the wrapper was added) so ideally that will get fixed too.

Rich
--000000000000c6a75905ed4f75d6--