From patchwork Fri Nov 11 16:36:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 60434 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 B338C383EC43 for ; Fri, 11 Nov 2022 16:37:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B338C383EC43 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668184633; bh=SBS2MvXVLo2wTLHjP+nXT8Bw62ZGXxrOkCDE+4JWgSM=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=QHAu0JZeP8fP0S8x9RvZI6oEdkS6xOF6/N3mQBqB8IS7sOkZZ3WFaMDfg86StuBiM eumCXbxQHTtLUEkVi1neKipDU2l4EhGpjzv/APyh+I1J2gwdMuFNAP0sdF/7OVywuP PDgUc3O1EjR/xtcQEHe0rkd1ABAifQsC2vNYZZ5Q= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id EF94538582AC for ; Fri, 11 Nov 2022 16:36:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EF94538582AC Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-407-AiaffWBtNBm3QLR7I8ABFw-1; Fri, 11 Nov 2022 11:36:38 -0500 X-MC-Unique: AiaffWBtNBm3QLR7I8ABFw-1 Received: by mail-qk1-f198.google.com with SMTP id v7-20020a05620a0f0700b006faffce43b2so5086037qkl.9 for ; Fri, 11 Nov 2022 08:36:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SBS2MvXVLo2wTLHjP+nXT8Bw62ZGXxrOkCDE+4JWgSM=; b=wV7wDCv1JBAof6aerD+8lnbtR05OuSFpHXMEYJ1IoM7DV9hmV0ipGHH1a+zdwsj/T3 ikxcNCSNWnOQWhKKcehIe+AIsNJ0sl0KBYsVec+JAn2sqPaXatzCVInxAGIMrWwaFR/V 2P1Mdgxojb+qhw+lt3ZfEw5LyX8M+5ZfhYNJbDyqKtuGAAcAG/R5WgWqElG12FYBQ2b2 0WPb+ffbrXME+cEWCiAQALDvkW8k7Qtr3VahdVREQQp81uSLTFdhcfckLiZBves+CxUw SFL1T96dj7h/6YaeB4CVrrVrP1s02BO7523PphfGJ0642UKUKYxRxI1iDSzfPHpZGxVa Oy+Q== X-Gm-Message-State: ANoB5pmkRfI5rNdbJehyfV+OMsmxUKJ8Niy9+tyTUoHTJFiqZobSIk59 Alp/wpqX1G7PnLjz0hiElApkF7XQn8rNZAJO0ABk0jXG3v+RhIzr4qPSvTYpAHLun62rYwryk49 MJ+V3hWfUnCOPsl/l88wBrBoI7AOp9Bqp66z/iCL09/lTg54h+MhcljYrK7Q++RyGvFr6G2mDWA == X-Received: by 2002:a05:622a:5816:b0:3a5:1a23:ca39 with SMTP id fg22-20020a05622a581600b003a51a23ca39mr2037780qtb.109.1668184597786; Fri, 11 Nov 2022 08:36:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf5NmVTvZuz64VgydvFFcwihQ7VeHSYZt0STLuoatBWdOo81NN7N0h23VRCHPmqsMcNTuD+gZw== X-Received: by 2002:a05:622a:5816:b0:3a5:1a23:ca39 with SMTP id fg22-20020a05622a581600b003a51a23ca39mr2037748qtb.109.1668184597474; Fri, 11 Nov 2022 08:36:37 -0800 (PST) Received: from localhost ([31.111.84.238]) by smtp.gmail.com with ESMTPSA id v22-20020a05620a441600b006faac3c33b8sm1738723qkp.27.2022.11.11.08.36.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 08:36:37 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 3/6] gdb/testsuite: fix gdb.compile/compile-ops.exp with clang Date: Fri, 11 Nov 2022 16:36:22 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" I noticed that the gdb.compile/compile-ops.exp test was failing when run with Clang as the compiler. This test makes use of the DWARF assembler, and, it turns out, uses a technique which is not portable to Clang. This problem is described in the comment on the function_range proc in lib/dwarf.exp, the explanation is: # If the compiler is gcc, we can do the following to get function start # and end address too: # # asm ("func_start: .globl func_start"); # static void func (void) {} # asm ("func_end: .globl func_end"); # # however, this isn't portable, because other compilers, such as clang, # may not guarantee the order of global asms and function. The code # becomes: # # asm ("func_start: .globl func_start"); # asm ("func_end: .globl func_end"); # static void func (void) {} These start/end labels are used for computing the function start, end, and length. The portable solution is to place a label within the function, like this: # int main (void) # { # asm ("main_label: .globl main_label"); # return 0; # } And make use of 'proc function_range' (from lib/dwarf.exp). So, that's what I do in this commit. One consequence of this change is that we need to compile the source file, and have it loaded into a GDB session, before calling function_range, so I've added an early call to prepare_for_testing. Additionally, this test script was generating the DWARF assembler into a file called gdbjit-ops.S, I suspect a copy and paste issue there, so I've switched this to use compile-ops-dbg.S instead, which is more inline with what other DWARF assembler tests do. The only other change, which might be a problem, is that I also deleted these two lines from the source file: asm (".section \".text\""); asm (".balign 8"); These lines were setting the alignment of the .text section. What I don't know is whether this was significant or not. If it is significant, then I can't see why. On x86-64, the test still passes fine without these lines, but that doesn't mean the test wont start failing on some other architecture. Still, I figure, lets remove them, then, if/when we find a test that starts failing, we can add the lines back, along with an explanation for why the extra alignment is required. But, if people would prefer to be more conservative, then I'm happy to just add the lines back. --- gdb/testsuite/gdb.compile/compile-ops.c | 8 ++------ gdb/testsuite/gdb.compile/compile-ops.exp | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/gdb/testsuite/gdb.compile/compile-ops.c b/gdb/testsuite/gdb.compile/compile-ops.c index 28afe628e35..7a35909e21e 100644 --- a/gdb/testsuite/gdb.compile/compile-ops.c +++ b/gdb/testsuite/gdb.compile/compile-ops.c @@ -18,20 +18,16 @@ int value = 0xdeadf00d; int *ptr = &value; -asm (".section \".text\""); -asm (".balign 8"); -asm ("func_start: .globl func_start"); - static void func (void) { + asm ("func_label: .globl func_label"); } -asm ("func_end: .globl func_end"); - int main (void) { + asm ("main_label: .globl main_label"); func (); return 0; } diff --git a/gdb/testsuite/gdb.compile/compile-ops.exp b/gdb/testsuite/gdb.compile/compile-ops.exp index b3b14d949d8..76f284f52f3 100644 --- a/gdb/testsuite/gdb.compile/compile-ops.exp +++ b/gdb/testsuite/gdb.compile/compile-ops.exp @@ -23,7 +23,7 @@ if {![dwarf2_support]} { return 0 } -standard_testfile .c gdbjit-ops.S +standard_testfile .c -dbg.S # # A port of the pr10770.c test code to the DWARF assembler format. @@ -354,9 +354,17 @@ set program [subst { addr ptr }] +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { + return -1 +} + # Make some DWARF for the test. set asm_file [standard_output_file $srcfile2] Dwarf::assemble $asm_file { + + # Find start, end, and length of "func". + get_func_info func + # Creating a CU with 4-byte addresses lets this test link on both # 32- and 64-bit machines. cu { addr_size 4 } { @@ -366,8 +374,8 @@ Dwarf::assemble $asm_file { compile_unit { {name file1.txt} {language @DW_LANG_C} - {low_pc func_start addr} - {high_pc func_end addr} + {low_pc $func_start addr} + {high_pc $func_end addr} } { global program @@ -380,8 +388,8 @@ Dwarf::assemble $asm_file { subprogram { {external 1 flag} {name func} - {low_pc func_start addr} - {high_pc func_end addr} + {low_pc $func_start addr} + {high_pc $func_end addr} } { formal_parameter { {name param}