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=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 11711 invoked from network); 13 Nov 2022 00:38:28 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 13 Nov 2022 00:38:28 -0000 Received: (qmail 3358 invoked by uid 550); 13 Nov 2022 00:38:26 -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 3326 invoked from network); 13 Nov 2022 00:38:25 -0000 Date: Sat, 12 Nov 2022 19:38:13 -0500 From: Rich Felker To: Rui Ueyama Cc: musl@lists.openwall.com Message-ID: <20221113003813.GL29905@brightrain.aerifal.cx> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] `musl-gcc -static` and lld/mold 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