public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin-patches@cygwin.com
Subject: [PATCH] Cygwin: Use two pass parse for tlsoffsets generation.
Date: Thu, 19 May 2022 03:22:35 +0900	[thread overview]
Message-ID: <20220518182235.9203-1-takashi.yano@nifty.ne.jp> (raw)

- 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 entry, however, there is no guarantee will retain
  the order of the entries in the future.

  This patch make gentls_offsets parse the assembler code in the
  two pass to omit -O0 option dependency.
---
 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..111e6aa78 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 -O0 -S - -o - | \
+${CXXCOMPILE} -x c++ -g0 -S - -o ${output_file}.s && \
 # The assembler file consists of lines like these:
 #
 #   __CYGTLS__foo
@@ -52,10 +52,25 @@ ${CXXCOMPILE} -x c++ -g0 -O0 -S - -o - | \
 #       .align 4
 #
 # From this info, generate the tlsoffsets file.
-gawk '\
+start_offset=$(gawk '\
+  BEGIN {
+    varname=""
+  }
+  /^__CYGTLS__/ {
+    varname = gensub (/__CYGTLS__(\w+):/, "\\1", "g");
+  }
+  /\s*\.long\s+/ {
+    if (length (varname) > 0) {
+      if (varname == "start_offset") {
+	print $2;
+      }
+      varname = "";
+    }
+  }
+' ${output_file}.s) && \
+gawk -v start_offset="$start_offset" '\
   BEGIN {
     varname=""
-    start_offset = 0
   }
   /^__CYGTLS__/ {
     varname = gensub (/__CYGTLS__(\w+):/, "\\1", "g");
@@ -70,7 +85,6 @@ gawk '\
   /\s*\.long\s+/ {
     if (length (varname) > 0) {
       if (varname == "start_offset") {
-      	start_offset = $2;
 	printf (".equ _cygtls.%s, -%u\n", varname, start_offset);
       } else {
       	value = $2;
@@ -80,4 +94,7 @@ gawk '\
       varname = "";
     }
   }
-' > "${output_file}"
+' ${output_file}.s > "${output_file}"
+ret=$?
+rm -f ${output_file}.s
+exit $ret
-- 
2.36.1


                 reply	other threads:[~2022-05-18 18:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220518182235.9203-1-takashi.yano@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=cygwin-patches@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).