This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[csl-hpux-branch]: object mangling
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 30 Nov 2003 16:25:58 +0000
- Subject: [csl-hpux-branch]: object mangling
- Organization: Codesourcery LLC
Hi,
I've installed this patch which effects the mangling of objects used in
expressions.
tested on ia64-hp-hpux11.23
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
The voices in my head said this was stupid too
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2003-11-30 Nathan Sidwell <nathan@codesourcery.com>
* target.h (gcc_target.abi): Add cxx_expr_decl_mangling member.
* target-def.h (TARGET_ABI_CXX_EXPR_DECL_MANGLING): New
(TARGET_ABI): Add new initializer.
* config/ia64/ia64.c (TARGET_ABI_CXX_EXPR_DECL_MANGLING): Override
on HPUX.
* doc/tm.text (TARGET_ABI_CXX_EXPR_DECL_MANGLING): Document.
* cp/Make-lang.in (cp/mangle.o): Depend on target.h
* cp/mangle.c: #include target.h.
(write_expression): Use cxx_expr_decl_mangling to determine how to
mangle DECL nodes.
* testsuite/g++.dg/abi/hpux-1.C: New test.
Index: target-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/target-def.h,v
retrieving revision 1.62.2.1
diff -c -3 -p -r1.62.2.1 target-def.h
*** target-def.h 30 Nov 2003 15:52:07 -0000 1.62.2.1
--- target-def.h 30 Nov 2003 16:11:01 -0000
*************** Foundation, 59 Temple Place - Suite 330,
*** 350,358 ****
--- 350,360 ----
}
#define TARGET_ABI_CXX_VIRTUAL_DTORS_POSITION abi_cxx_vdp_default
+ #define TARGET_ABI_CXX_EXPR_DECL_MANGLING abi_cxx_edm_default
#define TARGET_ABI { \
TARGET_ABI_CXX_VIRTUAL_DTORS_POSITION, \
+ TARGET_ABI_CXX_EXPR_DECL_MANGLING, \
}
/* The whole shebang. */
Index: target.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/target.h,v
retrieving revision 1.70.2.1
diff -c -3 -p -r1.70.2.1 target.h
*** target.h 30 Nov 2003 15:52:07 -0000 1.70.2.1
--- target.h 30 Nov 2003 16:11:02 -0000
*************** struct gcc_target
*** 448,453 ****
--- 448,460 ----
abi_cxx_vdp_last_in_vtable, /* Placed last in vtable. */
abi_cxx_vdp_declared_last /* As if they are declared last. */
} cxx_virtual_dtors_position;
+ /* How _DECL nodes are mangled in expressions. */
+ enum abi_cxx_expr_decl_mangling {
+ abi_cxx_edm_default,
+ abi_cxx_edm_as_nested_source_name /* As an indepedently mangled
+ symbol, encoded as a
+ source_name */
+ } cxx_expr_decl_mangling;
} abi;
};
Index: config/ia64/ia64.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/ia64/ia64.c,v
retrieving revision 1.259.2.1
diff -c -3 -p -r1.259.2.1 ia64.c
*** config/ia64/ia64.c 30 Nov 2003 15:52:12 -0000 1.259.2.1
--- config/ia64/ia64.c 30 Nov 2003 16:11:31 -0000
*************** static const struct attribute_spec ia64_
*** 375,380 ****
--- 375,384 ----
/* On HPUX, virtual destructors behave as if they are declared last. */
#undef TARGET_ABI_CXX_VIRTUAL_DTORS_POSITION
#define TARGET_ABI_CXX_VIRTUAL_DTORS_POSITION abi_cxx_vdp_declared_last
+ /* On HPUX DECL nodes are mangled independently and then encoded as a
+ source_name. */
+ #undef TARGET_ABI_CXX_EXPR_DECL_MANGLING
+ #define TARGET_ABI_CXX_EXPR_DECL_MANGLING abi_cxx_edm_as_nested_source_name
#endif
struct gcc_target targetm = TARGET_INITIALIZER;
Index: cp/Make-lang.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/Make-lang.in,v
retrieving revision 1.168
diff -c -3 -p -r1.168 Make-lang.in
*** cp/Make-lang.in 16 Nov 2003 06:17:15 -0000 1.168
--- cp/Make-lang.in 30 Nov 2003 16:11:32 -0000
*************** cp/semantics.o: cp/semantics.c $(CXX_TRE
*** 274,280 ****
cp/dump.o: cp/dump.c $(CXX_TREE_H) $(TM_H) tree-dump.h
cp/optimize.o: cp/optimize.c $(CXX_TREE_H) $(TM_H) rtl.h integrate.h insn-config.h \
input.h $(PARAMS_H) debug.h tree-inline.h
! cp/mangle.o: cp/mangle.c $(CXX_TREE_H) $(TM_H) toplev.h real.h gt-cp-mangle.h $(TM_P_H)
cp/parser.o: cp/parser.c $(CXX_TREE_H) $(TM_H) diagnostic.h gt-cp-parser.h output.h
--- 274,281 ----
cp/dump.o: cp/dump.c $(CXX_TREE_H) $(TM_H) tree-dump.h
cp/optimize.o: cp/optimize.c $(CXX_TREE_H) $(TM_H) rtl.h integrate.h insn-config.h \
input.h $(PARAMS_H) debug.h tree-inline.h
! cp/mangle.o: cp/mangle.c $(CXX_TREE_H) $(TM_H) toplev.h target.h real.h \
! gt-cp-mangle.h $(TM_P_H)
cp/parser.o: cp/parser.c $(CXX_TREE_H) $(TM_H) diagnostic.h gt-cp-parser.h output.h
Index: cp/mangle.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/mangle.c,v
retrieving revision 1.88
diff -c -3 -p -r1.88 mangle.c
*** cp/mangle.c 22 Oct 2003 02:08:45 -0000 1.88
--- cp/mangle.c 30 Nov 2003 16:11:45 -0000
***************
*** 58,63 ****
--- 58,64 ----
#include "obstack.h"
#include "toplev.h"
#include "varray.h"
+ #include "target.h"
/* Debugging support. */
***************
*** 89,95 ****
|| (CLASSTYPE_TEMPLATE_INFO (NODE) != NULL \
&& (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (NODE))))))
! /* Things we only need one of. This module is not reentrant. */
static struct globals
{
/* The name in which we're building the mangled name. */
--- 90,97 ----
|| (CLASSTYPE_TEMPLATE_INFO (NODE) != NULL \
&& (PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (NODE))))))
! /* Things we only need one of. We are only reentrant when mangling
! template arguments that are external objects. */
static struct globals
{
/* The name in which we're building the mangled name. */
*************** write_expression (tree expr)
*** 1893,1899 ****
if (code == CONST_DECL)
G.need_abi_warning = 1;
write_char ('L');
! write_mangled_name (expr);
write_char ('E');
}
else if (TREE_CODE (expr) == SIZEOF_EXPR
--- 1896,1943 ----
if (code == CONST_DECL)
G.need_abi_warning = 1;
write_char ('L');
!
! switch (targetm.abi.cxx_expr_decl_mangling)
! {
! case abi_cxx_edm_default:
! write_mangled_name (expr);
! break;
! case abi_cxx_edm_as_nested_source_name:
! {
! /* HPUX mangles the declaration in its own right, and then
! uses that as a <source-name>. We must nest the current
! mangling completely. Substitutions do not cross over
! between current and inner manglings. */
! varray_type substs;
! char *decl_mangle;
! char *current_mangle;
! tree entity;
!
! /* Save the current mangling context. */
! write_char (0);
! current_mangle =
! xstrdup ((const char *)obstack_base (&G.name_obstack));
! substs = G.substitutions;
! entity = G.entity;
!
! /* Mangle the declaration in its own right. */
! decl_mangle = xstrdup (mangle_decl_string (expr));
! obstack_free (&G.name_obstack, obstack_base (&G.name_obstack));
!
! /* Restore the mangling context. */
! G.entity = entity;
! G.substitutions = substs;
! write_string (current_mangle);
!
! /* Append the decl's mangling with a character count. */
! write_unsigned_number (strlen (decl_mangle));
! write_string (decl_mangle);
!
! free (decl_mangle);
! free (current_mangle);
! break;
! }
! }
write_char ('E');
}
else if (TREE_CODE (expr) == SIZEOF_EXPR
Index: doc/tm.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/tm.texi,v
retrieving revision 1.266.2.1
diff -c -3 -p -r1.266.2.1 tm.texi
*** doc/tm.texi 30 Nov 2003 15:52:11 -0000 1.266.2.1
--- doc/tm.texi 30 Nov 2003 16:12:13 -0000
*************** the difference is that @code{abi_cxx_vdp
*** 4518,4523 ****
--- 4518,4534 ----
choice of key function, but @code{abi_cxx_vdp_last_in_vtable} does not.)
@end deftypevr
+ @findex abi_cxx_edm_default
+ @findex abi_cxx_edm_as_nested_source_name
+ @deftypevr {Target Hook} {enum cxx_expr_decl_mangling} TARGET_ABI_CXX_EXPR_DECL_MANGLING
+ Set this hook if the default mangling of DECL nodes in expressions is
+ is not correct for the platform C++ ABI. The default is
+ @code{abi_cxx_edm_default}, which means they are mangled recursively
+ within the current mangling. If instead they should be mangled
+ independently and then encoded as a @code{source-name}, set the hook to
+ @code{abi_cxx_edm_as_nested_source_name}.
+ @end deftypevr
+
@node Trampolines
@section Trampolines for Nested Functions
@cindex trampolines for nested functions
// { dg-do compile { target ia64-hpux-* } }
// Copyright (C) 2003 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 30 Nov 2003 <nathan@codesourcery.com>
// Test mangling of expressions with DECLs on hpux - it is different
extern const int L = 3;
template <int I> struct S1 {};
template <int I> void f (S1<L>) {};
template void f<7>(S1<L>);
// { dg-final { scan-assembler "\n_Z1fILi7EEv2S1ILi3EE:" } }
template <int I> void g (S1<L+I>) {};
template void g<7>(S1<L+7>);
// { dg-final { scan-assembler "\n_Z1gILi7EEv2S1IXplL1LET_EE:" } }
template <int I> void h (S1<L+1>) {};
template void h<7>(S1<L+1>);
// { dg-final { scan-assembler "\n_Z1hILi7EEv2S1ILi4EE:" } }
extern "C" void Foo ();
extern void Bar ();
template <void (*)()> struct S2 {};
void f2 (S2<Foo>){}
// { dg-final { scan-assembler "\n_Z2f22S2IXadL3FooEEE:" } }
void g2 (S2<Bar>){}
// { dg-final { scan-assembler "\n_Z2g22S2IXadL7_Z3BarvEEE:" } }
extern int N;
extern "C" int M;
template <int &> struct S3 {};
void n (S3<N>) {}
// { dg-final { scan-assembler "\n_Z1n2S3IXadL1NEEE:" } }
void m (S3<M>) {}
// { dg-final { scan-assembler "\n_Z1m2S3IXadL1MEEE:" } }
struct XXX {};
extern void Foo (XXX *, XXX *);
template <void (*)(XXX *, XXX *)> struct S4 {};
// Substitutions do not cross between nester and nestee
void f3 (XXX *, S4<Foo>){}
// { dg-final { scan-assembler "\n_Z2f3P3XXX2S4IXadL14_Z3FooP3XXXS0_EEE:" } }
void g3 (S4<Foo>, XXX *){}
// { dg-final { scan-assembler "\n_Z2g32S4IXadL14_Z3FooP3XXXS0_EEEP3XXX:" } }