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.7 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,URIBL_BLACK autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 391 invoked from network); 13 Nov 2022 03:27:11 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 13 Nov 2022 03:27:11 -0000 Received: (qmail 7476 invoked by uid 550); 13 Nov 2022 03:27:07 -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 7441 invoked from network); 13 Nov 2022 03:27:06 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qrPoJGRKZQg7BD/Nm0GRFFWkIp/PoqtJkio2gRK6SFk=; b=TOWSdo0GfPDetpaBBsvFq1RQq4x0dOev0x9TQ4xpRkqsHlllEJFS3Q3/odZ/wFFSs+ u7tE9hvCuiq4TDhoWNtF5EPJzfJgfGlS0PoFOajojg4228r0zIdzXeDfT0+IxOGSiJq8 3qVqEVNE14Wy4Jn9CLsCdTxu/PkGBABr9xAFeC8dCJVXchgkxbTuff8vN2+pllAFfoNj mr8kfqu+lO0BmmzqcgGseuPI2ktKIQw+zrklNDfT2gCP3pgF2bVxFchflzWvNi2U4kZm PIPRFybIbqexLiLx9a3/OcHLNwsi+x4d02qW9oYJk6csKx5DKokZjQwKInkwTzdnsRl1 k6Bw== X-Gm-Message-State: ANoB5pnrn8K7DehwG4CJIo6ymL7klV170md0webnkkzUAXAQ2mzvTOSU aMdH3bWMMQAnguWLgwaizMs= X-Google-Smtp-Source: AA0mqf7za3cXio+YX07PR3BRLQocZBeJxfrFKYxNlS2ct3JaRwN5okGVqNQ+E/aG3TAqvkf0YX/Y4Q== X-Received: by 2002:a63:1b52:0:b0:44e:74d0:e843 with SMTP id b18-20020a631b52000000b0044e74d0e843mr7486210pgm.95.1668310014393; Sat, 12 Nov 2022 19:26:54 -0800 (PST) Date: Sat, 12 Nov 2022 19:26:53 -0800 From: Fangrui Song To: Rui Ueyama Cc: Rich Felker , musl@lists.openwall.com Message-ID: <20221113032653.6qz4hqh3nfm25tpt@gmail.com> References: <20221113003813.GL29905@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: Subject: Re: [musl] `musl-gcc -static` and lld/mold On 2022-11-13, Rui Ueyama wrote: >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: I use this patch which handles -static-pie as well: https://github.com/MaskRay/musl/tree/musl-gcc In addition, I use `*libdir: $libdir` to avoid absolute path references so that the spec file can be easily fixed after moving the build directory. >On Sun, Nov 13, 2022 at 8:46 AM Rui Ueyama wrote: > >> 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 >>> >>