From patchwork Mon Aug 23 19:18:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Galibert X-Patchwork-Id: 44745 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BC7EA3858022 for ; Mon, 23 Aug 2021 19:20:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC7EA3858022 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629746415; bh=rXxFzxCxrHUhla2VD+ak4ZQ4tRHE2woJwHe7DX1VQn0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=wLeU8fIbjE8rv24GPpj+iwpiSbjvekhxkssYYegr9PigK/EfopITo7ODaCyniIftm d+s76X55eEABVhIxK98O5UAat1qeBvM0aCayKI4lEylZsUzOLc04E41WD8j1nJuTN7 RqjkPfYoPoQ6O21J80dGIhtnQxHbQaxW6BiOddgo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) by sourceware.org (Postfix) with ESMTPS id 79F0A3858038 for ; Mon, 23 Aug 2021 19:18:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 79F0A3858038 Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 53B12EFA11; Mon, 23 Aug 2021 15:18:59 -0400 (EDT) (envelope-from galibert@pobox.com) Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 4BF7BEFA10; Mon, 23 Aug 2021 15:18:59 -0400 (EDT) (envelope-from galibert@pobox.com) Received: from localhost.localdomain (unknown [78.197.126.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 421B1EFA0E; Mon, 23 Aug 2021 15:18:58 -0400 (EDT) (envelope-from galibert@pobox.com) To: libc-alpha@sourceware.org Subject: [PATCH] glibcextract: Make compute_c_consts compatible with both clang and gcc Date: Mon, 23 Aug 2021 21:18:53 +0200 Message-Id: <20210823191853.597904-1-galibert@pobox.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Pobox-Relay-ID: F761B84C-0446-11EC-AC64-FD8818BA3BAF-92059326!pb-smtp2.pobox.com X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Olivier Galibert via Libc-alpha From: Olivier Galibert Reply-To: Olivier Galibert Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "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 --- 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