From owner-freebsd-bugs@freebsd.org Tue May 19 16:51:27 2020 Return-Path: Delivered-To: freebsd-bugs@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 02E842DE563 for ; Tue, 19 May 2020 16:51:27 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mailman.nyi.freebsd.org (mailman.nyi.freebsd.org [IPv6:2610:1c1:1:606c::50:13]) by mx1.freebsd.org (Postfix) with ESMTP id 49RMNG6NSrz3Yhk for ; Tue, 19 May 2020 16:51:26 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: by mailman.nyi.freebsd.org (Postfix) id DB10D2DEAD3; Tue, 19 May 2020 16:51:26 +0000 (UTC) Delivered-To: bugs@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id DAD772DE562 for ; Tue, 19 May 2020 16:51:26 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49RMNG5X9dz3ZLN for ; Tue, 19 May 2020 16:51:26 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B96E7E181 for ; Tue, 19 May 2020 16:51:26 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 04JGpQaj082210 for ; Tue, 19 May 2020 16:51:26 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 04JGpQxq082209 for bugs@FreeBSD.org; Tue, 19 May 2020 16:51:26 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 246561] [PATCH] rtld-elf: dlinfo() returns wrong address in RTLD_DI_LINKMAP's l_addr (breaking Wine, gdb, etc.) Date: Tue, 19 May 2020 16:51:26 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: 12.1-STABLE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: jhb@FreeBSD.org X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 May 2020 16:51:27 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D246561 --- Comment #4 from John Baldwin --- GDB doesn't use the special field for MIPS (it ignores it). GDB also uses = the structure embedded in the rtld itself, it does not call dlinfo(). GDB does seem to expect l_addr + offset of ".dynamic" in the binary =3D=3D l_ld. I think what we have now only works because all of our shared libraries are linked at a virtual address of 0. If we did "pre-linking" to set preferred addresses for shared libraries GDB would stop working. Here's stepping through the function (gdb/solib-svr4.c:lm_addr_check()) that finds the base address of a shared library (libutil.so in this case): (top-gdb) p *li $10 =3D { =3D {}, l_addr =3D 0x0,=20 l_addr_inferior =3D 0x800250000, l_addr_p =3D false, lm_addr =3D 0x800232= 638,=20 l_ld =3D 0x800263360, l_next =3D 0x800232a38, l_prev =3D 0x800232238,=20 l_name =3D 0x800230260} (top-gdb) n 225 l_addr =3D li->l_addr_inferior; (top-gdb) n 227 if (! abfd || ! has_lm_dynamic_from_link_map ()) (top-gdb)=20 230 l_dynaddr =3D li->l_ld; (top-gdb)=20 232 dyninfo_sect =3D bfd_get_section_by_name (abfd, ".dynamic"); (top-gdb)=20 233 if (dyninfo_sect =3D=3D NULL) (top-gdb)=20 236 dynaddr =3D bfd_section_vma (abfd, dyninfo_sect); (top-gdb)=20 238 if (dynaddr + l_addr !=3D l_dynaddr) (top-gdb) p dynaddr $11 =3D 0x13360 (top-gdb) p l_addr $12 =3D 0x800250000 (top-gdb) p l_dynaddr $13 =3D 0x800263360 li->l_addr_inferior is the value of 'l_addr' from the linkmap, li->l_ld is 'l_ld'. readelf -t libutil.so: [20] .dynamic DYNAMIC 0000000000013360 0000000000013360 6 0000000000000160 0000000000000010 0 8 [0000000000000003]: WRITE, ALLOC readelf -l shows first PT_LOAD with an offset of 0: Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align PHDR 0x0000000000000040 0x0000000000000040 0x0000000000000040 0x00000000000001f8 0x00000000000001f8 R 0x8 LOAD 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x00000000000075cc 0x00000000000075cc R 0x1000 LOAD 0x0000000000008000 0x0000000000008000 0x0000000000008000 0x000000000000a5d0 0x000000000000a5d0 R E 0x1000 --=20 You are receiving this mail because: You are the assignee for the bug.=