From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id B6B3F3858D3C for ; Fri, 19 Jan 2024 22:29:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B6B3F3858D3C 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 B6B3F3858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::52c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705703365; cv=none; b=Vjx3TyeKQ8doR/unKllBJIeG/8nx7F6Ap5wLIkcCDT67RzJkDotoBKf0XkZ8BeUDozfxrSbrtbDwbdola8jNw5G0bVvNriTy5bg15BXiqOLa0JBygd91OcaLTLSgnTcwCFuo/l0Uli9x1sOr2RswHzrlNL/1tZgD2yE+j6WcuEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705703365; c=relaxed/simple; bh=9nnaHOKPwgKlcyD7wOvNAaJP5JVIee2CeuA9NACLlLI=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=MiGyLUPhg42c6c47V7eLS5Jpuf/ibzCKNgaQH7lywhNkRsw6x5Uml0NOhlQfMoZlk6IyqWCWYW+hPFJMtbFkrpS5x2xyTXD1AaZl7cQoi1z8ovcRD8RiC1eqkNtSPVdsfFkq6PLZ2o9WbW3G0AXO1dJz/Dq0H2cPvojY5c8pXzk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5578485fc0eso1314891a12.1 for ; Fri, 19 Jan 2024 14:29:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705703362; x=1706308162; darn=sourceware.org; h=to:subject:message-id:date:from:reply-to:mime-version:from:to:cc :subject:date:message-id:reply-to; bh=QdecX7tp2idJMuRSpJL2wNFXq4Tq4YVQFZEbETVcMq0=; b=ChCakGxvCNlGCKnbZ5fLoMAJn0GVBJ6EzCsFxeFKr1cPGEqKgMSYSKe+QKRi938GSM ubEz67A5q5niyKpobQAKr6wkVqNPoekYrTUb/4YJEZOuCCF0UQe8pNkeS0TOaU7FRKXt sbp4rSieJtAIDAFj1IwF9l8wuzwN+pBJEyOX+oppAwZYvP8bSMZOmQREzx5pYgxIaRsV fBx7V2StIuXIpBRVgNQv5NIpgWeCLQ0+8rjlqVVNV6DrHwNTCFoDxfdH7bQiuhjmiOZl FF01QZyf2x8zFvXylnr2y5vRiz4DYuw032R+QAFiv2RqRahBH82GPbqrYn/Zq19sWe5S v/FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705703362; x=1706308162; h=to:subject:message-id:date:from:reply-to:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QdecX7tp2idJMuRSpJL2wNFXq4Tq4YVQFZEbETVcMq0=; b=DDy3F4tXUC1XJ9r2UNpPGu/sbFXIkri6Q4H2+2pSV+Ze/0gkeDfd3uCYeEN8qbuo9U 8+6vHpo6EBUrAt/cxQJAcE2HUwanjwz0Xro1+65vIZoXHet5DSFVHJWSkCh+ACAt+cuk aZiI8CU0yYVBYadC9bOszEBWN8l3hknIPYbS3cauyWYNa/O0ayPDrC19OfJzmbZJ12bU +YKpueaCDjFI41SYz4sNXM6I6xivBU3NhjLQ6sSFSN6Bqd2mYfqSN1TvBQan/NxEqRc4 a7AN82emBu+GNOELwz2OgVdE/Khw+srHntb592BzrpSyQdr24XfpBesVQLB+X6qZ8Nyd 0VtQ== X-Gm-Message-State: AOJu0Yz6cBaL3AoAlVGbrDBb/0oSw7OjCCpWm1jIZr4AZbBExN3ptJl8 QQCSOu4mYmYwpe3PBSg6t43PToBHS4Cj26SfZnnJ53gNIHRGH16dDY9V5PM+ktgjCvAMCXhkdIi aoGsHj3nlHlFx9X+8hwlmNRwn9gwI9chI X-Google-Smtp-Source: AGHT+IHzU1hFxi0jwqIIlYmNZuAdbnNsWl8+dUkHiEJ1vWV6T3iQ/vmsaXFg7cXImK/zxEU4oYgM9wIpl6ab5e4rlUA= X-Received: by 2002:a05:6402:348e:b0:55a:7191:b301 with SMTP id v14-20020a056402348e00b0055a7191b301mr334560edc.48.1705703362195; Fri, 19 Jan 2024 14:29:22 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a54:3345:0:b0:246:dedf:6cdc with HTTP; Fri, 19 Jan 2024 14:29:21 -0800 (PST) Reply-To: cauldwell.thomas@gmail.com From: Frederick Virchanza Gotham Date: Fri, 19 Jan 2024 22:29:21 +0000 Message-ID: Subject: Linker : Make a map of typeinfo to vtable To: binutils@sourceware.org Content-Type: multipart/alternative; boundary="000000000000fef3d8060f5402cf" X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,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: --000000000000fef3d8060f5402cf Content-Type: text/plain; charset="UTF-8" Over on the mailing list for new proposals for the C++ programming language, I am proposing that we be able to get a pointer to a class's vtable from its typeinfo. So I want to edit the source code for the GNU linker in order to add two new symbols to every binary: (1) __map_typeinfohash_vtable (2) __map_typeinfohash_vtable_size The first one is an array mapping the hashes of type_info's to vtable pointers. The second one is the number of elements in the array. The array would look something like the following in C++: pair const g_vtables[] = { { typeid(MyClass).hash_code(), &_ZTI7MyClass }, { typeid(YourClass).hash_code(), &_ZTI9YourClass }, }; Next I can write a function called 'std::get_polymorphic_facilitator' which would perform a binary search through this array, in order to convert a typeinfo to a vtable pointer. So if a massive program like Chromium has 6,000 classes, then a worst case binary search would be about 13 checks. On a desktop PC that's less than a microsecond. Afterward I would fork libstdc++ to edit the standard header file to add the following inline function: inline void const *get_polymorphic_facilitator(type_info const &ti) { extern pair const *const __map_typeinfohash_vtable; extern size_t const __map_typeinfohash_vtable_size; return lower_bound( p, p + __map_typeinfohash_vtable_size, ti.hash_code(), OnlyCompareFirst() )->second; } But first of all I need to edit the source code for 'ld' so that, after it has generated all the vtables and typeinfo's for every class, I can then create my aforementioned array which maps typeinfo's to vtables. Or, instead of waiting until after all the vtables and typeinfo's have been generated, I can populate my array as and when these things are generated (I imagine this might be easier than waiting until they're all generated, but whatever works). I've never edited a compiler or linker before, so could I please ask for a little guidance here? Could someone point me toward the right source file for 'ld' where I should start making changes to implement this? I would appreciate any tips you can give me please. --000000000000fef3d8060f5402cf--