From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by sourceware.org (Postfix) with ESMTPS id 9409C396E02D for ; Thu, 2 Jun 2022 14:28:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9409C396E02D X-IronPort-AV: E=McAfee;i="6400,9594,10365"; a="255830515" X-IronPort-AV: E=Sophos;i="5.91,271,1647327600"; d="scan'208";a="255830515" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2022 07:28:50 -0700 X-IronPort-AV: E=Sophos;i="5.91,271,1647327600"; d="scan'208";a="757009810" Received: from labpc2407.iul.intel.com (HELO localhost) ([172.28.50.61]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2022 07:28:49 -0700 From: Markus Metzger To: gdb-patches@sourceware.org Subject: [PATCH v5 02/15] gdb, solib-svr4: remove locate_base() Date: Thu, 2 Jun 2022 15:25:01 +0200 Message-Id: <20220602132514.957983-3-markus.t.metzger@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220602132514.957983-1-markus.t.metzger@intel.com> References: <20220602132514.957983-1-markus.t.metzger@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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-List-Received-Date: Thu, 02 Jun 2022 14:28:53 -0000 Whenever we call locate_base(), we clear info->debug_base directly before the call. Thus, we never cache the base location as locate_base() had intended. Move the svr4_have_link_map_offsets() check into elf_locate_base(), inline locate_base() at all call sites, and remove it. --- gdb/solib-svr4.c | 62 +++++++++--------------------------------------- 1 file changed, 11 insertions(+), 51 deletions(-) diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 5c046d3fab5..6222f79a7a0 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -662,6 +662,9 @@ elf_locate_base (void) struct bound_minimal_symbol msymbol; CORE_ADDR dyn_ptr, dyn_ptr_addr; + if (!svr4_have_link_map_offsets ()) + return 0; + /* Look for DT_MIPS_RLD_MAP first. MIPS executables use this instead of DT_DEBUG, although they sometimes contain an unused DT_DEBUG. */ @@ -719,45 +722,6 @@ elf_locate_base (void) return 0; } -/* Locate the base address of dynamic linker structs. - - For both the SunOS and SVR4 shared library implementations, if the - inferior executable has been linked dynamically, there is a single - address somewhere in the inferior's data space which is the key to - locating all of the dynamic linker's runtime structures. This - address is the value of the debug base symbol. The job of this - function is to find and return that address, or to return 0 if there - is no such address (the executable is statically linked for example). - - For SunOS, the job is almost trivial, since the dynamic linker and - all of it's structures are statically linked to the executable at - link time. Thus the symbol for the address we are looking for has - already been added to the minimal symbol table for the executable's - objfile at the time the symbol file's symbols were read, and all we - have to do is look it up there. Note that we explicitly do NOT want - to find the copies in the shared library. - - The SVR4 version is a bit more complicated because the address - is contained somewhere in the dynamic info section. We have to go - to a lot more work to discover the address of the debug base symbol. - Because of this complexity, we cache the value we find and return that - value on subsequent invocations. Note there is no copy in the - executable symbol tables. */ - -static CORE_ADDR -locate_base (struct svr4_info *info) -{ - /* Check to see if we have a currently valid address, and if so, avoid - doing all this work again and just return the cached address. If - we have no cached address, try to locate it in the dynamic info - section for ELF executables. There's no point in doing any of this - though if we don't have some link map offsets to work with. */ - - if (info->debug_base == 0 && svr4_have_link_map_offsets ()) - info->debug_base = elf_locate_base (); - return info->debug_base; -} - /* Find the first element in the inferior's dynamic link map, and return its address in the inferior. Return zero if the address could not be determined. @@ -845,9 +809,8 @@ svr4_keep_data_in_core (CORE_ADDR vaddr, unsigned long size) info = get_svr4_info (current_program_space); - info->debug_base = 0; - locate_base (info); - if (!info->debug_base) + info->debug_base = elf_locate_base (); + if (info->debug_base == 0) return 0; ldsomap = solib_svr4_r_ldsomap (info); @@ -881,8 +844,8 @@ open_symbol_file_object (int from_tty) return 0; /* Always locate the debug struct, in case it has moved. */ - info->debug_base = 0; - if (locate_base (info) == 0) + info->debug_base = elf_locate_base (); + if (info->debug_base == 0) return 0; /* failed somehow... */ /* First link map member should be the executable. */ @@ -1298,13 +1261,10 @@ svr4_current_sos_direct (struct svr4_info *info) return library_list.head ? library_list.head : svr4_default_sos (info); } - /* Always locate the debug struct, in case it has moved. */ - info->debug_base = 0; - locate_base (info); - /* If we can't find the dynamic linker's base structure, this must not be a dynamically linked executable. Hmm. */ - if (! info->debug_base) + info->debug_base = elf_locate_base (); + if (info->debug_base == 0) return svr4_default_sos (info); /* Assume that everything is a library if the dynamic loader was loaded @@ -1840,8 +1800,8 @@ svr4_handle_solib_event (void) return; /* Always locate the debug struct, in case it moved. */ - info->debug_base = 0; - if (locate_base (info) == 0) + info->debug_base = elf_locate_base (); + if (info->debug_base == 0) { /* It's possible for the reloc_complete probe to be triggered before the linker has set the DT_DEBUG pointer (for example, when the -- 2.35.3 Intel Deutschland GmbH Registered Address: Am Campeon 10, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928