public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-6154] libiberty: support digits in cpp mangled clone names
@ 2021-12-30 16:37 Jeff Law
  0 siblings, 0 replies; only message in thread
From: Jeff Law @ 2021-12-30 16:37 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:be674bdd11d5fa6b20d469e6d6f43c26da9e744f

commit r12-6154-gbe674bdd11d5fa6b20d469e6d6f43c26da9e744f
Author: Lancelot SIX <lsix@lancelotsix.com>
Date:   Thu Dec 30 11:36:52 2021 -0500

    libiberty: support digits in cpp mangled clone names
    
    Currently libiberty fails to demangle the name of cloned functions if
    the clone-type-identifier contains numbers.
    
    This can be observed with the following example:
    
        $ cat > ex.cc <<EOT
        void foo (float *, float *)
          __attribute__((target_clones("avx2,avx,sse4.1,default")));
    
        void foo (float *, float *) {}
        EOT
        $ gcc -c ex.cc
        $ nm -C ex.o | grep foo
        0000000000000000 i foo(float*, float*)
        0000000000000026 t foo(float*, float*) [clone .avx.1]
        0000000000000013 t _Z3fooPfS_.avx2.0
        0000000000000000 t foo(float*, float*) [clone .default.3]
        0000000000000000 W foo(float*, float*) [clone .resolver]
        0000000000000039 t _Z3fooPfS_.sse4_1.2
    
    In this example, gcc creates clones for the FOO function, each matching
    one of the specified targets.  When inspecting the binary, nm (and other
    libiberty-based tools, including gdb) fails to demangle the symbol names
    if the clone identifier contains numbers.
    
    Form my understanding of the mangling convention[1], clone names are
    part of vendor-specific suffixes and do not have rule preventing them
    from containing digits.
    
    This commit proposes to fix the demangling.  With this commit (ported to
    binutils), nm gives the following output:
    
        $ nm-new -C ex.o | grep foo
        0000000000000000 i foo(float*, float*)
        0000000000000026 t foo(float*, float*) [clone .avx.1]
        0000000000000013 t foo(float*, float*) [clone .avx2.0]
        0000000000000000 t foo(float*, float*) [clone .default.3]
        0000000000000000 W foo(float*, float*) [clone .resolver]
        0000000000000039 t foo(float*, float*) [clone .sse4_1.2]
    
    Tested on x86_86-linux with 'make check-libiberty'.
    
    [1] https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling
    
    libiberty/ChangeLog:
    
            * cp-demangle.c (d_clone_suffix): Support digits in clone tag
            names.
            * testsuite/demangle-expected: Check demangling of clone symbols
            with digits in name.

Diff:
---
 libiberty/cp-demangle.c               | 5 +++--
 libiberty/testsuite/demangle-expected | 5 +++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 33490f60285..fb576cb4c97 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -3884,10 +3884,11 @@ d_clone_suffix (struct d_info *di, struct demangle_component *encoding)
   const char *pend = suffix;
   struct demangle_component *n;
 
-  if (*pend == '.' && (IS_LOWER (pend[1]) || pend[1] == '_'))
+  if (*pend == '.' && (IS_LOWER (pend[1]) || IS_DIGIT (pend[1])
+		       || pend[1] == '_'))
     {
       pend += 2;
-      while (IS_LOWER (*pend) || *pend == '_')
+      while (IS_LOWER (*pend) || IS_DIGIT (*pend) || *pend == '_')
 	++pend;
     }
   while (*pend == '.' && IS_DIGIT (pend[1]))
diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected
index 19a0d621bc0..de54ad73cc8 100644
--- a/libiberty/testsuite/demangle-expected
+++ b/libiberty/testsuite/demangle-expected
@@ -1164,6 +1164,11 @@ foo(int) [clone ._omp_cpyfn.6]
 foo
 #
 --format=gnu-v3 --no-params
+_Z3fooPfS_S_j.sse4_1.2
+foo(float*, float*, float*, unsigned int) [clone .sse4_1.2]
+foo
+#
+--format=gnu-v3 --no-params
 _Z1fIKFvvES0_Evv
 void f<void () const, void () const>()
 f<void () const, void () const>


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-30 16:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-30 16:37 [gcc r12-6154] libiberty: support digits in cpp mangled clone names Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).