From patchwork Tue Dec 8 14:11:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1412709 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=jt8uWFJP; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cr2D84fpQz9sWK for ; Wed, 9 Dec 2020 01:11:35 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 97178396EC4C; Tue, 8 Dec 2020 14:11:33 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by sourceware.org (Postfix) with ESMTPS id 4D1A0396EC49 for ; Tue, 8 Dec 2020 14:11:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4D1A0396EC49 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qt1-x832.google.com with SMTP id l7so11949960qtp.8 for ; Tue, 08 Dec 2020 06:11:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=gRIb1iGjtDQNbNBaRn+gMmOu4RRAysxYnfrOqOxmKGo=; b=jt8uWFJP+EcZdf4rI7qVPqMusDKmkiZameC7qhSk/4+Tg1KfesF0Sytpwm02/YBQky Ls32vo1eUPZLvmCpR1SQ3Fubo3immmmrN8IktxswsuDriPwNxAojsjY5PIctPsjhGkmv mcuV18jujzRF/9k8BxFhjg+cj9VThMd/Ps0tAZYim2AxA6jWcPlB+J83+Es3vEtewwlQ HCfSF0uhtNx5Iv80TyUorP+RGbGuJ5RsI4xrEQuBgJXAuxz/NrosDJhU1oYD6T9RuyTF HLwPN0SsewWzla8KEPyFQsDdENfDVj6USG4Z6ctXy0z/exPonEym0rlFBkI8zWMjsr1t IIbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=gRIb1iGjtDQNbNBaRn+gMmOu4RRAysxYnfrOqOxmKGo=; b=UZIc9zxLq8CrR+ezYNj7xBiM1yhX3/V6OJUwQhxJb+ZO7pB6jDBVa1cUzuByE7gPSZ +K+VoTHHtQwQMY1cIoDJv2El/Kvv/m72hmvp0A4oWNP25ntIMdJReOZnEHTPXgMVupA3 mJXiXZYwnWrzBOvFrh2u5VmYYWLV5vYpqFTqZuIEdL8gCMMSlka4CKEW3PKYyGqydc/w htlt6ydFF1sp/EBpUknkfE01wY5eIMY64XHw8l2mH/hxcUbqH8NeHAbyPuM0MnXDr8w/ lIHcrTxYwZxdjoAClsbEa6pft0R7z59c4EInA7nzqAHGyZYZH9VFoyl6zu48GyxQ7m1M KNzg== X-Gm-Message-State: AOAM532zX6IWGtRPcQoL+dkVoJiVeFi+P5+cHen2kgYKsRlnt/opXcGH iKf3g/audW/8xtvrrwog6zI= X-Google-Smtp-Source: ABdhPJxu+uwqx1EBfB0n6p3EaGqVyPkedb8cSFMYwIm90iTzcWMqX9VtpaPlDyAqV45WAXu42vBGGw== X-Received: by 2002:ac8:4cc1:: with SMTP id l1mr29512456qtv.128.1607436681601; Tue, 08 Dec 2020 06:11:21 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:9e5:be57:d7de:21c6? ([2620:10d:c091:480::1:a476]) by smtp.googlemail.com with ESMTPSA id 189sm14501477qkn.125.2020.12.08.06.11.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Dec 2020 06:11:20 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: c++: Mangling for modules Message-ID: Date: Tue, 8 Dec 2020 09:11:17 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This is the mangling changes for modules. These were developed in collaboration with clang, which also implemements the same ABI (or plans to, I do not think the global init is in clang). The global init mangling is captured in https://github.com/itanium-cxx-abi/cxx-abi/issues/99 gcc/cp/ * cp-tree.h (mangle_module_substitution, mangle_identifier) (mangle_module_global_init): Declare. * mangle.c (struct globals): Add mod field. (mangle_module_substitution, mangle_identifier) (mangle_module_global_init): Define. (write_module, maybe_write_module): New. (write_name): Call it. (start_mangling): Clear mod field. (finish_mangling_internal): Adjust. * module.cc (mangle_module, mangle_module_fini) (get_originating_module): Stubs. pushing to trunk diff --git i/gcc/cp/cp-tree.h w/gcc/cp/cp-tree.h index aa2b0f782fa..f11cf87f190 100644 --- i/gcc/cp/cp-tree.h +++ w/gcc/cp/cp-tree.h @@ -7916,6 +7916,9 @@ extern tree mangle_template_parm_object (tree); extern char *get_mangled_vtable_map_var_name (tree); extern bool mangle_return_type_p (tree); extern tree mangle_decomp (tree, vec &); +extern void mangle_module_substitution (int); +extern void mangle_identifier (char, tree); +extern tree mangle_module_global_init (int); /* in dump.c */ extern bool cp_dump_tree (void *, tree); diff --git i/gcc/cp/mangle.c w/gcc/cp/mangle.c index 5548e51d39d..c1d9c737a16 100644 --- i/gcc/cp/mangle.c +++ w/gcc/cp/mangle.c @@ -117,6 +117,9 @@ struct GTY(()) globals { /* True if the mangling will be different in C++17 mode. */ bool need_cxx17_warning; + + /* True if we mangled a module name. */ + bool mod; }; static GTY (()) globals G; @@ -832,6 +835,62 @@ write_encoding (const tree decl) } } +/* Interface to substitution and identifer mangling, used by the + module name mangler. */ + +void +mangle_module_substitution (int v) +{ + if (v < 10) + { + write_char ('_'); + write_char ('0' + v); + } + else + { + write_char ('W'); + write_unsigned_number (v - 10); + write_char ('_'); + } +} + +void +mangle_identifier (char c, tree id) +{ + if (c) + write_char (c); + write_source_name (id); +} + +/* If the outermost non-namespace context (including DECL itself) is + a module-linkage decl, mangle the module information. For module + global initializers we need to include the partition part. + + ::= W + E + :: + || _ ;; short backref + || W _ ;; long backref + || P ;; partition introducer +*/ + +static void +write_module (int m, bool include_partition) +{ + G.mod = true; + + write_char ('W'); + mangle_module (m, include_partition); + write_char ('E'); +} + +static void +maybe_write_module (tree decl) +{ + int m = get_originating_module (decl, true); + if (m >= 0) + write_module (m, false); +} + /* Lambdas can have a bit more context for mangling, specifically VAR_DECL or PARM_DECL context, which doesn't belong in DECL_CONTEXT. */ @@ -894,6 +953,9 @@ write_name (tree decl, const int ignore_local_scope) decl = TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (decl))); } + if (modules_p ()) + maybe_write_module (decl); + context = decl_mangling_context (decl); gcc_assert (context != NULL_TREE); @@ -3825,14 +3887,13 @@ start_mangling (const tree entity) G.entity = entity; G.need_abi_warning = false; G.need_cxx17_warning = false; + G.mod = false; obstack_free (&name_obstack, name_base); mangle_obstack = &name_obstack; name_base = obstack_alloc (&name_obstack, 0); } -/* Done with mangling. If WARN is true, and the name of G.entity will - be mangled differently in a future version of the ABI, issue a - warning. */ +/* Done with mangling. Release the data. */ static void finish_mangling_internal (void) @@ -3840,6 +3901,9 @@ finish_mangling_internal (void) /* Clear all the substitutions. */ vec_safe_truncate (G.substitutions, 0); + if (G.mod) + mangle_module_fini (); + /* Null-terminate the string. */ write_char ('\0'); } @@ -3884,6 +3948,20 @@ init_mangle (void) subst_identifiers[SUBID_BASIC_IOSTREAM] = get_identifier ("basic_iostream"); } +/* Generate a mangling for MODULE's global initializer fn. */ + +tree +mangle_module_global_init (int module) +{ + start_mangling (NULL_TREE); + + write_string ("_ZGI"); + write_module (module, true); + write_char ('v'); + + return finish_mangling_get_identifier (); +} + /* Generate the mangled name of DECL. */ static tree diff --git i/gcc/cp/module.cc w/gcc/cp/module.cc index 91a16815811..24580c70907 100644 --- i/gcc/cp/module.cc +++ w/gcc/cp/module.cc @@ -70,6 +70,23 @@ get_module (tree, module_state *, bool) return nullptr; } + +void +mangle_module (int, bool) +{ +} + +void +mangle_module_fini () +{ +} + +int +get_originating_module (tree, bool) +{ + return 0; +} + module_state * preprocess_module (module_state *, unsigned, bool, bool, bool, cpp_reader *) {