public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] glibcextract: Make compute_c_consts compatible with both clang and gcc
@ 2021-08-23 19:18 Olivier Galibert
  2021-08-23 20:01 ` Joseph Myers
  0 siblings, 1 reply; 3+ messages in thread
From: Olivier Galibert @ 2021-08-23 19:18 UTC (permalink / raw)
  To: libc-alpha

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


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

* Re: [PATCH] glibcextract: Make compute_c_consts compatible with both clang and gcc
  2021-08-23 19:18 [PATCH] glibcextract: Make compute_c_consts compatible with both clang and gcc Olivier Galibert
@ 2021-08-23 20:01 ` Joseph Myers
  2021-08-23 20:13   ` Olivier Galibert
  0 siblings, 1 reply; 3+ messages in thread
From: Joseph Myers @ 2021-08-23 20:01 UTC (permalink / raw)
  To: Olivier Galibert; +Cc: libc-alpha

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.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* [PATCH] glibcextract: Make compute_c_consts compatible with both clang and gcc
  2021-08-23 20:01 ` Joseph Myers
@ 2021-08-23 20:13   ` Olivier Galibert
  0 siblings, 0 replies; 3+ messages in thread
From: Olivier Galibert @ 2021-08-23 20:13 UTC (permalink / raw)
  To: libc-alpha; +Cc: Joseph Myers, Olivier Galibert

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

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
 
 
-- 
2.33.0


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

end of thread, other threads:[~2021-08-23 20:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-23 19:18 [PATCH] glibcextract: Make compute_c_consts compatible with both clang and gcc Olivier Galibert
2021-08-23 20:01 ` Joseph Myers
2021-08-23 20:13   ` Olivier Galibert

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