public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/maskray/grte] Make gen-XX-const scripts work with llvm-as
@ 2021-08-28  0:31 Fangrui Song
  0 siblings, 0 replies; 3+ messages in thread
From: Fangrui Song @ 2021-08-28  0:31 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ad41eacfb70e98e13cbfda076ded0c77b387ae8b

commit ad41eacfb70e98e13cbfda076ded0c77b387ae8b
Author: Josh Kunz <jkz@google.com>
Date:   Wed Aug 7 11:40:50 2019 -0700

    Make gen-XX-const scripts work with llvm-as
    
    The gen-as-const and gen-py-const scripts are used to generate integer constant
    definitions from a list of constant C-expressions. This is achieved by
    generating a C program with inline `asm` statements, that depend on
    these constant expressions. During compilation, the constant expressions
    are evaluated, and included in the inline asm. The build process
    generates only the assembly, and then used `sed` to extract the values
    from the assembly text.
    
    This is clever. It allows the build process to extract the value of C
    statements built under the target architecture. The implementation is a
    bit fragile, but it is not immediately obvious to me how it could be
    improved.
    
    This change slightly modifies `gen-as-const` and `gen-py-const` to emit
    valid assembly directives instead of invalid directives that were
    previously emitted. Since the values are extracted via string parsing,
    this has no effect on the values extracted. This is needed because the
    LLVM assembler validates all statements before emitting them, whereas it
    appears GCC will literally emit any `asm` directives without validation
    or recognition.

Diff:
---
 Makerules                | 5 ++---
 scripts/gen-as-const.awk | 2 +-
 scripts/gen-py-const.awk | 2 +-
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/Makerules b/Makerules
index 652879038c..1bffdcc147 100644
--- a/Makerules
+++ b/Makerules
@@ -260,7 +260,7 @@ $(py-const): $(py-const-dir)%.py: %.pysym $(py-const-script) \
 	     $(common-before-compile)
 	$(make-target-directory)
 	$(AWK) -f $(py-const-script) $< \
-	       | $(CC) -S $(MOARFLAGS) -o $@.tmp $(CFLAGS) $(CPPFLAGS) -x c -
+	       | $(CC) -S -o $@.tmp $(CFLAGS) $(CPPFLAGS) -x c -
 	echo '# GENERATED FILE\n' > $@.tmp2
 	echo '# Constant definitions for pretty printers.' >> $@.tmp2
 	echo '# See gen-py-const.awk for details.\n' >> $@.tmp2
@@ -276,11 +276,10 @@ ifdef gen-as-const-headers
 # Generating headers for assembly constants.
 # We need this defined early to get into before-compile before
 # it's used in sysd-rules, below.
-# clang's integrated assembler doesn't like the freaky tokens.
 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
 					   %.sym $(common-before-compile)
 	$(AWK) -f $< $(filter %.sym,$^) \
-	| $(CC) -S $(MOARFLAGS) -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
+	| $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
 		-MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
 	sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
 		$(@:.h.d=.h)T3 > $(@:.h.d=.h)T
diff --git a/scripts/gen-as-const.awk b/scripts/gen-as-const.awk
index 1ffd5f2c1c..36e6de303c 100644
--- a/scripts/gen-as-const.awk
+++ b/scripts/gen-as-const.awk
@@ -49,7 +49,7 @@ NF > 1 {
   if (test)
     print "  TEST (" name ", \"" FILENAME ":" FNR "\", " $0 ")";
   else
-    printf "asm (\"@@@name@@@%s@@@value@@@%%0@@@end@@@\" : : \"i\" ((long) %s));\n",
+    printf "asm (\".ascii \\\"@@@name@@@%s@@@value@@@%%0@@@end@@@\\\"\" : : \"i\" ((long) %s));\n",
       name, $0;
 }
 
diff --git a/scripts/gen-py-const.awk b/scripts/gen-py-const.awk
index 91220281c5..beb41964ee 100644
--- a/scripts/gen-py-const.awk
+++ b/scripts/gen-py-const.awk
@@ -111,7 +111,7 @@ NF > 1 {
 
     # '$0' ends up being everything that appeared after the first field
     # separator.
-    printf "  asm (\"@name@%s@value@%0@\" : : \"i\" (%s));\n", name, $0;
+    printf "  asm (\".ascii \\\"@name@%s@value@%0@\\\"\" : : \"i\" (%s));\n", name, $0;
 }
 
 # Close the 'dummy' function.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [glibc/maskray/grte] Make gen-XX-const scripts work with llvm-as
