diff mbox series

glibcextract: Make compute_c_consts compatible with both clang and gcc

Message ID 20210823191853.597904-1-galibert@pobox.com
State Superseded
Headers show
Series glibcextract: Make compute_c_consts compatible with both clang and gcc | expand

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Olivier Galibert Aug. 23, 2021, 7:18 p.m. UTC
clang parses the asm() contents even when using -S, so you can't
generate nonsensical code.  Use normal .ascii/.long instead.

Signed-off-by: Olivier Galibert <galibert@pobox.com>
---
 scripts/glibcextract.py | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

Comments

Joseph Myers Aug. 23, 2021, 8:01 p.m. UTC | #1
On Mon, 23 Aug 2021, Olivier Galibert via Libc-alpha wrote:

> @@ -59,19 +59,26 @@ def compute_c_consts(sym_data, cc):
>          # Compilation has to be from stdin to avoid the temporary file
>          # name being written into the generated dependencies.
>          cmd = ('%s -S -o %s -x c - < %s' % (cc, s_file_name, c_file_name))
> +        with open("t.c", 'w') as c_file:
> +            c_file.write(out_text)
>          subprocess.check_call(cmd, shell=True)

This looks like debugging code left in the patch by mistake.
diff mbox series

Patch

diff --git a/scripts/glibcextract.py b/scripts/glibcextract.py
index 752ff6223b..d92d7aed70 100644
--- a/scripts/glibcextract.py
+++ b/scripts/glibcextract.py
@@ -45,7 +45,7 @@  def compute_c_consts(sym_data, cc):
             continue
         name = arg[0]
         value = arg[1]
-        out_lines.append('asm ("@@@name@@@%s@@@value@@@%%0@@@end@@@" '
+        out_lines.append('asm (".ascii \\\"%s\\\"\\n\\t.long %%0\\n" '
                          ': : \"i\" ((long int) (%s)));'
                          % (name, value))
     out_lines.append('}')
@@ -59,19 +59,26 @@  def compute_c_consts(sym_data, cc):
         # Compilation has to be from stdin to avoid the temporary file
         # name being written into the generated dependencies.
         cmd = ('%s -S -o %s -x c - < %s' % (cc, s_file_name, c_file_name))
+        with open("t.c", 'w') as c_file:
+            c_file.write(out_text)
         subprocess.check_call(cmd, shell=True)
         consts = {}
         with open(s_file_name, 'r') as s_file:
+            symbol = None
             for line in s_file:
-                match = re.search('@@@name@@@([^@]*)'
-                                  '@@@value@@@[^0-9Xxa-fA-F-]*'
-                                  '([0-9Xxa-fA-F-]+).*@@@end@@@', line)
+                match = re.search('[.]ascii[ \t]*"([^"]*)"', line)
                 if match:
-                    if (match.group(1) in consts
-                        and match.group(2) != consts[match.group(1)]):
-                        raise ValueError('duplicate constant %s'
-                                         % match.group(1))
-                    consts[match.group(1)] = match.group(2)
+                    symbol = match.group(1)
+                elif symbol != None:
+                    match = re.search('[.]long[ \t]*[(]?[$]([0-9Xxa-fA-F-]+)', line)
+                    if match:
+                        if (symbol in consts
+                            and match.group(1) != consts[symbol]):
+                            raise ValueError('duplicate constant %s'
+                                             % symbol)
+                        consts[symbol] = match.group(1)
+                    else:
+                        symbol = None
         return consts