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=-3.3 required=5.0 tests=HTML_MESSAGE, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 10854 invoked from network); 7 Sep 2023 01:14:39 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 7 Sep 2023 01:14:39 -0000 Received: (qmail 20148 invoked by uid 550); 7 Sep 2023 01:14:34 -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 30628 invoked from network); 7 Sep 2023 00:46:45 -0000 Message-ID: <1db459153e3f7be32cb469509c272977b9c2b381.camel@newton.cx> From: Peter Williams To: musl@lists.openwall.com Date: Wed, 06 Sep 2023 20:46:32 -0400 Content-Type: multipart/alternative; boundary="=-GIj2GCC9Y740msRTgxAO" User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 Subject: [musl] aarch64 sigsetjmp relocation truncation bug, maybe --=-GIj2GCC9Y740msRTgxAO Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello, I'm experiencing a software issue that I think maybe, might, possibly, indicate a musl bug. I'm not at all familiar with the issues involved, but it looks like emailing this list might be my best bet for testing that hypothesis, so that's what I'm doing. Please CC me on any replies as I'm not subscribed, and accept my apologies if I'm way off base here. The short answer is that I'm trying to link a large (~100 MB) static executable for aarch64 and getting this error out of the binutils linker: /home/rust/sysroot-aarch64/usr/lib/libc.a(sigsetjmp.lo): in function `sig= setjmp': /home/buildozer/aports/main/musl/src/v1.2.3/src/signal/aarch64/sigsetjmp.= s:7:(.text+0x0): relocation truncated to fit: R_AARCH64_CONDBR19 against symbol `setjmp' defined in .text section in /home/rust/sysroot-aarch64/usr/lib/libc.a(s= etjmp.lo) If I'm understanding correctly, the complaint is that a=C2=A0branch in sigsetjmp that invokes setjmp=C2=A0is too far away from the definition of setjmp. My very handwavey idea is that maybe for some reason my program is causing the linker to want to locate setjmp() and sigsetjmp() really far away from each other. If that's right, perhaps it would be possible to modify the assembler code to be able to handle such a situation? My build environment is extremely gnarly =E2=80=94 I am running my build to= ols inside a cross-compiling Alpine Linux chroot that in turn runs inside an Ubuntu Docker container. (You don't want to know.) I can provide more details if needed, as well as a script that leads up to the error on my system, if you have CPU time to burn on the Docker container build. But since the error seems to be localized within my aarch64 "libc.a", I'm hopeful that maybe this funky environment doesn't actually affect the core situation here. As you might see in the output above, I'm using musl 1.2.3. Thanks for any insight, Peter --=-GIj2GCC9Y740msRTgxAO Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
Hello,

I'm experiencing = a software issue that I think maybe, might, possibly, indicate a musl bug. = I'm not at all familiar with the issues involved, but it looks like emailin= g this list might be my best bet for testing that hypothesis, so that's wha= t I'm doing. Please CC me on any replies as I'm not subscribed, and accept = my apologies if I'm way off base here.

The short a= nswer is that I'm trying to link a large (~100 MB) static executable for aa= rch64 and getting this error out of the binutils linker:

  /home/rust/sysroot-aarch64/usr/lib/libc.a(sigsetjmp.lo): in functi=
on `sigsetjmp':
  /home/buildozer/aports/main/musl/src/v1.2.3/src=
/signal/aarch64/sigsetjmp.s:7:(.text+0x0):
    relocation truncat=
