From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 25A5B3858C2A for ; Mon, 16 Oct 2023 09:21:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 25A5B3858C2A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 25A5B3858C2A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:2178:6::1c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697448072; cv=none; b=I9TPF7mzSlPtPX2owcxD3OSvk1Xy3NsMQjLBik6JhvhAreisWEwJ7MgRDQFSTbADd7OHUV9abCSQWdZVEMFW7q3NU+u2Iqtu3Nd1294Z1v73AEIYikbjyQmKQB7ruE9N+bpaR1CaV9rpEsnBZXtLLW4yWCKK8o45OcMg+hKoTic= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697448072; c=relaxed/simple; bh=Vwdoe8NFV/KIwROBUlUFBZa0UVD9Z4Tf9ECM7XOIpRA=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version: Subject:To:From; b=WZ5W9tOM8d2+BWQNtWOBOAkxjQAZq7p1jWnePqh618FL9HtnNRRfOSLdSAH21+3cq5MQ1AUh+JdVcNPQuFEpBMDs1xSsYZ2sV0iFkvYVbuQRt66fvKmmpIveyDtGqIY7fiLm0dPy7/sjhfsFq1Kzr4t1Eb/aiqQ/12k9hMLyLfc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BF43721C4C for ; Mon, 16 Oct 2023 09:21:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1697448068; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aPq0pzM50o578ta7/MBB3diA8atClgi2SUNfcHdXe9k=; b=W/vwo5MRFJ7ET8hgQYfzsFNX2J6JKS1IdQAD0jOKwiN/fRB3jAdGNXpOBZrffFBPGo/mj7 qRlSHl0ig+r0huIh60OirmhRMSscFYc7L25piG0ZCrn6+j/DXj97EFjhQxdMqGFOcRW0Ks 8zjXPMuiny4HZFcyOx5Juk12NE8O1xo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1697448068; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aPq0pzM50o578ta7/MBB3diA8atClgi2SUNfcHdXe9k=; b=8SCgDTIilZFll2BxGzZdFH9zczntz1GU5C13FwYyQNJLtbZXTKmuqkneu6dEUCODtwrX5K z8tyiV0P68kGnbAw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id AB6A1138EF for ; Mon, 16 Oct 2023 09:21:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WtCwJ4QALWUILwAAMHmgww (envelope-from ) for ; Mon, 16 Oct 2023 09:21:08 +0000 Message-ID: <786e514c-6ff7-452e-a52e-5d727942d1c0@suse.de> Date: Mon, 16 Oct 2023 11:21:35 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PING][PATCH] [gdb/symtab] Work around PR gas/29517 Content-Language: en-US To: gdb-patches@sourceware.org References: <20230928160748.16042-1-tdevries@suse.de> From: Tom de Vries In-Reply-To: <20230928160748.16042-1-tdevries@suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -1.09 X-Spamd-Result: default: False [-1.09 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; XM_UA_NO_VERSION(0.01)[]; TO_DN_NONE(0.00)[]; NEURAL_HAM_SHORT(-1.00)[-0.999]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_MATCH_FROM(0.00)[]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCPT_COUNT_ONE(0.00)[1]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_SPAM_LONG(3.00)[1.000]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[] X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_NUMSUBJECT,SPF_HELO_NONE,SPF_PASS,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 List-Id: On 9/28/23 18:07, Tom de Vries via Gdb-patches wrote: > When using glibc debuginfo generated with gas 2.39, we run into PR gas/29517: > ... > $ gdb -q -batch a.out -ex start -ex "p (char *)strstr (\"haha\", \"ah\")" > Temporary breakpoint 1 at 0x40051b: file hello.c, line 6. > > Temporary breakpoint 1, main () at hello.c:6 > 6 printf ("hello\n"); > Invalid cast. > ... > while without glibc debuginfo installed we get the expected result: > ... > $n = 0x7ffff7daa1b1 "aha" > ... > and likewise with glibc debuginfo generated with gas 2.40. > > The strstr ifunc resolves to __strstr_sse2_unaligned. The problem is that gas > generates dwarf that states that the return type is void: > ... > <1><3e1e58>: Abbrev Number: 2 (DW_TAG_subprogram) > <3e1e59> DW_AT_name : __strstr_sse2_unaligned > <3e1e5d> DW_AT_external : 1 > <3e1e5e> DW_AT_low_pc : 0xbbd2e > <3e1e66> DW_AT_high_pc : 0xbc1c3 > ... > while the return type should be a DW_TAG_unspecified_type, as is the case > with gas 2.40. > > We can still use the workaround of casting to another function type for both > __strstr_sse2_unaligned: > ... > (gdb) p ((char * (*) (const char *, const char *))__strstr_sse2_unaligned) \ > ("haha", "ah") > $n = 0x7ffff7daa211 "aha" > ... > and strstr (which requires using *strstr to dereference the ifunc before we > cast): > ... > gdb) p ((char * (*) (const char *, const char *))*strstr) ("haha", "ah") > $n = 0x7ffff7daa251 "aha" > ... > but that's a bit cumbersome to use. > > Work around this in the dwarf reader, such that we have instead: > ... > (gdb) p (char *)strstr ("haha", "ah") > $n = 0x7ffff7daa1b1 "aha" > ... > > This also requires fixing producer_is_gcc to stop returning true for > producer "GNU AS 2.39.0". > > Tested on x86_64-linux. > Ping. Thanks, - Tom > PR symtab/30911 > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30911 > --- > gdb/dwarf2/cu.c | 1 + > gdb/dwarf2/cu.h | 1 + > gdb/dwarf2/read.c | 23 ++++++++++++ > gdb/producer.c | 8 ++++- > .../gdb.dwarf2/dw2-unspecified-type.c | 9 ++++- > .../gdb.dwarf2/dw2-unspecified-type.exp | 36 +++++++++++++++---- > 6 files changed, 69 insertions(+), 9 deletions(-) > > diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c > index 89de40daab0..a908ec908cd 100644 > --- a/gdb/dwarf2/cu.c > +++ b/gdb/dwarf2/cu.c > @@ -40,6 +40,7 @@ dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data *per_cu, > producer_is_icc_lt_14 (false), > producer_is_codewarrior (false), > producer_is_clang (false), > + producer_is_gas_2_39 (false), > processing_has_namespace_info (false), > load_all_dies (false) > { > diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h > index 0c15d8b02db..6c611710503 100644 > --- a/gdb/dwarf2/cu.h > +++ b/gdb/dwarf2/cu.h > @@ -265,6 +265,7 @@ struct dwarf2_cu > bool producer_is_icc_lt_14 : 1; > bool producer_is_codewarrior : 1; > bool producer_is_clang : 1; > + bool producer_is_gas_2_39 : 1; > > /* When true, the file that we're processing is known to have > debugging info for C++ namespaces. GCC 3.3.x did not produce > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c > index 5bbc8e24cf9..bd8cdad6e65 100644 > --- a/gdb/dwarf2/read.c > +++ b/gdb/dwarf2/read.c > @@ -11426,6 +11426,8 @@ check_producer (struct dwarf2_cu *cu) > cu->producer_is_codewarrior = true; > else if (producer_is_clang (cu->producer, &major, &minor)) > cu->producer_is_clang = true; > + else if (startswith (cu->producer, "GNU AS 2.39.0")) > + cu->producer_is_gas_2_39 = true; > else > { > /* For other non-GCC compilers, expect their behavior is DWARF version > @@ -11461,6 +11463,15 @@ producer_is_codewarrior (struct dwarf2_cu *cu) > return cu->producer_is_codewarrior; > } > > +static bool > +producer_is_gas_2_39 (struct dwarf2_cu *cu) > +{ > + if (!cu->checked_producer) > + check_producer (cu); > + > + return cu->producer_is_gas_2_39; > +} > + > /* Return the accessibility of DIE, as given by DW_AT_accessibility. > If that attribute is not available, return the appropriate > default. */ > @@ -14635,6 +14646,18 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) > > type = die_type (die, cu); > > + if (type->code () == TYPE_CODE_VOID > + && !type->is_stub () > + && die->child == nullptr > + && producer_is_gas_2_39 (cu)) > + { > + /* Work around PR gas/29517, pretend we have an DW_TAG_unspecified_type > + return type. */ > + type = (type_allocator (cu->per_objfile->objfile, cu->lang ()) > + .new_type (TYPE_CODE_VOID, 0, nullptr)); > + type->set_is_stub (true); > + } > + > /* The die_type call above may have already set the type for this DIE. */ > ftype = get_die_type (die, cu); > if (ftype) > diff --git a/gdb/producer.c b/gdb/producer.c > index 655eb971283..9fcf749e3d4 100644 > --- a/gdb/producer.c > +++ b/gdb/producer.c > @@ -54,13 +54,19 @@ producer_is_gcc (const char *producer, int *major, int *minor) > if (minor == NULL) > minor = &min; > > + /* Skip GNU. */ > + cs = &producer[strlen ("GNU ")]; > + > + /* Bail out for GNU AS. */ > + if (startswith (cs, "AS ")) > + return 0; > + > /* Skip any identifier after "GNU " - such as "C11" "C++" or "Java". > A full producer string might look like: > "GNU C 4.7.2" > "GNU Fortran 4.8.2 20140120 (Red Hat 4.8.2-16) -mtune=generic ..." > "GNU C++14 5.0.0 20150123 (experimental)" > */ > - cs = &producer[strlen ("GNU ")]; > while (*cs && !isspace (*cs)) > cs++; > if (*cs && isspace (*cs)) > diff --git a/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.c b/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.c > index 1df09214d4a..e07d9517ff2 100644 > --- a/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.c > +++ b/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.c > @@ -17,9 +17,16 @@ > > extern int foo (void); > > +int > +bar (void) > +{ > + asm ("bar_label: .globl bar_label"); > + return 0; > +} > + > int > main (void) > { > - int res = foo (); > + int res = foo () + bar (); > return res; > } > diff --git a/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.exp b/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.exp > index 5fa6ee544b2..a6f2a57e33e 100644 > --- a/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.exp > +++ b/gdb/testsuite/gdb.dwarf2/dw2-unspecified-type.exp > @@ -27,10 +27,18 @@ lassign $foo_res \ > foo_start foo_len > set foo_end "$foo_start + $foo_len" > > +set bar_res \ > + [function_range bar \ > + [list ${srcdir}/${subdir}/$srcfile ${srcdir}/${subdir}/$srcfile2]] > +lassign $bar_res \ > + bar_start bar_len > +set bar_end "$bar_start + $bar_len" > + > # Create the DWARF. > set asm_file [standard_output_file $srcfile3] > Dwarf::assemble $asm_file { > global foo_start foo_end > + global bar_start bar_end > declare_labels unspecified_type_label > > cu {} { > @@ -45,7 +53,19 @@ Dwarf::assemble $asm_file { > {high_pc $foo_end addr} > {type :$unspecified_type_label} > } > + } > + } > > + cu {} { > + compile_unit { > + {language @DW_LANG_Mips_Assembler} > + {producer "GNU AS 2.39.0"} > + } { > + DW_TAG_subprogram { > + {name bar} > + {low_pc $bar_start addr} > + {high_pc $bar_end addr} > + } > } > } > } > @@ -59,12 +79,14 @@ if ![runto_main] { > return -1 > } > > -# Print the function type. Return type should be stub type, which is printed > -# as void. > -gdb_test "ptype foo" "type = void \\(void\\)" > +foreach f {foo bar} { > + # Print the function type. Return type should be stub type, which is printed > + # as void. > + gdb_test "ptype $f" "type = void \\(void\\)" > > -# Call the function, casting the function to the correct function type. > -gdb_test "p ((int (*) ()) foo) ()" " = 0" > + # Call the function, casting the function to the correct function type. > + gdb_test "p ((int (*) ()) $f) ()" " = 0" > > -# Call the function, casting the function result to the correct type. > -gdb_test "p (int) foo ()" " = 0" > + # Call the function, casting the function result to the correct type. > + gdb_test "p (int) $f ()" " = 0" > +} > > base-commit: 73b22419edd563cf26bc8688c3f04fb3cf414cb0