From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id ACA9D384B0C5; Wed, 18 May 2022 19:05:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ACA9D384B0C5 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: Use two pass parse for tlsoffsets generation. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 12d07e1ddd2d5164d766a8804fae738e6acff11b X-Git-Newrev: 1559f7f4581832f05339b950fc7c82a8c98a9e0f Message-Id: <20220518190536.ACA9D384B0C5@sourceware.org> Date: Wed, 18 May 2022 19:05:36 +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: Wed, 18 May 2022 19:05:36 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D1559f7f4581= 832f05339b950fc7c82a8c98a9e0f commit 1559f7f4581832f05339b950fc7c82a8c98a9e0f Author: Takashi Yano Date: Thu May 19 02:51:46 2022 +0900 Cygwin: Use two pass parse for tlsoffsets generation. =20 - The commit "Cygwin: fix new sigfe.o generation in optimized case" fixed the wrong tlsoffsets generation by adding -O0 to compile options. Current gentls_offsets expects entry of "start_offset" is the first entry in the assembler code. However, without -O0, entry of "start_offset" goes to the last entry for some reason. Currently, -O0 can prevents assembler code from reversing the order of the entries, however, there is no guarantee that it will retain the order of the entries in the future. =20 This patch makes gentls_offsets parse the assembler code in the two pass to omit -O0 option dependency. Diff: --- winsup/cygwin/gentls_offsets | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/winsup/cygwin/gentls_offsets b/winsup/cygwin/gentls_offsets index d76562c05..0adb702a3 100755 --- a/winsup/cygwin/gentls_offsets +++ b/winsup/cygwin/gentls_offsets @@ -2,6 +2,9 @@ #set -x input_file=3D$1 output_file=3D$2 +tmp_file=3D/tmp/${output_file}.$$ + +trap "rm -f ${tmp_file}" 0 1 2 15 =20 # Preprocess cygtls.h and filter out only the member lines from # class _cygtls to generate an input file for the cross compiler @@ -43,7 +46,7 @@ gawk ' } ' | \ # Now run the compiler to generate an assembler file. -${CXXCOMPILE} -x c++ -g0 -O0 -S - -o - | \ +${CXXCOMPILE} -x c++ -g0 -S - -o ${tmp_file} && \ # The assembler file consists of lines like these: # # __CYGTLS__foo @@ -52,10 +55,25 @@ ${CXXCOMPILE} -x c++ -g0 -O0 -S - -o - | \ # .align 4 # # From this info, generate the tlsoffsets file. -gawk '\ +start_offset=3D$(gawk '\ + BEGIN { + varname=3D"" + } + /^__CYGTLS__/ { + varname =3D gensub (/__CYGTLS__(\w+):/, "\\1", "g"); + } + /\s*\.long\s+/ { + if (length (varname) > 0) { + if (varname =3D=3D "start_offset") { + print $2; + } + varname =3D ""; + } + } +' ${tmp_file}) && \ +gawk -v start_offset=3D"$start_offset" '\ BEGIN { varname=3D"" - start_offset =3D 0 } /^__CYGTLS__/ { varname =3D gensub (/__CYGTLS__(\w+):/, "\\1", "g"); @@ -70,7 +88,6 @@ gawk '\ /\s*\.long\s+/ { if (length (varname) > 0) { if (varname =3D=3D "start_offset") { - start_offset =3D $2; printf (".equ _cygtls.%s, -%u\n", varname, start_offset); } else { value =3D $2; @@ -80,4 +97,4 @@ gawk '\ varname =3D ""; } } -' > "${output_file}" +' ${tmp_file} > "${output_file}"