From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by sourceware.org (Postfix) with ESMTPS id 7D2293858401 for ; Thu, 25 Jan 2024 10:17:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7D2293858401 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7D2293858401 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::531 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706177883; cv=none; b=kBovznGoBPAFPN0zSi43AWBEQGlZHFvmPHXvwdUJ9E3cRNoZehv4zficLFJIIkNNRR2gOm7zcwE3DcHByaLcL64TtRdArR9ylSVw/SDKgrDH0gItb6W2wyabYhNQASCeeZjBxcZfxQKIslYNY0XOEo/8H1045r0/H5XzeA70eBs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706177883; c=relaxed/simple; bh=k+7vBfP6GnuFRxsohM7ZUD+0diLN7W9arsjLRSBPaK0=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=RVFcZzCaU7yPJG/ryI1SYtQi63dsXdBrdV0uKKgKwI8Do88Pt4p/GkH6VMLsCL+dW4DOI+TD6sRwFUUz+nj9pIlBulaBZ9+n3d22WN55+GFjwZQ/KzWn9hqHWvqrCpH2kkDcHehwP/tG6Fvvz7+5b1cSL8IPkRGXkTtTJn7iGVc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-55817a12ad8so7389297a12.2 for ; Thu, 25 Jan 2024 02:17:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706177878; x=1706782678; darn=sourceware.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=dialeWkSNg1L/YwtiCtuqoyFQ169jif+RS4m73oMLaM=; b=L8lLTpVo56Tig7QWtzi2bGthphRJudqEw5wnnJCttbxAY/c9l+AF3OBXBHwOFV/xwO 2+9evrut9s1hws7oJFCJwVjTzsws/JihZUEES4hzNFA2hL6xMB3SNol2E9DvFd77K8Vv zwSTIY9L2QU9d8kU6fcCDBDhpHF7MuVAxaU0B2w4sX51BdMH7nE9cj2zB5h9EALBfX7Y wrHnGl+0BMHF4Xt+oQElTkID8kC3GG2Qn3nQwsLWm6BC4SIVUnXHYs8c53g3n8l1P6Ns xgMi8QVG0l0K8qegWoi4uVGRKlTEv2/xgfiqOG/zJ5qs+byVunTVnPt17I6WSz184zsK B1tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706177878; x=1706782678; h=content-transfer-encoding:cc:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=dialeWkSNg1L/YwtiCtuqoyFQ169jif+RS4m73oMLaM=; b=kCO/4hLQCezMBHeosfuqWkPVBkyN10SzlmF4f5UEMOdtNszb2jAsRBRCqE91hk28CV YFhPZlUl9GoyfatIuFJ4bwGudestiV3HBsbzFg3vt2Hu5uJeSvNVSGLnh695CHX8oBKX Pn3gLVT1n5c7kRmyDKeECPStOGWPrA0cZo09CckWxSUmjQzWyFaH/3Ks32LqjGqwgkvT VhWDevjp7NIpP7hbf+oF88iNw6/n5lnuWMCpFISu5Dc5I2HvcAffS8fwBhi4D/NaNmYR ysjhP3WeM3Gk66ITrFs7gR1NHLkYbLNogWFwmPiGHTs4SHrNOxUQCi87DIgidw9SUDtf MvcA== X-Gm-Message-State: AOJu0YzyR3Xw1bAvEZ/IWpi7QcQnFDG2v3jqQ/ZYbnNB6MB/WHiTddqb /IFuzGwLFw+8QWrnBjYO0HUf/HBaQr84k0pmxshnJyNB+JMy0AxIS5RL93R1T37mUgij6L9ordn uSnaUoyGj15N5fG1NgbAA26HGvsfUeZaUyFE= X-Google-Smtp-Source: AGHT+IErVCf8cYrz1o9He2EOyEhdvF7gtGydJOWlariIbJ7aQ5a/yRv0ArZFjaEjvcMYPyxd711kdin0qbvptXHJKNM= X-Received: by 2002:a05:6402:3095:b0:55a:e43d:7687 with SMTP id de21-20020a056402309500b0055ae43d7687mr412576edb.62.1706177877936; Thu, 25 Jan 2024 02:17:57 -0800 (PST) MIME-Version: 1.0 References: <51e942dd-dbe0-f644-e9bb-0e12fc69f076@suse.de> In-Reply-To: <51e942dd-dbe0-f644-e9bb-0e12fc69f076@suse.de> Reply-To: cauldwell.thomas@gmail.com From: Frederick Virchanza Gotham Date: Thu, 25 Jan 2024 10:17:46 +0000 Message-ID: Subject: Re: Linker : Make a map of typeinfo to vtable To: binutils@sourceware.org Cc: Michael Matz Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 List-Id: On Mon, Jan 22, 2024 at 4:50=E2=80=AFPM Michael Matz wrote: > > When you want to get from typeinfo to vtable pointer, why not just add > that pointer directly into the typeinfo? A hashtable is quite a > roundabout way to implement 'typeid(Type).vtable()' . That would be one option, yes it would be possible to edit the source code for the GNU g++ compiler so that the type '__vmi_class_type_info' has the vtable pointer appended onto the end of it, and then the '__vmi_class_type_info::flags' member could have a bit set in it to indicate the presence of the vtable pointer. There are two drawbacks to this option though: (1) It involves editing the GNU g++ compiler, and I'd rather edit the linker because then it can be extended easily to other languages (such as D) (2) If we have multiple object files with a weak vtable symbol, and if some of the weak symbols don't have the vtable pointer appended, then a symbol missing the vtable pointer might become 'strong' (2) It will be necessary to recompile entire programs, whereas if I edit just the linker, only the final linking step will need to be redone (which is a big deal if you have been given proprietary object files and static archives) So for the time being I'm ploughing on ahead with editing the linker. Please help me to get this working, here's what I've got so far: https://github.com/bminor/binutils-gdb/compare/f11786a1951932217d348f37= 39e8deb31975a355...healytpk:linker-vtable:master Inside the file, "ld/ldmain.c", the function 'main' calls 'ldwrite' which calls 'bfd_final_link'. After 'ldwrite' is called, I am able to use the pointer "link_info.output_bfd" in order to get a list of all symbols along with their offsets inside their sections. From this data I'm able to produce my array which maps typeinfo's to vtables. But there's one problem -- 'ldwrite' has already been called by the time I produce my array. So, somehow, I need to call 'bfd_final_link' in order get the offsets for the vtables inside their section, but then I need to append my own array onto the end of the section, and then perform the final link. Can anybody please point me in the right direction for how to do this? Can I possibly make a duplicate of the "bfd_link_info" struct and pass it to "bfd_final_link" so that I can determine the vtable offsets, then append my array onto the end of the section, and then call 'bfd_final_link' a second time giving it the original "bfd_link_info" struct? Would something like that work?