]> sourceware.org Git - newlib-cygwin.git/commitdiff
Cygwin: Use two pass parse for tlsoffsets generation.
authorTakashi Yano <takashi.yano@nifty.ne.jp>
Wed, 18 May 2022 17:51:46 +0000 (02:51 +0900)
committerTakashi Yano <takashi.yano@nifty.ne.jp>
Wed, 18 May 2022 19:03:16 +0000 (04:03 +0900)
- 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.

  This patch makes gentls_offsets parse the assembler code in the
  two pass to omit -O0 option dependency.

winsup/cygwin/gentls_offsets

index d76562c05bf223989d2dee40425d07403c352fe5..0adb702a389d378e702156a4c03d438f1c15f957 100755 (executable)
@@ -2,6 +2,9 @@
 #set -x
 input_file=$1
 output_file=$2
+tmp_file=/tmp/${output_file}.$$
+
+trap "rm -f ${tmp_file}" 0 1 2 15
 
 # 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=$(gawk '\
+  BEGIN {
+    varname=""
+  }
+  /^__CYGTLS__/ {
+    varname = gensub (/__CYGTLS__(\w+):/, "\\1", "g");
+  }
+  /\s*\.long\s+/ {
+    if (length (varname) > 0) {
+      if (varname == "start_offset") {
+       print $2;
+      }
+      varname = "";
+    }
+  }
+' ${tmp_file}) && \
+gawk -v start_offset="$start_offset" '\
   BEGIN {
     varname=""
-    start_offset = 0
   }
   /^__CYGTLS__/ {
     varname = gensub (/__CYGTLS__(\w+):/, "\\1", "g");
@@ -70,7 +88,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 +97,4 @@ gawk '\
       varname = "";
     }
   }
-' > "${output_file}"
+' ${tmp_file} > "${output_file}"
This page took 0.033322 seconds and 5 git commands to generate.