From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id 6F572384F494; Fri, 18 Nov 2022 11:46:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F572384F494 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668771992; bh=VEa12RxsBXgwb43niqgqvgYxz6qldMgsBk1lYPlhB4I=; h=From:To:Subject:Date:From; b=YipccMOtpqO2QuLP+nzv+RxcNe1Os30kpPK4WeGVAUws0x58GKlztD0RDpJo+36K/ gJ0aOKyMA75T91q3zOIGxk4ByzphnS9Rz3DbWLkcitfONB1UUo4m9Z6kqfake3zj+h EYxw5U/X6edG/mmwbU/L0Ro+bzhI3Az+Zk+NZzts= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/testsuite: fix gdb.compile/compile-ops.exp with clang X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 33c1395cf5e9deec7733691ba32c450e5c27f757 X-Git-Newrev: ed64647b7f32b067e910ae7b24b477e11b268d5d Message-Id: <20221118114632.6F572384F494@sourceware.org> Date: Fri, 18 Nov 2022 11:46:32 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Ded64647b7f32= b067e910ae7b24b477e11b268d5d commit ed64647b7f32b067e910ae7b24b477e11b268d5d Author: Andrew Burgess Date: Fri Nov 11 15:35:05 2022 +0000 gdb/testsuite: fix gdb.compile/compile-ops.exp with clang =20 I noticed that the gdb.compile/compile-ops.exp test was failing when run with Clang as the compiler. =20 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: =20 # If the compiler is gcc, we can do the following to get function sta= rt # 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 clan= g, # 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) {} =20 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: =20 # int main (void) # { # asm ("main_label: .globl main_label"); # return 0; # } =20 And make use of 'proc function_range' (from lib/dwarf.exp). =20 So, that's what I do in this commit. =20 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. =20 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. =20 The only other change, which might be a problem, is that I also deleted these two lines from the source file: =20 asm (".section \".text\""); asm (".balign 8"); =20 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. =20 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. =20 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. =20 But, if people would prefer to be more conservative, then I'm happy to just add the lines back. =20 Reviewed-By: Lancelot SIX Diff: --- 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.co= mpile/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 =3D 0xdeadf00d; int *ptr =3D &value; =20 -asm (".section \".text\""); -asm (".balign 8"); -asm ("func_start: .globl func_start"); - static void func (void) { + asm ("func_label: .globl func_label"); } =20 -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 } =20 -standard_testfile .c gdbjit-ops.S +standard_testfile .c -dbg.S =20 # # A port of the pr10770.c test code to the DWARF assembler format. @@ -354,9 +354,17 @@ set program [subst { addr ptr }] =20 +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 =20 @@ -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}