From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1805) id BB4243858C50; Tue, 18 Oct 2022 13:24:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB4243858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666099487; bh=HmfJudp3CP7VIEAuVWJB7r9hKfnxVkb8BxA94uW3XdM=; h=From:To:Subject:Date:From; b=tTOBsL1OUJSH6rTNUjBPvjIt+oF50qrxJxaHXx2CQxJXuaQUEMkcwMj5hntIqEYXX 6BxR+JL6lbjyAmexeM5vthEfz4Vi4SwGIH+fIuz/s7BnBRzxkT1m0lm3eg2zwxcv3d ZgyxeKj1vUbmcbkrx3IN0RJgrzuZFepvXoy44nAo= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Markus Metzger To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb, solib-svr4: remove locate_base() X-Act-Checkin: binutils-gdb X-Git-Author: Markus Metzger X-Git-Refname: refs/heads/master X-Git-Oldrev: 44288716537103644dfdd0c72f03be737cafb768 X-Git-Newrev: 60d09f0a0d8000359b8f1dd14b51e7f013ea9e5c Message-Id: <20221018132447.BB4243858C50@sourceware.org> Date: Tue, 18 Oct 2022 13:24:47 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D60d09f0a0d80= 00359b8f1dd14b51e7f013ea9e5c commit 60d09f0a0d8000359b8f1dd14b51e7f013ea9e5c Author: Markus Metzger Date: Fri Mar 11 06:46:15 2022 +0100 gdb, solib-svr4: remove locate_base() =20 Whenever we call locate_base(), we clear info->debug_base directly befo= re the call. Thus, we never cache the base location as locate_base() had intended. =20 Move the svr4_have_link_map_offsets() check into elf_locate_base(), inl= ine locate_base() at all call sites, and remove it. Diff: --- 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 7e83819a03d..222b9df3c47 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -661,6 +661,9 @@ elf_locate_base (void) struct bound_minimal_symbol msymbol; CORE_ADDR dyn_ptr, dyn_ptr_addr; =20 + 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. */ @@ -718,45 +721,6 @@ elf_locate_base (void) return 0; } =20 -/* 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 =3D=3D 0 && svr4_have_link_map_offsets ()) - info->debug_base =3D 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. @@ -844,9 +808,8 @@ svr4_keep_data_in_core (CORE_ADDR vaddr, unsigned long = size) =20 info =3D get_svr4_info (current_program_space); =20 - info->debug_base =3D 0; - locate_base (info); - if (!info->debug_base) + info->debug_base =3D elf_locate_base (); + if (info->debug_base =3D=3D 0) return 0; =20 ldsomap =3D solib_svr4_r_ldsomap (info); @@ -880,8 +843,8 @@ open_symbol_file_object (int from_tty) return 0; =20 /* Always locate the debug struct, in case it has moved. */ - info->debug_base =3D 0; - if (locate_base (info) =3D=3D 0) + info->debug_base =3D elf_locate_base (); + if (info->debug_base =3D=3D 0) return 0; /* failed somehow... */ =20 /* First link map member should be the executable. */ @@ -1297,13 +1260,10 @@ svr4_current_sos_direct (struct svr4_info *info) return library_list.head ? library_list.head : svr4_default_sos (inf= o); } =20 - /* Always locate the debug struct, in case it has moved. */ - info->debug_base =3D 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 =3D elf_locate_base (); + if (info->debug_base =3D=3D 0) return svr4_default_sos (info); =20 /* Assume that everything is a library if the dynamic loader was loaded @@ -1839,8 +1799,8 @@ svr4_handle_solib_event (void) return; =20 /* Always locate the debug struct, in case it moved. */ - info->debug_base =3D 0; - if (locate_base (info) =3D=3D 0) + info->debug_base =3D elf_locate_base (); + if (info->debug_base =3D=3D 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