mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rui Ueyama <rui314@gmail.com>
To: Rich Felker <dalias@libc.org>
Cc: musl@lists.openwall.com
Subject: Re: [musl] `musl-gcc -static` and lld/mold
Date: Sun, 13 Nov 2022 08:55:45 +0800	[thread overview]
Message-ID: <CACKH++aY3cZB=GsR4Kq72Z1vKMi5vt+CFJPYNTW0O33ubmOD=g@mail.gmail.com> (raw)
In-Reply-To: <CACKH++Y3_5e=-RarJPWui=pPgcGYbVsS4K-BQYrhsEfS0cVk-A@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2132 bytes --]

The below patch should fix the issue.

diff --git a/tools/musl-gcc.specs.sh b/tools/musl-gcc.specs.sh
index 30492574..ffb46d70 100644
--- a/tools/musl-gcc.specs.sh
+++ b/tools/musl-gcc.specs.sh
@@ -23,7 +23,7 @@ libgcc.a%s %:if-exists(libgcc_eh.a%s)
 crtendS.o%s $libdir/crtn.o

 *link:
--dynamic-linker $ldso -nostdlib %{shared:-shared} %{static:-static}
%{rdynamic:-export-dynamic}
+%{!static:-dynamic-linker $ldso} -nostdlib %{shared:-shared}
%{static:-static} %{rdynamic:-export-dynamic}

 *esp_link:

On Sun, Nov 13, 2022 at 8:46 AM Rui Ueyama <rui314@gmail.com> wrote:

> Let me try to create a patch.
>
> On Sun, Nov 13, 2022 at 8:38 AM Rich Felker <dalias@libc.org> 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 <stdio.h>
>> > 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
>>
>

[-- Attachment #2: Type: text/html, Size: 3097 bytes --]

  reply	other threads:[~2022-11-13  0:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-13  0:11 Rui Ueyama
2022-11-13  0:38 ` Rich Felker
2022-11-13  0:46   ` Rui Ueyama
2022-11-13  0:55     ` Rui Ueyama [this message]
2022-11-13  3:26       ` Fangrui Song
2022-11-13 15:51         ` Szabolcs Nagy
2022-11-13 17:09           ` Rich Felker
2022-11-13 18:30             ` Fangrui Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACKH++aY3cZB=GsR4Kq72Z1vKMi5vt+CFJPYNTW0O33ubmOD=g@mail.gmail.com' \
    --to=rui314@gmail.com \
    --cc=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).