From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 9C26B397EC0A; Fri, 13 May 2022 19:23:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C26B397EC0A Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: fix new sigfe.o generation in optimized case X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/master X-Git-Oldrev: 4f034daba70f359015f79cba3d5fb3d0d468924e X-Git-Newrev: 8f66bc28ae461763d1da91384a652512590eea16 Message-Id: <20220513192316.9C26B397EC0A@sourceware.org> Date: Fri, 13 May 2022 19:23:16 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 May 2022 19:23:16 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D8f66bc28ae4= 61763d1da91384a652512590eea16 commit 8f66bc28ae461763d1da91384a652512590eea16 Author: Corinna Vinschen Date: Fri May 13 21:22:44 2022 +0200 Cygwin: fix new sigfe.o generation in optimized case =20 Commit 0597c84b9bdb ("Cygwin: revamp TLS offsets computation") introduced a really weird problem when building Cygwin with optimization. =20 First of all, the tlsoffsets file is broken with -O2. This can easily be fixed by running the compiler with -O0 when called from the gentls_offsets script. =20 But it gets worse: =20 When creating sigfe.o with optimization, the generated machine code uses incorrect offsets: For some reason the assembler codes using _cygtls.stackptr as offset value are assembled into machine code using _cygtls.pstackptr as offsets. =20 And as if that isn't already absurd enough, renaming _cygtls.pstackptr to, say, _cygtls.blurb, fixes the assembled machine code expressions; they use the value of _cygtls.stackptr again. =20 So I changed gentls_offsets and gendef to use _cygtls.foo_p rather than _cygtls.pfoo and that fixes the assembled code in the optimized case. =20 No, I can't explain that. There's no system in that behaviour. It looks absolutely crazy. =20 Fixes: 0597c84b9bdb ("Cygwin: revamp TLS offsets computation") Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/gendef | 16 ++++++++-------- winsup/cygwin/gentls_offsets | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/winsup/cygwin/gendef b/winsup/cygwin/gendef index 779cdcfd0..577dfe8ee 100755 --- a/winsup/cygwin/gendef +++ b/winsup/cygwin/gendef @@ -318,7 +318,7 @@ _sigdelayed_end: _ZN7_cygtls3popEv: .seh_endprologue movq \$-8,%r11 - xaddq %r11,_cygtls.pstackptr(%rcx) + xaddq %r11,_cygtls.stackptr_p(%rcx) movq -8(%r11),%rax ret .seh_endproc @@ -332,7 +332,7 @@ _ZN7_cygtls4lockEv: .seh_endprologue movq %rcx,%r12 1: movl \$1,%r11d - xchgl %r11d,_cygtls.pstacklock(%r12) + xchgl %r11d,_cygtls.stacklock_p(%r12) testl %r11d,%r11d jz 2f pause @@ -346,7 +346,7 @@ _ZN7_cygtls4lockEv: .seh_proc _ZN7_cygtls6unlockEv _ZN7_cygtls6unlockEv: .seh_endprologue - decl _cygtls.pstacklock(%rcx) + decl _cygtls.stacklock_p(%rcx) ret .seh_endproc =20 @@ -355,7 +355,7 @@ _ZN7_cygtls6unlockEv: .seh_proc _ZN7_cygtls6lockedEv _ZN7_cygtls6lockedEv: .seh_endprologue - movl _cygtls.pstacklock(%rcx),%eax + movl _cygtls.stacklock_p(%rcx),%eax ret .seh_endproc =20 @@ -528,7 +528,7 @@ __ZN7_cygtls3popEv\@4: 1: pushl %ebx movl %eax,%ebx # this movl \$-4,%eax - xadd %eax,_cygtls.pstackptr(%ebx) + xadd %eax,_cygtls.stackptr_p(%ebx) movl -4(%eax),%eax popl %ebx ret @@ -539,7 +539,7 @@ __ZN7_cygtls4lockEv\@4: pushl %ebx movl %eax,%ebx 1: movl \$1,%eax - xchgl %eax,_cygtls.pstacklock(%ebx) + xchgl %eax,_cygtls.stacklock_p(%ebx) testl %eax,%eax jz 2f call _yield @@ -550,12 +550,12 @@ __ZN7_cygtls4lockEv\@4: # _cygtls::unlock .global __ZN7_cygtls6unlockEv\@4 __ZN7_cygtls6unlockEv\@4: - decl _cygtls.pstacklock(%eax) + decl _cygtls.stacklock_p(%eax) ret =20 .global __ZN7_cygtls6lockedEv __ZN7_cygtls6lockedEv: - movl _cygtls.pstacklock(%eax),%eax + movl _cygtls.stacklock_p(%eax),%eax ret =20 .extern __ZN7_cygtls19call_signal_handlerEv\@4 diff --git a/winsup/cygwin/gentls_offsets b/winsup/cygwin/gentls_offsets index 6892bd528..d76562c05 100755 --- a/winsup/cygwin/gentls_offsets +++ b/winsup/cygwin/gentls_offsets @@ -43,7 +43,7 @@ gawk ' } ' | \ # Now run the compiler to generate an assembler file. -${CXXCOMPILE} -x c++ -g0 -S - -o - | \ +${CXXCOMPILE} -x c++ -g0 -O0 -S - -o - | \ # The assembler file consists of lines like these: # # __CYGTLS__foo @@ -63,7 +63,7 @@ gawk '\ /\s*\.space\s*4/ { if (length (varname) > 0) { printf (".equ _cygtls.%s, %d\n", varname, -start_offset); - printf (".equ _cygtls.p%s, 0\n", varname); + printf (".equ _cygtls.%s_p, 0\n", varname); varname =3D ""; } } @@ -75,7 +75,7 @@ gawk '\ } else { value =3D $2; printf (".equ _cygtls.%s, %d\n", varname, value - start_offset); - printf (".equ _cygtls.p%s, %d\n", varname, value); + printf (".equ _cygtls.%s_p, %d\n", varname, value); } varname =3D ""; }