[PATCH] introduce attribute exalias

Nathan Sidwell nathan@acm.org
Fri Aug 14 16:24:00 GMT 2020

On 8/14/20 11:39 AM, Alexandre Oliva wrote:
> Ping?
> In case there isn't immediate approval for the patch proper (I suppose
> different parts will require review by different subsystem maintainers),
> I'd appreciate at least community and language lawyers buy-in (or
> turn-down) for the new feature hereby proposed for C-family languages,
> namely, attribute exalias("symbol_name") as a means to have symbol_name
> output as a same-linkage alias for functions, variables, and for C++
> class types' RTTI symbols.

This seems a useful feature.  I don;t think it needs language lawyering 
-- it's an extension, right?  By 'same-linkage', do you mean same 
linkage as the *symbol* of the thing it is aliasing, or same linkage as
the language entity it is aliasing?  I suspect you mean the former.

I'm sure we can bikeshed the name 'exalias' doesn't seem very mnemonic 
to me.  'symbol_alias' or something?

> Thanks in advance,
> On Aug  7, 2020, Alexandre Oliva <oliva@adacore.com> wrote:
>> Since last week's patchlet, I've delayed the creation of the exalias
>> decls, improved the merging of attributes, minimizing
>> interface/visibility updates, found a better way to assign exaliases to
>> nested explicit instantiations, even after enabling aliases to
>> already-defined types, so now I'm reasonably happy with the patch.
>> This patch introduces an attribute to add extra aliases to a symbol
>> when its definition is output.  The main goal is to ease interfacing
>> C++ with Ada, as C++ mangled names have to be named, and in some cases
>> (e.g. when using stdint.h typedefs in function arguments) the symbol
>> names may vary across platforms.
>> The attribute is usable in C and C++, presumably in all C-family
>> languages.  It can be attached to global variables and functions.  In
>> C++, it can also be attached to namespace-scoped variables and
>> functions, static data members, member functions, explicit
>> instantiations and specializations of template functions, members and
>> classes.  When applied to constructors or destructor, additional
>> exaliases with _Base and _Del suffixes are defined for variants other
>> than complete-object ones.
>> Applying the attribute to class types is only valid in C++, and the
>> effect is to attach the alias to the RTTI object associated with the
>> class type.
>> While working on this, I noticed C++ didn't merge attributes of extern
>> local declarations with those of the namespace-scoped declaration.
>> I've added code to merge the attributes if there is a namespace-scoped
>> declaration, but if there isn't one, there won't be any merging, and
>> the effects are noticeable, as in the added attr-weak-1.C.  I'm also
>> slightly concerned that an earlier local decl would go out of sync if
>> a subsequent local decl, say within the same or even in another
>> function, introduces additional attributes in the global decl.
>> Regstrapped on x86_64-linux-gnu.  Ok to install?
>> (The newly-introduced attr-weak-1.c passes in C, but is marked as XFAIL
>> for C++, so it gets an XPASS in C; I could move it to some C++-only
>> subtree, or drop it altogether and file a PR instead)
>> for  gcc/ChangeLog
>> 	* attribs.c: Include cgraph.h.
>> 	(decl_attributes): Allow late introduction of exalias in
>> 	types.
>> 	(create_exalias_decl, create_exalias_decls): New.
>> 	* attribs.h: Declare them.
>> 	(FOR_EACH_EXALIAS): New macro.
>> 	* cgraph.c (cgraph_node::create): Create exalias decls.
>> 	* varpool.c (varpool_node::get_create): Create exalias decls.
>> 	* cgraph.h (symtab_node::remap_exalias_target): New.
>> 	* symtab.c (symtab_node::remap_exalias_target): Define.
>> 	* cgraphunit.c (cgraph_node::analyze): Create alias_target
>> 	node if needed.
>> 	(analyze_functions): Fixup visibility of implicit alias only
>> 	after its node is analyzed.
>> 	* doc/extend.texi (exalias): Document for variables, functions
>> 	and types.
>> for  gcc/ada/ChangeLog
>> 	* doc/gnat_rm/interfacing_to_other_languages.rst: Mention
>> 	attribute exalias to give RTTI symbols mnemonic names.
>> 	* doc/gnat_ugn/the_gnat_compilation_model.rst: Mention
>> 	attribute exalias.  Fix incorrect ref to C1 ctor variant.
>> for  gcc/c-family/ChangeLog
>> 	* c-ada-spec.c (pp_asm_name): Use first exalias if available.
>> 	* c-attribs.c (handle_exalias_attribute): New.
>> 	(c_common_attribute_table): Add exalias.
>> 	(handle_copy_attribute): Do not copy exalias.
>> 	* c-decl.c (duplicate_decls): Remap exalias target.
>> for  gcc/cp/ChangeLog
>> 	* class.c (copy_fndecl_with_name): Move/adjust exalias to
>> 	cdtor variants.
>> 	(build_cdtor_clones): Drop exalias from primary variant.
>> 	* cp-tree.h (update_exalias_interface, update_tinfo_exalias):
>> 	Declare.
>> 	* decl.c (duplicate_decls): Remap exalias target.
>> 	(grokfndecl): Tentatively create exalias decls after adding
>> 	attributes in e.g. a template member function explicit
>> 	instantiation.
>> 	* decl2.c (cplus_decl_attributes): Update tinfo exalias.
>> 	(copy_interface, update_exalias_interface): New.
>> 	(determine_visibility): Update exalias interface.
>> 	(tentative_decl_linkage, import_export_decl): Likewise.
>> 	* name-lookup.c: Include target.h and cgraph.h.
>> 	(set_local_extern_decl_linkage): Merge attributes with a
>> 	namespace-scoped decl if one is found.  Remap exalias
>> 	targets, and drop exaliases from the local decl.
>> 	* optimize.c (maybe_clone_body): Only copy attributes if they
>> 	haven't been copied yet.  Update exalias interface.
>> 	* rtti.c: Include attribs.h and cgraph.h.
>> 	(get_tinfo_decl): Copy exalias attributes from type to tinfo
>> 	decl.  Create exalias decls.
>> 	(update_tinfo_exalias): New.
>> for  gcc/testsuite/ChangeLog
>> 	* c-c++-common/attr-weak-1.c: New, xfailed.
>> 	* c-c++-common/torture/attr-exalias-1.c: New.
>> 	* c-c++-common/torture/attr-exalias-2.c: New.
>> 	* c-c++-common/torture/attr-exalias-3.c: New.
>> 	* c-c++-common/torture/attr-exalias-4.c: New.
>> 	* g++.dg/torture/attr-exalias-1.C: New.
>> 	* g++.dg/torture/attr-exalias-2.C: New.
>> 	* g++.dg/torture/attr-exalias-3.C: New.
>> 	* g++.dg/torture/attr-exalias-4.C: New.
> https://gcc.gnu.org/pipermail/gcc-patches/2020-August/551614.html

Nathan Sidwell

More information about the Gcc-patches mailing list