From f7741f514ce6c2e50a1b9dd8445a3274b92e1ec7 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Mon, 3 May 2004 11:12:37 +0000 Subject: [PATCH] Continue the implementation of the C++ name mangling routines. --- ChangeLog | 5 + doc/Makefile.am | 4 + doc/libjit.texi | 1 + doc/mangling_rules.txt | 328 +++++++++++++++++++++++++ include/jit/jit-type.h | 42 ++-- include/jit/jit-util.h | 19 ++ jit/jit-mangle.c | 541 +++++++++++++++++++++++++++++++++++++++-- jit/jit-type.c | 10 +- 8 files changed, 903 insertions(+), 47 deletions(-) create mode 100644 doc/mangling_rules.txt diff --git a/ChangeLog b/ChangeLog index 05a2a0d..4d1035f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,11 @@ name mangler, to help with extracting C++ symbols from dynamic shared libraries. + * doc/Makefile.am, doc/libjit.texi, doc/mangling_rules.txt, + include/jit/jit-type.h, include/jit/jit-util.h, jit/jit-mangle.c, + jit/jit-type.c: continue the implementation of the C++ name + mangling routines. + 2004-05-01 Rhys Weatherley * jit/jit-apply-x86.c, jit/jit-rules-x86.c, tools/gen-apply.c: diff --git a/doc/Makefile.am b/doc/Makefile.am index d24d152..f536ef6 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -15,6 +15,7 @@ libjit_TEXINFOS = \ $(srcdir)/libjitext-init.texi \ $(srcdir)/libjitext-insn.texi \ $(srcdir)/libjitext-intrinsic.texi \ + $(srcdir)/libjitext-mangle.texi \ $(srcdir)/libjitext-memory.texi \ $(srcdir)/libjitext-meta.texi \ $(srcdir)/libjitext-reg-alloc.texi \ @@ -60,6 +61,9 @@ $(srcdir)/libjitext-insn.texi: $(top_srcdir)/jit/jit-insn.c $(srcdir)/libjitext-intrinsic.texi: $(top_srcdir)/jit/jit-intrinsic.c $(SHELL) $(srcdir)/extract-docs.sh $< >$@ +$(srcdir)/libjitext-mangle.texi: $(top_srcdir)/jit/jit-mangle.c + $(SHELL) $(srcdir)/extract-docs.sh $< >$@ + $(srcdir)/libjitext-memory.texi: $(top_srcdir)/jit/jit-memory.c $(SHELL) $(srcdir)/extract-docs.sh $< >$@ diff --git a/doc/libjit.texi b/doc/libjit.texi index 8fd4c35..47d7db5 100644 --- a/doc/libjit.texi +++ b/doc/libjit.texi @@ -1003,6 +1003,7 @@ that it itself uses internally, but which may also be useful to front ends. @include libjitext-apply.texi @include libjitext-walk.texi @include libjitext-dynlib.texi +@include libjitext-mangle.texi @c ----------------------------------------------------------------------- diff --git a/doc/mangling_rules.txt b/doc/mangling_rules.txt new file mode 100644 index 0000000..b90bd62 --- /dev/null +++ b/doc/mangling_rules.txt @@ -0,0 +1,328 @@ + +GCC 2.95.3 name mangling grammar (intuited from gcc sources): +------------------------------------------------------------ + + ::= '__F' + + ::= '__' + + ::= '__' + + ::= '_' '_' + + ::= '.' | '$' # system-dependent joiner + + ::= + + ::= + ::= 'Q' + + ::= 'Q' '_' + '_' + + + ::= + # length-prefixed name + + ::= 'R' # reference + ::= 'P' # array or pointer type + ::= 'O' '_' # offset type + ::= 'M' # methods + ::= + ::= + ::= + + ::= + + ::= 'F' '_' + + ::= 'e' # () parameters + ::= 'v' # (void) parameters + ::= + + ::= + 'e' # ends in "..." + + ::= + + ::= [C] [U] [V] [u] # const, unsigned, volatile, restrict + + ::= 'i' # int + ::= 'l' # long + ::= 's' # short + ::= 'Sc' # signed char + ::= 'c' # char + ::= 'w' # wchar/java-char + ::= 'x' # long long + ::= 'b' # bool + ::= 'r' # long double + ::= 'd' # double + ::= 'f' # float + ::= 'J' # complex + ::= 'v' # void + ::= 'I' # integer of bits + + ::= # sizes < 256 + ::= _ + _ # sizes >= 256 + + ::= + ::= + + ::= 'T' # single repeat + ::= 'N' # repeats of 2..9 + ::= 'N' '_' # repeats of 10 or more + ::= 'n' # alt-style, repeats of 1..9 + ::= 'n' '_' # alt-style, repeats of 10+ + + ::= # backrefs 0..9 + ::= '_' # backrefs of 10 or more + +GCC 3.2 name mangling grammar (extracted from gcc sources): +---------------------------------------------------------- + + ::= St + # ::std + + ::= Sa + # ::std::allocator + + ::= Sb + # ::std::basic_string + + ::= Ss + # ::std::basic_string, + ::std::allocator > + + ::= Si + # ::std::basic_istream > + + ::= So + # ::std::basic_ostream > + + ::= Sd + # ::std::basic_iostream > + + ::= S _ # base 36 sequence id + ::= S_ + + ::= _Z + + ::= + ::= + + ::= + ::= + ::= + ::= + + If IGNORE_LOCAL_SCOPE option to is non-zero, this production of + is called from , which mangles the enclosing scope + elsewhere and then uses this function to mangle just the part + underneath the function scope. So don't use the + production, to avoid an infinite recursion. + + ::= + ::= St # ::std:: + + ::= + ::= + + ::= N [] E + ::= N [] E + + ::= [r] [V] [K] + + ::= > + ::= + ::= # empty + ::= + + ::=