Cygwin: fix new sigfe.o generation in optimized case

Commit 0597c84b9b ("Cygwin: revamp TLS offsets computation")
introduced a really weird problem when building Cygwin with
optimization.

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.

But it gets worse:

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.

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.

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.

No, I can't explain that.  There's no system in that behaviour.
It looks absolutely crazy.

Fixes: 0597c84b9b ("Cygwin: revamp TLS offsets computation")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2022-05-13 21:22:44 +02:00
parent 4f034daba7
commit 8f66bc28ae
2 changed files with 11 additions and 11 deletions

View File

@ -318,7 +318,7 @@ _sigdelayed_end:
_ZN7_cygtls3popEv: _ZN7_cygtls3popEv:
.seh_endprologue .seh_endprologue
movq \$-8,%r11 movq \$-8,%r11
xaddq %r11,_cygtls.pstackptr(%rcx) xaddq %r11,_cygtls.stackptr_p(%rcx)
movq -8(%r11),%rax movq -8(%r11),%rax
ret ret
.seh_endproc .seh_endproc
@ -332,7 +332,7 @@ _ZN7_cygtls4lockEv:
.seh_endprologue .seh_endprologue
movq %rcx,%r12 movq %rcx,%r12
1: movl \$1,%r11d 1: movl \$1,%r11d
xchgl %r11d,_cygtls.pstacklock(%r12) xchgl %r11d,_cygtls.stacklock_p(%r12)
testl %r11d,%r11d testl %r11d,%r11d
jz 2f jz 2f
pause pause
@ -346,7 +346,7 @@ _ZN7_cygtls4lockEv:
.seh_proc _ZN7_cygtls6unlockEv .seh_proc _ZN7_cygtls6unlockEv
_ZN7_cygtls6unlockEv: _ZN7_cygtls6unlockEv:
.seh_endprologue .seh_endprologue
decl _cygtls.pstacklock(%rcx) decl _cygtls.stacklock_p(%rcx)
ret ret
.seh_endproc .seh_endproc
@ -355,7 +355,7 @@ _ZN7_cygtls6unlockEv:
.seh_proc _ZN7_cygtls6lockedEv .seh_proc _ZN7_cygtls6lockedEv
_ZN7_cygtls6lockedEv: _ZN7_cygtls6lockedEv:
.seh_endprologue .seh_endprologue
movl _cygtls.pstacklock(%rcx),%eax movl _cygtls.stacklock_p(%rcx),%eax
ret ret
.seh_endproc .seh_endproc
@ -528,7 +528,7 @@ __ZN7_cygtls3popEv\@4:
1: pushl %ebx 1: pushl %ebx
movl %eax,%ebx # this movl %eax,%ebx # this
movl \$-4,%eax movl \$-4,%eax
xadd %eax,_cygtls.pstackptr(%ebx) xadd %eax,_cygtls.stackptr_p(%ebx)
movl -4(%eax),%eax movl -4(%eax),%eax
popl %ebx popl %ebx
ret ret
@ -539,7 +539,7 @@ __ZN7_cygtls4lockEv\@4:
pushl %ebx pushl %ebx
movl %eax,%ebx movl %eax,%ebx
1: movl \$1,%eax 1: movl \$1,%eax
xchgl %eax,_cygtls.pstacklock(%ebx) xchgl %eax,_cygtls.stacklock_p(%ebx)
testl %eax,%eax testl %eax,%eax
jz 2f jz 2f
call _yield call _yield
@ -550,12 +550,12 @@ __ZN7_cygtls4lockEv\@4:
# _cygtls::unlock # _cygtls::unlock
.global __ZN7_cygtls6unlockEv\@4 .global __ZN7_cygtls6unlockEv\@4
__ZN7_cygtls6unlockEv\@4: __ZN7_cygtls6unlockEv\@4:
decl _cygtls.pstacklock(%eax) decl _cygtls.stacklock_p(%eax)
ret ret
.global __ZN7_cygtls6lockedEv .global __ZN7_cygtls6lockedEv
__ZN7_cygtls6lockedEv: __ZN7_cygtls6lockedEv:
movl _cygtls.pstacklock(%eax),%eax movl _cygtls.stacklock_p(%eax),%eax
ret ret
.extern __ZN7_cygtls19call_signal_handlerEv\@4 .extern __ZN7_cygtls19call_signal_handlerEv\@4

View File

@ -43,7 +43,7 @@ gawk '
} }
' | \ ' | \
# Now run the compiler to generate an assembler file. # 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: # The assembler file consists of lines like these:
# #
# __CYGTLS__foo # __CYGTLS__foo
@ -63,7 +63,7 @@ gawk '\
/\s*\.space\s*4/ { /\s*\.space\s*4/ {
if (length (varname) > 0) { if (length (varname) > 0) {
printf (".equ _cygtls.%s, %d\n", varname, -start_offset); 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 = ""; varname = "";
} }
} }
@ -75,7 +75,7 @@ gawk '\
} else { } else {
value = $2; value = $2;
printf (".equ _cygtls.%s, %d\n", varname, value - start_offset); 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 = ""; varname = "";
} }