ed to fit: R_AARCH64_CONDBR19 against symbol `setjmp'
    defined=
 in .text section in /home/rust/sysroot-aarch64/usr/lib/libc.a(setjmp.lo)





--=-GIj2GCC9Y740msRTgxAO-- 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=-3.3 required=5.0 tests=HTML_MESSAGE, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 10876 invoked from network); 7 Sep 2023 01:14:49 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 7 Sep 2023 01:14:49 -0000 Received: (qmail 20416 invoked by uid 550); 7 Sep 2023 01:14: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 9804 invoked from network); 7 Sep 2023 01:01:34 -0000 Message-ID: <062f8c2b1efa5b952b9e44a1953888c07a52e28e.camel@newton.cx> From: Peter Williams To: musl@lists.openwall.com Date: Wed, 06 Sep 2023 21:01:22 -0400 In-Reply-To: <1db459153e3f7be32cb469509c272977b9c2b381.camel@newton.cx> References: <1db459153e3f7be32cb469509c272977b9c2b381.camel@newton.cx> Content-Type: multipart/alternative; boundary="=-z3FBa+9Fpuija5esp4vy" User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 Subject: [musl] Re: aarch64 sigsetjmp relocation truncation bug, maybe --=-z3FBa+9Fpuija5esp4vy Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Of course, right after I send the email ... here's another piece of evidence, which I think is consistent with my interpretation below. If I simply add the following function to one of my C files: void you_gotta_be_kidding_me(int arg) { jmp_buf buf1; sigjmp_buf buf2; setjmp(buf1); sigsetjmp(buf2, arg); } ... the linker error goes away. My hypothesis is/was that code like this would encourage the linker to locate the two libc functions closer together, so that the relocation is no longer truncated. So, it appears that I at least have a workaround. Peter On Wed, 2023-09-06 at 20:46 -0400, Peter Williams wrote: > Hello, >=20 > I'm experiencing a software issue that I think maybe, might, > possibly, indicate a musl bug. I'm not at all familiar with the > issues involved, but it looks like emailing this list might be my > best bet for testing that hypothesis, so that's what I'm doing. > Please CC me on any replies as I'm not subscribed, and accept my > apologies if I'm way off base here. >=20 > The short answer is that I'm trying to link a large (~100 MB) static > executable for aarch64 and getting this error out of the binutils > linker: >=20 > /home/rust/sysroot-aarch64/usr/lib/libc.a(sigsetjmp.lo): in function `s= igsetjmp': > /home/buildozer/aports/main/musl/src/v1.2.3/src/signal/aarch64/sigsetjm= p.s:7:(.text+0x0): > relocation truncated to fit: R_AARCH64_CONDBR19 against symbol `setjm= p' > defined in .text section in /home/rust/sysroot-aarch64/usr/lib/libc.a= (setjmp.lo) >=20 > If I'm understanding correctly, the complaint is that a=C2=A0branch in > sigsetjmp that invokes setjmp=C2=A0is too far away from the definition of > setjmp. My very handwavey idea is that maybe for some reason my > program is causing the linker to want to locate setjmp() and > sigsetjmp() really far away from each other. If that's right, perhaps > it would be possible to modify the assembler code to be able to > handle such a situation? >=20 > My build environment is extremely gnarly =E2=80=94 I am running my build > tools inside a cross-compiling Alpine Linux chroot that in turn runs > inside an Ubuntu Docker container. (You don't want to know.) I can > provide more details if needed, as well as a script that leads up to > the error on my system, if you have CPU time to burn on the Docker > container build. But since the error seems to be localized within my > aarch64 "libc.a", I'm hopeful that maybe this funky environment > doesn't actually affect the core situation here. As you might see in > the output above, I'm using musl 1.2.3. >=20 > Thanks for any insight, >=20 > Peter >=20 --=-z3FBa+9Fpuija5esp4vy Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
Of course, right after I send the email ... here'= s another piece of evidence, which I think is consistent with my interpreta= tion below.

If I simply add the following function= to one of my C files:

void you_gotta_be_kidding_m=
e(int arg)
{
    jmp_buf buf1;
    sigjmp_buf=
 buf2;

    setjmp(buf1);
    sigsetjmp(b=
uf2, arg);
}

... the linker error goes a= way. My hypothesis is/was that code like this would encourage the linker to= locate the two libc functions closer together, so that the relocation is n= o longer truncated. So, it appears that I at least have a workaround.
=

Peter

On Wed, 2023-09-06 at 20= :46 -0400, Peter Williams wrote:
Hello= ,

I'm experiencing a software issue that I think m= aybe, might, possibly, indicate a musl bug. I'm not at all familiar with th= e issues involved, but it looks like emailing this list might be my best be= t for testing that hypothesis, so that's what I'm doing. Please CC me on an= y replies as I'm not subscribed, and accept my apologies if I'm way off bas= e here.

The short answer is that I'm trying to lin= k a large (~100 MB) static executable for aarch64 and getting this error ou= t of the binutils linker:

  /home/rust/sysroot-aar=
ch64/usr/lib/libc.a(sigsetjmp.lo): in function `sigsetjmp':
  /ho=
me/buildozer/aports/main/musl/src/v1.2.3/src/signal/aarch64/sigsetjmp.s:7:(=
.text+0x0):
    relocation truncated to fit: R_AARCH64_CONDBR19 a=
gainst symbol `setjmp'
    defined in .text section in /home/rust=
/sysroot-aarch64/usr/lib/libc.a(setjmp.lo)

If I'm = understanding correctly, the complaint is that a branch in sigsetjmp that invokes setjmp is too far away from the= definition of setjmp. My very handwavey idea is that maybe for some reason= my program is causing the linker to want to locate setjmp() and sigsetjmp(= ) really far away from each other. If that's right, perhaps it would be pos= sible to modify the assembler code to be able to handle such a situation?

My build environment is extremely gnarly =E2=80=94 = I am running my build tools inside a cross-compiling Alpine Linux chroot th= at in turn runs inside an Ubuntu Docker container. (You don't want to know.= ) I can provide more details if needed, as well as a script that leads up t= o the error on my system, if you have CPU time to burn on the Docker contai= ner build. But since the error seems to be localized within my aarch64 "lib= c.a", I'm hopeful that maybe this funky environment doesn't actually affect= the core situation here. As you might see in the output above, I'm using m= usl 1.2.3.

Thanks for any insight,

<= /div>
Peter


--=-z3FBa+9Fpuija5esp4vy-- 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=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 15104 invoked from network); 7 Sep 2023 03:08:29 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 7 Sep 2023 03:08:29 -0000 Received: (qmail 23841 invoked by uid 550); 7 Sep 2023 03:08: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 23806 invoked from network); 7 Sep 2023 03:08:26 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1694056094; x=1694660894; i=nullplan@gmx.net; bh=K7M+44eCC9YyUN8Wjgaj1XBDm9NtjZ1qiKDg6SXfEvw=; h=X-UI-Sender-Class:Date:From:To:Subject:References:In-Reply-To; b=Qzj7EKRGCVe18oFwDUFTvQY/n3j+qn31eArs44ik5qYW+STmtTTDWQl6ZnEQj4QuxQ0jRM8 zfTkHE3LMuf9cyvsJ9sB9/seZHFmY9gA5jqgaGiOh/Xk740WHHiTz//BnvoPjWBP/AbJtd1UL rkYKHZAbxlzaD7itjR/R4EvudH1gXif4JmTlhQGICeYO+kY62J1xX7UXdM4+DiTMNUHCvUwY9 2BwJPLJYWejWjvZkZ6jbMtBl/SRuW3RruXrQxHtUkwtcNg4qf/3qfZrdgtk4xqRjluunLNne0 MovzKUNdSsHc0aCpwhDsueUWJkV4aAT7P3NJc5T7kRIckjUI65QA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Date: Thu, 7 Sep 2023 05:08:13 +0200 From: Markus Wichmann To: musl@lists.openwall.com Message-ID: References: <1db459153e3f7be32cb469509c272977b9c2b381.camel@newton.cx> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="FDPiRWCTPHY74CP1" Content-Disposition: inline In-Reply-To: <1db459153e3f7be32cb469509c272977b9c2b381.camel@newton.cx> X-Provags-ID: V03:K1:U8X+Tst4MpTrtZIwV+8iFQoMdOTZo3xws3fl9NvX4FXcxLlWWW6 st9LqmilVKXhu+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H9SJpz4tNRDP5dr0ALxHN3NeyvFzNk IHZroTX1UEmyBrkgIR5xP4/pOZISefFRQDLMhvwnawyyYubPxiWGJrrEpMg8QUHmUWeJkRCkq LBcq5LPQapRcb3GpMCxY2og73TM= Subject: Re: [musl] aarch64 sigsetjmp relocation truncation bug, maybe --FDPiRWCTPHY74CP1 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Am Wed, Sep 06, 2023 at 08:46:32PM -0400 schrieb Peter Williams: > If I'm understanding correctly, the complaint is that a=A0branch in > sigsetjmp that invokes setjmp=A0is too far away from the definition of > setjmp. My very handwavey idea is that maybe for some reason my program > is causing the linker to want to locate setjmp() and sigsetjmp() really > far away from each other. If that's right, perhaps it would be possible > to modify the assembler code to be able to handle such a situation? I'm guessing the same. Pretty much all architectures have shorter conditional than unconditional branches. That is why branches to other files (technically to other sections) should always be unconditional. I am attaching a simple patch that should help with the situation. Ciao, Markus --FDPiRWCTPHY74CP1 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Make-branch-to-external-symbol-unconditional.patch" Content-Transfer-Encoding: quoted-printable =46rom dd227e22a5337d54e1cb0838410bca6672c76c43 Mon Sep 17 00:00:00 2001 From: Markus Wichmann Date: Thu, 7 Sep 2023 05:01:23 +0200 Subject: [PATCH] Make branch to external symbol unconditional. Conditional branches have a shorter branch length than unconditional ones, and almost all ABIs require unconditional branches to external symbols. Otherwise linkers may create broken binaries. =2D-- src/signal/aarch64/sigsetjmp.s | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/signal/aarch64/sigsetjmp.s b/src/signal/aarch64/sigsetjmp= .s index 75910c43..9a28e395 100644 =2D-- a/src/signal/aarch64/sigsetjmp.s +++ b/src/signal/aarch64/sigsetjmp.s @@ -4,7 +4,7 @@ .type __sigsetjmp,%function sigsetjmp: __sigsetjmp: - cbz x1,setjmp + cbz x1,1f str x30,[x0,#176] str x19,[x0,#176+8+8] @@ -19,3 +19,5 @@ __sigsetjmp: .hidden __sigsetjmp_tail b __sigsetjmp_tail + +1: b setjmp =2D- 2.39.2 --FDPiRWCTPHY74CP1-- 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=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 960 invoked from network); 7 Sep 2023 12:48:40 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 7 Sep 2023 12:48:40 -0000 Received: (qmail 5762 invoked by uid 550); 7 Sep 2023 12:48:34 -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 5727 invoked from network); 7 Sep 2023 12:48:34 -0000 Date: Thu, 7 Sep 2023 08:48:28 -0400 From: Rich Felker To: musl@lists.openwall.com Message-ID: <20230907124828.GB4163@brightrain.aerifal.cx> References: <1db459153e3f7be32cb469509c272977b9c2b381.camel@newton.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] aarch64 sigsetjmp relocation truncation bug, maybe On Thu, Sep 07, 2023 at 05:08:13AM +0200, Markus Wichmann wrote: > Am Wed, Sep 06, 2023 at 08:46:32PM -0400 schrieb Peter Williams: > > If I'm understanding correctly, the complaint is that a branch in > > sigsetjmp that invokes setjmp is too far away from the definition of > > setjmp. My very handwavey idea is that maybe for some reason my program > > is causing the linker to want to locate setjmp() and sigsetjmp() really > > far away from each other. If that's right, perhaps it would be possible > > to modify the assembler code to be able to handle such a situation? > > I'm guessing the same. Pretty much all architectures have shorter > conditional than unconditional branches. That is why branches to other > files (technically to other sections) should always be unconditional. I > am attaching a simple patch that should help with the situation. > > Ciao, > Markus > From dd227e22a5337d54e1cb0838410bca6672c76c43 Mon Sep 17 00:00:00 2001 > From: Markus Wichmann > Date: Thu, 7 Sep 2023 05:01:23 +0200 > Subject: [PATCH] Make branch to external symbol unconditional. > > Conditional branches have a shorter branch length than unconditional > ones, and almost all ABIs require unconditional branches to external > symbols. Otherwise linkers may create broken binaries. > --- > src/signal/aarch64/sigsetjmp.s | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/src/signal/aarch64/sigsetjmp.s b/src/signal/aarch64/sigsetjmp..s > index 75910c43..9a28e395 100644 > --- a/src/signal/aarch64/sigsetjmp.s > +++ b/src/signal/aarch64/sigsetjmp.s > @@ -4,7 +4,7 @@ > .type __sigsetjmp,%function > sigsetjmp: > __sigsetjmp: > - cbz x1,setjmp > + cbz x1,1f > > str x30,[x0,#176] > str x19,[x0,#176+8+8] > @@ -19,3 +19,5 @@ __sigsetjmp: > > .hidden __sigsetjmp_tail > b __sigsetjmp_tail > + > +1: b setjmp > -- > 2.39.2 Are you sure this is the actual problem? I think it's that the aarch64 (and several other archs) version of sigsetjmp is wrongly using the public setjmp symbol whose definition is possibly provided by a PLT thunk in the main program, rather than either setjmp@PLT (which would necessarily be the right local call point to use) or the hidden ___setjmp symbol that exists for this purpose (which i386, for example, uses). Rich 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=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2124 invoked from network); 7 Sep 2023 13:29:05 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 7 Sep 2023 13:29:05 -0000 Received: (qmail 5703 invoked by uid 550); 7 Sep 2023 13:29:02 -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 5657 invoked from network); 7 Sep 2023 13:29:01 -0000 Date: Thu, 7 Sep 2023 09:28:52 -0400 From: Rich Felker To: musl@lists.openwall.com Cc: Peter Williams Message-ID: <20230907132851.GC4163@brightrain.aerifal.cx> References: <1db459153e3f7be32cb469509c272977b9c2b381.camel@newton.cx> <20230907124828.GB4163@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230907124828.GB4163@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] aarch64 sigsetjmp relocation truncation bug, maybe (Re-adding the OP to CC) On Thu, Sep 07, 2023 at 08:48:28AM -0400, Rich Felker wrote: > On Thu, Sep 07, 2023 at 05:08:13AM +0200, Markus Wichmann wrote: > > Am Wed, Sep 06, 2023 at 08:46:32PM -0400 schrieb Peter Williams: > > > If I'm understanding correctly, the complaint is that a branch in > > > sigsetjmp that invokes setjmp is too far away from the definition of > > > setjmp. My very handwavey idea is that maybe for some reason my program > > > is causing the linker to want to locate setjmp() and sigsetjmp() really > > > far away from each other. If that's right, perhaps it would be possible > > > to modify the assembler code to be able to handle such a situation? > > > > I'm guessing the same. Pretty much all architectures have shorter > > conditional than unconditional branches. That is why branches to other > > files (technically to other sections) should always be unconditional. I > > am attaching a simple patch that should help with the situation. > > > > Ciao, > > Markus > > > From dd227e22a5337d54e1cb0838410bca6672c76c43 Mon Sep 17 00:00:00 2001 > > From: Markus Wichmann > > Date: Thu, 7 Sep 2023 05:01:23 +0200 > > Subject: [PATCH] Make branch to external symbol unconditional. > > > > Conditional branches have a shorter branch length than unconditional > > ones, and almost all ABIs require unconditional branches to external > > symbols. Otherwise linkers may create broken binaries. > > --- > > src/signal/aarch64/sigsetjmp.s | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/src/signal/aarch64/sigsetjmp.s b/src/signal/aarch64/sigsetjmp..s > > index 75910c43..9a28e395 100644 > > --- a/src/signal/aarch64/sigsetjmp.s > > +++ b/src/signal/aarch64/sigsetjmp.s > > @@ -4,7 +4,7 @@ > > .type __sigsetjmp,%function > > sigsetjmp: > > __sigsetjmp: > > - cbz x1,setjmp > > + cbz x1,1f > > > > str x30,[x0,#176] > > str x19,[x0,#176+8+8] > > @@ -19,3 +19,5 @@ __sigsetjmp: > > > > .hidden __sigsetjmp_tail > > b __sigsetjmp_tail > > + > > +1: b setjmp > > -- > > 2.39.2 > > Are you sure this is the actual problem? I think it's that the aarch64 > (and several other archs) version of sigsetjmp is wrongly using the > public setjmp symbol whose definition is possibly provided by a PLT > thunk in the main program, rather than either setjmp@PLT (which would > necessarily be the right local call point to use) or the hidden > ___setjmp symbol that exists for this purpose (which i386, for > example, uses). Hmm, no, that seems to be a separate issue. The reported issue is indeed a large static link where PLT stuff should not come into play. So I think the cbz limited-range is indeed the issue. Rich 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=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 4504 invoked from network); 7 Sep 2023 14:43:07 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 7 Sep 2023 14:43:07 -0000 Received: (qmail 32578 invoked by uid 550); 7 Sep 2023 14:43:03 -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 32546 invoked from network); 7 Sep 2023 14:43:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1694097771; x=1694702571; i=nullplan@gmx.net; bh=xDaTSswhsg+JbGd6SICrxvjn0lCOxxvejKdS/y1xQUI=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=hQL5sSsCn95JnWIZeVxfl9AaKwsFHYXHJrkXO55Xvb140VOBITRBgK5YT4gr6Jg74d6QTu/ +14XzPxnG3rtjs5qy8jwUH5n74eJ246zzeq1GbgmgPbZksPRMBzGFYCuzPUdqMhfDJfdf2UbY 4OYT2GAqVsDr4SoEW+qHfRnT7lP4JR5fmk5Uhrzh8eplIpkqAG22t334VpBd5tXRMZ4/9DXTS t9G/2vseOhQMHyFKSJax4bA5H06g1Ir4DztUX+yCGeknwm4G6gFfwiwCGO5KMvISjElONUrR7 aUeRcYohigmH2Xwsl26f1vfYbo1Eg3lXWbmwqMnVHiKGcp5ZxFeQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Date: Thu, 7 Sep 2023 16:42:50 +0200 From: Markus Wichmann To: musl@lists.openwall.com Cc: Peter Williams Message-ID: References: <1db459153e3f7be32cb469509c272977b9c2b381.camel@newton.cx> <20230907124828.GB4163@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230907124828.GB4163@brightrain.aerifal.cx> X-Provags-ID: V03:K1:CysqvKKU8V5eSNCmkn3dNXGwKg6b6Qfqz7w+cq+CcvVUZENO+gY YOy7H3gJuWMC6/fHZhgp76UmUklewicAs9kCzsLvEJJTsu4HJmIGOVHHSR82jLgZYXj5dFz 8+yEri4/mIP187vb9plBiIB+vL4GGFrAqADMAWw+SafvxpJ13LcHvZQeXzRTbEZioLmsta/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Encoding: quoted-printable Subject: Re: [musl] aarch64 sigsetjmp relocation truncation bug, maybe Am Thu, Sep 07, 2023 at 08:48:28AM -0400 schrieb Rich Felker: > Are you sure this is the actual problem? I think it's that the aarch64 > (and several other archs) version of sigsetjmp is wrongly using the > public setjmp symbol whose definition is possibly provided by a PLT > thunk in the main program, rather than either setjmp@PLT (which would > necessarily be the right local call point to use) or the hidden > ___setjmp symbol that exists for this purpose (which i386, for > example, uses). > > Rich No I am not sure. I wrote that patch before heading to work, without even test-compiling, and I don't know the first thing about arm64. But every architecture I have ever looked into at any depth had a shorter conditional branch than unconditional branch, and the linker normally presumes to be able to rearrange input code sections at will, at least for the branch length of an unconditional branch. Anything more usually requires more specialized code and specialized options to the compiler. That's why I wrote the patch in that way. Of course you are right that I did not think about the PLT, or a possible symbol interposition. However, the subroutine call to setjmp that was already in sigsetjmp also didn't. And the prior version of the code as well. So at least I didn't worsen the situation. Ciao, Markus 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.6 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 14357 invoked from network); 7 Sep 2023 19:49:52 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 7 Sep 2023 19:49:52 -0000 Received: (qmail 24264 invoked by uid 550); 7 Sep 2023 19:49:48 -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 24216 invoked from network); 7 Sep 2023 19:49:47 -0000 Date: Thu, 7 Sep 2023 21:49:35 +0200 From: Szabolcs Nagy To: Rich Felker Cc: musl@lists.openwall.com, Peter Williams Message-ID: <20230907194935.GG3448312@port70.net> Mail-Followup-To: Rich Felker , musl@lists.openwall.com, Peter Williams References: <1db459153e3f7be32cb469509c272977b9c2b381.camel@newton.cx> <20230907124828.GB4163@brightrain.aerifal.cx> <20230907132851.GC4163@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <20230907132851.GC4163@brightrain.aerifal.cx> Subject: Re: [musl] aarch64 sigsetjmp relocation truncation bug, maybe * Rich Felker [2023-09-07 09:28:52 -0400]: > On Thu, Sep 07, 2023 at 08:48:28AM -0400, Rich Felker wrote: > > On Thu, Sep 07, 2023 at 05:08:13AM +0200, Markus Wichmann wrote: > > > Am Wed, Sep 06, 2023 at 08:46:32PM -0400 schrieb Peter Williams: > > > > If I'm understanding correctly, the complaint is that a=C2=A0branch= in > > > > sigsetjmp that invokes setjmp=C2=A0is too far away from the definit= ion of > > > > setjmp. My very handwavey idea is that maybe for some reason my pro= gram > > > > is causing the linker to want to locate setjmp() and sigsetjmp() re= ally > > > > far away from each other. If that's right, perhaps it would be poss= ible > > > > to modify the assembler code to be able to handle such a situation? > > >=20 > > > I'm guessing the same. Pretty much all architectures have shorter > > > conditional than unconditional branches. That is why branches to other > > > files (technically to other sections) should always be unconditional.= I > > > am attaching a simple patch that should help with the situation. > > >=20 > > > Ciao, > > > Markus > >=20 > > > From dd227e22a5337d54e1cb0838410bca6672c76c43 Mon Sep 17 00:00:00 2001 > > > From: Markus Wichmann > > > Date: Thu, 7 Sep 2023 05:01:23 +0200 > > > Subject: [PATCH] Make branch to external symbol unconditional. > > >=20 > > > Conditional branches have a shorter branch length than unconditional > > > ones, and almost all ABIs require unconditional branches to external > > > symbols. Otherwise linkers may create broken binaries. > > > --- > > > src/signal/aarch64/sigsetjmp.s | 4 +++- > > > 1 file changed, 3 insertions(+), 1 deletion(-) > > >=20 > > > diff --git a/src/signal/aarch64/sigsetjmp.s b/src/signal/aarch64/sigs= etjmp..s > > > index 75910c43..9a28e395 100644 > > > --- a/src/signal/aarch64/sigsetjmp.s > > > +++ b/src/signal/aarch64/sigsetjmp.s > > > @@ -4,7 +4,7 @@ > > > .type __sigsetjmp,%function > > > sigsetjmp: > > > __sigsetjmp: > > > - cbz x1,setjmp > > > + cbz x1,1f > > >=20 > > > str x30,[x0,#176] > > > str x19,[x0,#176+8+8] > > > @@ -19,3 +19,5 @@ __sigsetjmp: > > >=20 > > > .hidden __sigsetjmp_tail > > > b __sigsetjmp_tail > > > + > > > +1: b setjmp yeah, this looks good except the commit message can be improved. conditional branch has +-1M reach, unconditional branch has +-128M reach and the linker inserts a veneer if unconditional branch goes further than that (i.e. it can go arbitrarily far). setjmp is a local symbol to libc (or in case of static linking to the exe), so using unconditional branch is perfectly fine if we ensure the linker does not move the symbols far (e.g. putting the two symbols in the same object file or into the same small section is enough). this depends on that user code cannot interpose setjmp (link namespace violation) and setjmp in libc does not use plt. note that aarch64 libc.so text is < 1M so we can compile it with -mcmodel=3Dtiny code model and then the compiler would emit cond branch for libc symbols. but .lo objects built like that are not suitable for libc.a. the simple b setjmp is the reasonable fix for now. > > Are you sure this is the actual problem? I think it's that the aarch64 > > (and several other archs) version of sigsetjmp is wrongly using the > > public setjmp symbol whose definition is possibly provided by a PLT > > thunk in the main program, rather than either setjmp@PLT (which would > > necessarily be the right local call point to use) or the hidden > > ___setjmp symbol that exists for this purpose (which i386, for > > example, uses). >=20 > Hmm, no, that seems to be a separate issue. The reported issue is > indeed a large static link where PLT stuff should not come into play. > So I think the cbz limited-range is indeed the issue. >=20 > Rich