From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id A3F9529EA2 for ; Sun, 11 Aug 2024 23:52:42 +0200 (CEST) Received: (qmail 32353 invoked by uid 550); 11 Aug 2024 21:52:37 -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 32307 invoked from network); 11 Aug 2024 21:52:36 -0000 Date: Sun, 11 Aug 2024 17:52:29 -0400 From: Rich Felker To: =?utf-8?Q?J=2E_Neusch=C3=A4fer?= Cc: lvm-devel@lists.linux.dev, buildroot@buildroot.org, musl@lists.openwall.com Message-ID: <20240811215226.GK10433@brightrain.aerifal.cx> References: <20240811-microblaze-v1-1-2781ba343e75@gmx.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240811-microblaze-v1-1-2781ba343e75@gmx.net> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] [PATCH lvm2] acinclude.m4: Link when trying CCFLAGS On Sun, Aug 11, 2024 at 11:04:38AM +0200, J. Neuschäfer wrote: > Through a build failure of LVM2 on musl-libc 1.2.5 in the Buildroot > autobuild service[1], I noticed that musl-libc's Scrt1 for microblaze > produces a relocation targeting the .text section, which subsequently > leads to a crash at run-time because musl-libc does not support > textrels[2]. Buildroot uses the "-z text" linker option to catch > textrels early, on musl-libc. > > The error can be reduced to the following test case: > > $ cat hello.c > #include > int main(void) { puts("Hello world!"); return 0; } > $ host/bin/microblaze-buildroot-linux-musl-gcc hello.c -z text -pie -fPIC > microblaze-buildroot-linux-musl/bin/ld: microblaze-buildroot-linux-musl/sysroot/lib/Scrt1.o: > warning: relocation against `_start_c' in read-only section `.text' > microblaze-buildroot-linux-musl/bin/ld: read-only segment has dynamic relocations > collect2: error: ld returned 1 exit status > > LVM2 uses -pie only after the AC_TRY_CCFLAG macro has determined that it > can be used. This is where the problem begins: AC_TRY_CCFLAG only tries > compiling, it does not try linking the resulting object file. > > To catch problems like this, this patch changes AC_TRY_CCFLAG to link in > addition to compiling. By detecting correctly that -pie does not work on > musl-libc/microblaze with -ztext, the build failure in Buildroot is fixed. > > [1]: http://autobuild.buildroot.net/results/dc4/dc4fc33eaeafe5d6707d26a373560402533954f6/build-end.log > [2]: https://www.openwall.com/lists/musl/2020/09/25/4 > > Signed-off-by: J. Neuschäfer > --- > Hi, I'm cross-posting this to the LVM2, Buildroot, and musl mailing > lists to get potential feedback early on. > --- > acinclude.m4 | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/acinclude.m4 b/acinclude.m4 > index 47fdd59c3..9b1d3a605 100644 > --- a/acinclude.m4 > +++ b/acinclude.m4 > @@ -25,7 +25,7 @@ AC_DEFUN([AC_TRY_CCFLAG], > ac_save_CFLAGS=$CFLAGS > CFLAGS=$1 > AC_CACHE_CHECK([whether $CC accepts $1 flag], [ac_cv_flag_$2], > - [AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], > + [AC_LINK_IFELSE([AC_LANG_PROGRAM()], > [AS_VAR_SET([ac_cv_flag_$2], [yes])], > [AS_VAR_SET([ac_cv_flag_$2], [no])])]) > CFLAGS=$ac_save_CFLAGS > > --- No objection, but this is a bug in the tooling (ld) that we could also avoid on the musl side. So there are probably 3 places things should be changed here. Rich