]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Make gen-XX-const scripts work with llvm-as
authorJosh Kunz <jkz@google.com>
Wed, 7 Aug 2019 18:40:50 +0000 (11:40 -0700)
committerFangrui Song <i@maskray.me>
Sat, 28 Aug 2021 00:26:02 +0000 (17:26 -0700)
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.

Makerules
scripts/gen-as-const.awk
scripts/gen-py-const.awk

index 652879038cc9f563431facccd90a2ea50ef7c89c..1bffdcc147823e76f71c3ce2dba0536aee60e75b 100644 (file)
--- 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
index 1ffd5f2c1cbd8c7f59fe8173f542d668f8aff852..36e6de303c769fe9f22723f3b8ae87471f3027e2 100644 (file)
@@ -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;
 }
 
index 91220281c592a0ca8af9d498948f9b650bbb00a5..beb41964eefd12d06c64262f41e36ada30340ed0 100644 (file)
@@ -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.