glibcextract: Make compute_c_consts compatible with both clang and gcc

Message ID 20210823201347.599807-1-galibert@pobox.com
State Changes Requested, archived
Headers
Series glibcextract: Make compute_c_consts compatible with both clang and gcc |

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, 8:13 p.m. UTC
  clang parses the asm() contents even when using -S, so you can't
generate nonsensical code.  Use normal .ascii/.long instead.

v2: Remove leftover debugging code.

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

Patch

diff --git a/scripts/glibcextract.py b/scripts/glibcextract.py
index 752ff6223b..66f8c96a32 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('}')
@@ -62,16 +62,21 @@  def compute_c_consts(sym_data, cc):
         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