@ 2021-08-28  0:27 Fangrui Song
  0 siblings, 0 replies; 3+ messages in thread
From: Fangrui Song @ 2021-08-28  0:27 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=f1e907206494990929b175b7a0784b3d6899fbfb

commit f1e907206494990929b175b7a0784b3d6899fbfb
Author: Josh Kunz <jkz@google.com>
Date:   Wed Aug 7 11:40:50 2019 -0700

    Make gen-XX-const scripts work with llvm-as
    
    The gen-as-const and gen-py-const scripts are used to generate integer constant
    definitions from a list of constant C-expressions. This is achieved by
    generating a C program with inline `asm` statements, that depend on
    these constant expressions. During compilation, the constant expressions
    are evaluated, and included in the inline asm. The build process
    generates only the assembly, and then used `sed` to extract the values
    from the assembly text.
    
    This is clever. It allows the build process to extract the value of C
    statements built under the target architecture. The implementation is a
    bit fragile, but it is not immediately obvious to me how it could be
    improved.
    
    This change slightly modifies `gen-as-const` and `gen-py-const` to emit
    valid assembly directives instead of invalid directives that were
    previously emitted. Since the values are extracted via string parsing,
    this has no effect on the values extracted. This is needed because the
    LLVM assembler validates all statements before emitting them, whereas it
    appears GCC will literally emit any `asm` directives without validation
    or recognition.

Diff:
---
 Makerules                | 5 ++---
 scripts/gen-as-const.awk | 2 +-
 scripts/gen-py-const.awk | 2 +-
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/Makerules b/Makerules
index 652879038c..1bffdcc147 100644
--- a/Makerules
+++ b/Makerules
@@ -260,7 +260,7 @@ $(py-const): $(py-const-dir)%.py: %.pysym $(py-const-script) \
 	     $(common-before-compile)
 	$(make-target-directory)
 	$(AWK) -f $(py-const-script) $< \
-	       | $(CC) -S $(MOARFLAGS) -o $@.tmp $(CFLAGS) $(CPPFLAGS) -x c -
+	       | $(CC) -S -o $@.tmp $(CFLAGS) $(CPPFLAGS) -x c -
 	echo '# GENERATED FILE\n' > $@.tmp2
 	echo '# Constant definitions for pretty printers.' >> $@.tmp2
 	echo '# See gen-py-const.awk for details.\n' >> $@.tmp2
@@ -276,11 +276,10 @@ ifdef gen-as-const-headers
 # Generating headers for assembly constants.
 # We need this defined early to get into before-compile before
 # it's used in sysd-rules, below.
-# clang's integrated assembler doesn't like the freaky tokens.
 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
 					   %.sym $(common-before-compile)
 	$(AWK) -f $< $(filter %.sym,$^) \
-	| $(CC) -S $(MOARFLAGS) -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
+	| $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
 		-MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
 	sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
 		$(@:.h.d=.h)T3 > $(@:.h.d=.h)T
diff --git a/scripts/gen-as-const.awk b/scripts/gen-as-const.awk
index 1ffd5f2c1c..36e6de303c 100644
--- a/scripts/gen-as-const.awk
+++ b/scripts/gen-as-const.awk
@@ -49,7 +49,7 @@ NF > 1 {
   if (test)
     print "  TEST (" name ", \"" FILENAME ":" FNR "\", " $0 ")";
   else
-    printf "asm (\"@@@name@@@%s@@@value@@@%%0@@@end@@@\" : : \"i\" ((long) %s));\n",
+    printf "asm (\".ascii \\\"@@@name@@@%s@@@value@@@%%0@@@end@@@\\\"\" : : \"i\" ((long) %s));\n",
       name, $0;
 }
 
diff --git a/scripts/gen-py-const.awk b/scripts/gen-py-const.awk
index 91220281c5..beb41964ee 100644
--- a/scripts/gen-py-const.awk
+++ b/scripts/gen-py-const.awk
@@ -111,7 +111,7 @@ NF > 1 {
 
     # '$0' ends up being everything that appeared after the first field
     # separator.
-    printf "  asm (\"@name@%s@value@%0@\" : : \"i\" (%s));\n", name, $0;
+    printf "  asm (\".ascii \\\"@name@%s@value@%0@\\\"\" : : \"i\" (%s));\n", name, $0;
 }
 
 # Close the 'dummy' function.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [glibc/maskray/grte] Make gen-XX-const scripts work with llvm-as
@ 2021-08-27 23:50 Fangrui Song
  0 siblings, 0 replies; 3+ messages in thread
