From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id F226E3857034; Thu, 31 Mar 2022 21:18:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F226E3857034 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: initialize ctf_context::builder in create_partial_symtab X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 49a82d50c0ee41bf51db6899291a8beaea4e7e2a X-Git-Newrev: 59f837cb11e3b96c581fe23b79f6995b7c8177ee Message-Id: <20220331211831.F226E3857034@sourceware.org> Date: Thu, 31 Mar 2022 21:18:31 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Mar 2022 21:18:32 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D59f837cb11e3= b96c581fe23b79f6995b7c8177ee commit 59f837cb11e3b96c581fe23b79f6995b7c8177ee Author: Simon Marchi Date: Thu Mar 31 14:20:02 2022 -0400 gdb: initialize ctf_context::builder in create_partial_symtab =20 I built a random project with -gctf, in order to test the CTF support in GDB. With my ASan/UBSan/etc-enabled build of GDB, I get: =20 $ ./gdb --data-directory=3Ddata-directory /tmp/babeltrace-ctf/src/l= ib/.libs/libbabeltrace2.so.0.0.0 ... Reading symbols from /tmp/babeltrace-ctf/src/lib/.libs/libbabeltrac= e2.so.0.0.0... /home/simark/src/binutils-gdb/gdb/ctfread.c:1545:31: runtime error:= member call on misaligned address 0xbebebebebebebebe for type 'struct buil= dsym_compunit', which requires 8 byte alignment 0xbebebebebebebebe: note: pointer points here =20 The 0xbebebebebebebebe value is a sign that the ctf_context::builder field is uninitialized. The problem probably goes under the radar if the field happens to be zero-initialized, because ctf_start_archive contains this code: =20 if (ccx->builder =3D=3D nullptr) { ccx->builder =3D new buildsym_compunit (of, of->original_name, nullptr, language_c, 0); =20 If the field was zero-initialized (by chance), this will create a new buildsym_compunit. But if the field was purposely filled with random bytes by one of the sanitizers, we won't create a buildsym_compunit here and we'll continue with ccx->builder equal to 0xbebebebebebebebe. =20 Fix this the easy way by initializing ccx->builder where the other ctf_context fields are initialized (yeah, this code could be made nicer C++, but I am going for the obvious fix here). =20 With this patch, this passes cleanly on my system: =20 $ make check TESTS=3D"gdb.ctf/*.exp" RUNTESTFLAGS=3D"CC_FOR_TARGET=3D= /opt/gcc/git/bin/gcc" # of expected passes 40 =20 ... where /opt/gcc/git/bin/gcc is a gcc with CTF support, given my system gcc does not have it. =20 Change-Id: Idea1b0cf3e3708b72ecb16b1b60222439160f9b9 Diff: --- gdb/ctfread.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gdb/ctfread.c b/gdb/ctfread.c index 585c664cce2..8da38cc70af 100644 --- a/gdb/ctfread.c +++ b/gdb/ctfread.c @@ -1449,6 +1449,7 @@ create_partial_symtab (const char *name, pst->context.of =3D objfile; pst->context.partial_symtabs =3D partial_symtabs; pst->context.pst =3D pst; + pst->context.builder =3D nullptr; =20 return pst; }