[PATCH] glibcextract: Make compute_c_consts compatible with both clang and gcc
Olivier Galibert
galibert@pobox.com
Mon Aug 23 19:18:53 GMT 2021
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(-)
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
--
2.33.0
More information about the Libc-alpha
mailing list