if (DECL_ONE_ONLY (function))
thunk_node->add_to_same_comdat_group (funcn);
-
- /* Target assemble_mi_thunk doesn't work across section boundaries
- on many targets, instead force thunk to be expanded in gimple. */
- if (DECL_EXTERNAL (function))
- {
- /* cgraph::expand_thunk writes over current_function_decl, so if this
- could ever be in use by the codegen pass, we want to know about it. */
- gcc_assert (current_function_decl == NULL_TREE);
-
- if (!stdarg_p (TREE_TYPE (thunk)))
- {
- thunk_node->create_edge (funcn, NULL, thunk_node->count);
- expand_thunk (thunk_node, false, true);
- }
-
- /* Tell the back-end to not bother inlining the function, this is
- assumed not to work as it could be referencing symbols outside
- of the current compilation unit. */
- DECL_UNINLINABLE (function) = 1;
- }
}
/* Return a thunk to DECL. Thunks adjust the incoming `this' pointer by OFFSET.
DECL_CONTEXT (thunk) = d_decl_context (decl);
- /* Thunks inherit the public access of the function they are targetting.
- When the function is outside the current compilation unit however, then the
- thunk must be kept private to not conflict. */
- TREE_PUBLIC (thunk) = TREE_PUBLIC (function) && !DECL_EXTERNAL (function);
-
- DECL_EXTERNAL (thunk) = 0;
+ /* Thunks inherit the public access of the function they are targeting.
+ Thunks are connected to the definitions of the functions, so thunks are
+ not produced for external functions. */
+ TREE_PUBLIC (thunk) = TREE_PUBLIC (function);
+ DECL_EXTERNAL (thunk) = DECL_EXTERNAL (function);
/* Thunks are always addressable. */
TREE_ADDRESSABLE (thunk) = 1;
DECL_COMDAT (thunk) = DECL_COMDAT (function);
DECL_WEAK (thunk) = DECL_WEAK (function);
- tree target_name = DECL_ASSEMBLER_NAME (function);
- unsigned identlen = IDENTIFIER_LENGTH (target_name) + 14;
- const char *ident = XNEWVEC (const char, identlen);
- snprintf (CONST_CAST (char *, ident), identlen,
- "_DT%u%s", offset, IDENTIFIER_POINTER (target_name));
+ /* When the thunk is for an extern C++ function, let C++ do the thunk
+ generation and just reference the symbol as extern, instead of
+ forcing a D local thunk to be emitted. */
+ const char *ident;
+
+ if (decl->linkage == LINKcpp)
+ ident = target.cpp.thunkMangle (decl, offset);
+ else
+ {
+ tree target_name = DECL_ASSEMBLER_NAME (function);
+ unsigned identlen = IDENTIFIER_LENGTH (target_name) + 14;
+ ident = XNEWVEC (const char, identlen);
+
+ snprintf (CONST_CAST (char *, ident), identlen,
+ "_DTi%u%s", offset, IDENTIFIER_POINTER (target_name));
+ }
DECL_NAME (thunk) = get_identifier (ident);
SET_DECL_ASSEMBLER_NAME (thunk, DECL_NAME (thunk));
d_keep (thunk);
+ free (CONST_CAST (char *, ident));
- finish_thunk (thunk, function);
+ if (!DECL_EXTERNAL (function))
+ finish_thunk (thunk, function);
/* Add it to the list of thunks associated with the function. */
DECL_LANG_THUNKS (thunk) = NULL_TREE;
//printf("mangle_function(%s)\n", d->toChars());
/*
* <mangled-name> ::= _Z <encoding>
+ */
+ buf->writestring("_Z");
+ this->mangle_function_encoding(d);
+ }
+
+ void mangle_function_encoding(FuncDeclaration *d)
+ {
+ //printf("mangle_function_encoding(%s)\n", d->toChars());
+ /*
* <encoding> ::= <function name> <bare-function-type>
* ::= <data name>
* ::= <special-name>
*/
TypeFunction *tf = (TypeFunction *)d->type;
- buf->writestring("_Z");
if (getFuncTemplateDecl(d))
{
/* It's an instance of a function template
v.cpp_mangle_name(s, false);
return buf.extractChars();
}
+
+const char *cppThunkMangleItanium(FuncDeclaration *fd, int offset)
+{
+ //printf("cppThunkMangleItanium(%s)\n", fd.toChars());
+ OutBuffer buf;
+ buf.printf("_ZThn%u_", offset); // "Th" means thunk, "n%u" is the call offset
+ CppMangleVisitor v(&buf, fd->loc);
+ v.mangle_function_encoding(fd);
+ return buf.extractChars();
+}