From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id v7/XCOuJVWFjTwAAWB0awg (envelope-from ) for ; Thu, 30 Sep 2021 05:56:59 -0400 Received: by simark.ca (Postfix, from userid 112) id 0931D1EE27; Thu, 30 Sep 2021 05:56:59 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 978661EDF7 for ; Thu, 30 Sep 2021 05:56:57 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3CE5A3858001 for ; Thu, 30 Sep 2021 09:56:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3CE5A3858001 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1632995816; bh=qsMm5eafJnjz67lIkHQq1m2yINaYKGKMPPDZiKDCZMc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=S93ICgJTzIPYR+p4GPRQ55SV8omt+TDTFKNBwHjL6RihcPlgggGJo/mEENHmdY9zt DduDaw9sU0pRwOTKF4fkAEJFCqKXDHhO9HQDY7BbBQiAHxEIGcFvH6ujWF3sqFG/QT pfnV0CziTv4TW9ugXUM3/wIUqPvbPfiEmVDPMpXk= Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 32F603857C52 for ; Thu, 30 Sep 2021 09:56:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 32F603857C52 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 38990224F8; Thu, 30 Sep 2021 09:56:12 +0000 (UTC) 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 1DB4D140D0; Thu, 30 Sep 2021 09:56:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GqlTBryJVWECYwAAMHmgww (envelope-from ); Thu, 30 Sep 2021 09:56:12 +0000 Date: Thu, 30 Sep 2021 11:56:10 +0200 To: gdb-patches@sourceware.org Subject: [PATCH][gdb/symtab] Relocate call_site_htab Message-ID: <20210930095608.GA11467@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) 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: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Cc: Tom Tromey Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" [ CC-ing maintainers that reviewed previous submission. ] Hi, When running test-case gdb.arch/amd64-entry-value-inline.exp with target board unix/-no-pie/-fno-PIE we have: ... (gdb) continue^M Continuing.^M ^M Breakpoint 2, fn2 (y=y@entry=25, x=x@entry=6) at \ gdb.arch/amd64-entry-value-inline.c:32^M 32 y = -2 + x; /* break-here */^M (gdb) PASS: gdb.arch/amd64-entry-value-inline.exp: \ continue to breakpoint: break-here p y^M $1 = 25^M (gdb) PASS: gdb.arch/amd64-entry-value-inline.exp: p y ... But with target board unix/-pie/-fPIE we have instead: ... p y^M $1 = ^M (gdb) FAIL: gdb.arch/amd64-entry-value-inline.exp: p y ... The test-case uses a .S file, which was generated using gcc 4.8.0, but I can reproduce the same problem using the original C file and gcc 4.8.5. The problem is that in order to access the value, call_site information is accessed, which is both: - unrelocated, and - accessed as if it were relocated. I've submitted an attempt at fixing this before, trying to handle this at all points where the information is used ( https://sourceware.org/pipermail/gdb-patches/2019-August/159631.html ). Instead, fix this more reliably by relocating the call_site information. This fixes for me all remaining regressions for unix/-pie/-fPIE vs unix/-no-pie/-fno-PIE (not counting ada compilation FAILs). Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24892 Any comments? Thanks, - Tom [gdb/symtab] Relocate call_site_htab --- gdb/objfiles.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/gdb/objfiles.c b/gdb/objfiles.c index b65fa8820ca..ceff0fcfba4 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -626,6 +626,60 @@ relocate_one_symbol (struct symbol *sym, struct objfile *objfile, } } +/* Relocate call_site S using offset DELTA. */ + +static void +call_site_relocate (struct call_site *s, CORE_ADDR delta) +{ + s->pc += delta; + if (FIELD_LOC_KIND (s->target) == FIELD_LOC_KIND_PHYSADDR) + FIELD_STATIC_PHYSADDR (s->target) += delta; +} + +/* Relocate HTAB, which is a COMPUNIT_CALL_SITE_HTAB using offset DELTA. */ + +static void +compunit_call_site_htab_relocate (htab_t htab, CORE_ADDR delta) +{ + /* Changing the pc field changes the hashcode, so we can't just update the + elements. Instead, we move them to this var, and then reinsert them. */ + std::vector tmp; + + /* Copy elements to tmp. */ + auto visitor_func + = [] (void **slot, void *info) -> int + { + /* Copy element to tmp. */ + struct call_site *s = (struct call_site *) *slot; + std::vector *tmp_ptr + = (std::vector *)info; + tmp_ptr->push_back (s); + + /* Keep going. */ + return 1; + }; + htab_traverse (htab, visitor_func, &tmp); + + /* Make hashtable empty. This does not destroy the elements because the + hashtable is created with del_f == nullptr. */ + htab_empty (htab); + + /* Relocate and reinsert elements. */ + for (struct call_site *s : tmp) { + /* Relocate element. */ + call_site_relocate (s, delta); + + /* Reinsert element. */ + struct call_site call_site_local; + call_site_local.pc = s->pc; + void **slot + = htab_find_slot (htab, &call_site_local, INSERT); + gdb_assert (slot != NULL); + gdb_assert (*slot == NULL); + *slot = s; + } +} + /* Relocate OBJFILE to NEW_OFFSETS. There should be OBJFILE->NUM_SECTIONS entries in new_offsets. SEPARATE_DEBUG_OBJFILE is not touched here. Return non-zero iff any change happened. */ @@ -697,6 +751,10 @@ objfile_relocate1 (struct objfile *objfile, relocate_one_symbol (sym, objfile, delta); } } + + if (COMPUNIT_CALL_SITE_HTAB (cust) != nullptr) + compunit_call_site_htab_relocate (COMPUNIT_CALL_SITE_HTAB (cust), + delta[block_line_section]); } }