From: Fangrui Song @ 2021-08-27 23:50 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=4d7496a48487ba92199e319de296d7dfa9d81e6d

commit 4d7496a48487ba92199e319de296d7dfa9d81e6d
Author: Josh Kunz <jkz@google.com>
Date:   Wed Aug 7 11:40:50 2019 -0700

    Make gen-XX-const scripts work with llvm-as
    
    The gen-as-const and gen-py-const scripts are used to generate integer constant
    definitions from a list of constant C-expressions. This is achieved by
    generating a C program with inline `asm` statements, that depend on
    these constant expressions. During compilation, the constant expressions
    are evaluated, and included in the inline asm. The build process
    generates only the assembly, and then used `sed` to extract the values
    from the assembly text.
    
    This is clever. It allows the build process to extract the value of C
    statements built under the target architecture. The implementation is a
    bit fragile, but it is not immediately obvious to me how it could be
    improved.
    
    This change slightly modifies `gen-as-const` and `gen-py-const` to emit
    valid assembly directives instead of invalid directives that were
    previously emitted. Since the values are extracted via string parsing,
    this has no effect on the values extracted. This is needed because the
    LLVM assembler validates all statements before emitting them, whereas it
    appears GCC will literally emit any `asm` directives without validation
    or recognition.

Diff:
---
 Makerules                | 5 ++---
 scripts/gen-as-const.awk | 2 +-
 scripts/gen-py-const.awk | 2 +-
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/Makerules b/Makerules
index 652879038c..1bffdcc147 100644
--- a/Makerules
+++ b/Makerules
@@ -260,7 +260,7 @@ $(py-const): $(py-const-dir)%.py: %.pysym $(py-const-script) \
 	     $(common-before-compile)
 	$(make-target-directory)
 	$(AWK) -f $(py-const-script) $< \
-	       | $(CC) -S $(MOARFLAGS) -o $@.tmp $(CFLAGS) $(CPPFLAGS) -x c -
+	       | $(CC) -S -o $@.tmp $(CFLAGS) $(CPPFLAGS) -x c -
 	echo '# GENERATED FILE\n' > $@.tmp2
 	echo '# Constant definitions for pretty printers.' >> $@.tmp2
 	echo '# See gen-py-const.awk for details.\n' >> $@.tmp2
@@ -276,11 +276,10 @@ ifdef gen-as-const-headers
 # Generating headers for assembly constants.
 # We need this defined early to get into before-compile before
 # it's used in sysd-rules, below.
-# clang's integrated assembler doesn't like the freaky tokens.
 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
 					   %.sym $(common-before-compile)
 	$(AWK) -f $< $(filter %.sym,$^) \
-	| $(CC) -S $(MOARFLAGS) -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
+	| $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
 		-MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
 	sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
 		$(@:.h.d=.h)T3 > $(@:.h.d=.h)T
diff --git a/scripts/gen-as-const.awk b/scripts/gen-as-const.awk
index 1ffd5f2c1c..36e6de303c 100644
--- a/scripts/gen-as-const.awk
+++ b/scripts/gen-as-const.awk
@@ -49,7 +49,7 @@ NF > 1 {
   if (test)
     print "  TEST (" name ", \"" FILENAME ":" FNR "\", " $0 ")";
   else
-    printf "asm (\"@@@name@@@%s@@@value@@@%%0@@@end@@@\" : : \"i\" ((long) %s));\n",
+    printf "asm (\".ascii \\\"@@@name@@@%s@@@value@@@%%0@@@end@@@\\\"\" : : \"i\" ((long) %s));\n",
       name, $0;
 }
 
diff --git a/scripts/gen-py-const.awk b/scripts/gen-py-const.awk
index 91220281c5..beb41964ee 100644
--- a/scripts/gen-py-const.awk
+++ b/scripts/gen-py-const.awk
@@ -111,7 +111,7 @@ NF > 1 {
 
     # '$0' ends up being everything that appeared after the first field
     # separator.
-    printf "  asm (\"@name@%s@value@%0@\" : : \"i\" (%s));\n", name, $0;
+    printf "  asm (\".ascii \\\"@name@%s@value@%0@\\\"\" : : \"i\" (%s));\n", name, $0;
 }
 
 # Close the 'dummy' function.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-28  0:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-28  0:31 [glibc/maskray/grte] Make gen-XX-const scripts work with llvm-as Fangrui Song
  -- strict thread matches above, loose matches on Subject: below --
2021-08-28  0:27 Fangrui Song
2021-08-27 23:50 Fangrui Song

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).