Skip to content

Commit

Permalink
Describe abi_tag mangling.
Browse files Browse the repository at this point in the history
  • Loading branch information
jicama committed Jun 2, 2016
1 parent cddd213 commit 69cea3c
Showing 1 changed file with 64 additions and 4 deletions.
68 changes: 64 additions & 4 deletions abi.html
Original file line number Diff line number Diff line change
Expand Up @@ -4129,10 +4129,10 @@ <h5><a name="mangle.name">Names</a></h5>
::= &lt;<a href="#mangle.template-param">template-param</a>&gt; # template template parameter
::= &lt;<a href="#mangle.substitution">substitution</a>&gt;

&lt;<a name="mangle.unqualified-name">unqualified-name</a>&gt; ::= &lt;<a href="#mangle.operator-name">operator-name</a>&gt;
::= &lt;<a href="#mangle.ctor-dtor-name">ctor-dtor-name</a>&gt;
::= &lt;<a href="#mangle.source-name">source-name</a>&gt;
::= &lt;<a href="#mangle.unnamed-type-name">unnamed-type-name</a>&gt;
&lt;<a name="mangle.unqualified-name">unqualified-name</a>&gt; ::= &lt;<a href="#mangle.operator-name">operator-name</a>&gt; [&lt;<a href="#mangle.abi-tags">abi-tags</a>&gt;]
::= &lt;<a href="#mangle.ctor-dtor-name">ctor-dtor-name</a>&gt; [&lt;<a href="#mangle.abi-tags">abi-tags</a>&gt;]
::= &lt;<a href="#mangle.source-name">source-name</a>&gt; [&lt;<a href="#mangle.abi-tags">abi-tags</a>&gt;]
::= &lt;<a href="#mangle.unnamed-type-name">unnamed-type-name</a>&gt; [&lt;<a href="#mangle.abi-tags">abi-tags</a>&gt;]

&lt;<a name="mangle.source-name">source-name</a>&gt; ::= &lt;<i>positive length</i> <a href="#mangle.number">number</a>&gt; &lt;<a href="#mangle.identifier">identifier</a>&gt;
&lt;<a name="mangle.identifier">identifier</a>&gt; ::= &lt;<i>unqualified source code identifier</i>>
Expand All @@ -4147,6 +4147,64 @@ <h5><a name="mangle.name">Names</a></h5>
may be either a function or data object name when derived from &lt;<a href="#mangle.name">name</a>&gt;,
or a class or enum name when derived from &lt;<a href="#mangle.type">type</a>&gt;.

<h5>ABI tags</h5>

<p>The GNU <code>abi_tag</code> attribute can be applied to a variable,
function, inline namespace, class, or enumeration. The
&lt;<a href="#mangle.unqualified-name">unqualified-name</a>&gt; for a tagged
variable, function, or type includes a representation of the tags on that
entity, in alphabetical order:
<pre><code><font color=blue>
&lt;<a name="mangle.abi-tags">abi-tags</a>&gt; ::= &lt;<a href="#mangle.abi-tag">abi-tag</a>&gt; [&lt;<a href="#mangle.abi-tags">abi-tags</a>&gt;]
&lt;<a name="mangle.abi-tag">abi-tag</a>&gt; ::= B &lt;<a href="#mangle.source-name">source-name</a>&gt;
</font></code></pre>

For example:
<pre>
struct [[gnu::abi_tag ("foo","bar")]] A { }; // mangles as 1AB3bar3foo
</pre>

If a name that would use a built-in
&lt;<a href="#mangle.substitution">substitution</a>&gt; has ABI tags, the tags
are appended to the substitution; the result is a substitutable component.

<pre>
namespace std
{
template &lt;class T> struct char_traits { /* ... */ };
template &lt;class T> struct allocator { /* ... */ };
template &lt;class T, class R = char_traits&lt;T>, class A = allocator&lt;T>>
struct [[gnu::abi_tag ("X")]] basic_string { /* ... */ };
using string = basic_string&lt;char>;
}

void f(std::string, std::string) { } // mangles as _Z1fSsB1XS_
</pre>

If part of a declaration's type is not represented in the mangling, i.e. the
type of a variable or a return type that is not represented in the mangling of
a function, any ABI tags on that type (or components of a compound type) that
are not otherwise represented in the mangling of the declaration are applied to
the name of the declaration. Note that there is no similar tag propagation
from members or bases to a class type, as that would be impossible for
incomplete types.

<p>If no arguments are specified for the attribute on an inline namespace, the
namespace has its own name as a tag. Tags on an inline namespace are not
represented in the mangled name of the namespace, but they are subject to the
above tag propagation. For example:

<pre>
inline namespace [[gnu::abi_tag]] Foo {
struct A {};
A f() { } // mangles as _ZN3Foo1fEv
}
template &lt;class T> struct B { };
typedef void (*fp)(B&lt;A>);
fp p; // mangles as _Z1pB3Foo
A g(A) { } // mangles as _Z1gN3Foo1AE
</pre>

<h5><a name="mangle.number"> Numbers </a></h5>

<pre><code><font color=blue> &lt;<a name="mangle.number">number</a>&gt; ::= [n] &lt;<i>non-negative decimal integer</i>>
Expand Down Expand Up @@ -5756,6 +5814,8 @@ <h3><a href="#unwind"> 5.3 Unwind Table Location </a></h3>

<h2><a name="revisions">Appendix R: Revision History</a></h2>
<p> <hr>
<p class="revision"><span class="date">[160602]</span>
Describe <code>abi_tag</code> mangling.</p>

<p class="revision"><span class="date">[151021]</span>
Support transaction-safe functions.</p>
Expand Down

2 comments on commit 69cea3c

@stbergmann
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Shouldn't the example read "mangles as 1AB3barB3foo" instead (with a "B" before "3foo")?
  • How exactly is alphabetical order defined for identifiers (used as abi_tag tags)? (But I see that the Itanium C++ ABI already uses "alphabetical order" in the context of 'U' qualifiers in type encodings, without defining its meaning.)

@jicama
Copy link
Owner Author

@jicama jicama commented on 69cea3c Aug 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Yes, thanks.
  • It's based on string comparison. Do you have a suggestion for improving the wording?

Please sign in to comment.