public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* RFC: adding lookups on the target names for alias attributes
@ 2000-09-20 18:22 Greg McGary
  2000-09-21  0:35 ` Greg McGary
  2000-09-21 14:22 ` llewelly
  0 siblings, 2 replies; 3+ messages in thread
From: Greg McGary @ 2000-09-20 18:22 UTC (permalink / raw)
  To: gcc; +Cc: greg

The target name in an alias attribute is always used verbatim and
never looked-up.  The programmer needed to explicitly mangle C++
function names, and if the alias attribute didn't name a valid program
object it was silently ineffectual, passing from compiler to
assembler, then silently ignored by the assembler.

I would like to change that, to the degree that seems reasonable,
primarily for the benefit of bounded-pointer name mangling.

For C++, it seems reasonable, though painful, to require that the
programmer explicitly mangle the target name in order to disambiguate
overloaded names.  C++ doesn't seem so important for alias attributes
though, since I don't see any uses of alias attributes in libstdc++.

I'd like to do this in decl_attributes:

1) Lookup the target name, seeking a decl with the same
   flavor (function, data, type, whatever) as the aliasing decl
   yielding a target decl.

2) If a target decl of appropriate flavor is found and is unambiguous
   (overloading in C++ being the primary source of ambiguity), use the
   target decl's DECL_ASSEMBLER_NAME as the alias target, rather than
   the programmer-supplied target string.

   If the target name is not found, is the wrong flavor, or is
   ambiguous, issue a warning and use the programmer-supplied string.
   The warning is justified because if the target remains undefined in
   the object file, then the assembler will silently ignore the alias,
   which is unexpected and sometimes confusing behavior.  It's easy
   enough to avoid the warning by placing the alias decl after the
   target's definition.  Explicitly mangled C++ names need special
   handling to avoid the warning, but I'm inclined to just let that
   slide for now since aliases seem to be seldom, if ever, used in C++.

Does that sound reasonable?

I have already implemented something like this on GCC's
bounded-pointers-branch and it's been operational and trouble-free
for months for glibc on ix86 and PowerPC.

Greg

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: RFC: adding lookups on the target names for alias attributes
  2000-09-20 18:22 RFC: adding lookups on the target names for alias attributes Greg McGary
@ 2000-09-21  0:35 ` Greg McGary
  2000-09-21 14:22 ` llewelly
  1 sibling, 0 replies; 3+ messages in thread
From: Greg McGary @ 2000-09-21  0:35 UTC (permalink / raw)
  To: gcc

Greg McGary <greg@mcgary.org> writes:

> I'd like to do this in decl_attributes:
> 
> 1) Lookup the target name, seeking a decl with the same
>    flavor (function, data, type, whatever) as the aliasing decl
>    yielding a target decl.
> 
> 2) If a target decl of appropriate flavor is found and is unambiguous
>    (overloading in C++ being the primary source of ambiguity), use the
>    target decl's DECL_ASSEMBLER_NAME as the alias target, rather than
>    the programmer-supplied target string.
> 
>    If the target name is not found, is the wrong flavor, or is
>    ambiguous, issue a warning and use the programmer-supplied string.
>    The warning is justified because if the target remains undefined in
>    the object file, then the assembler will silently ignore the alias,
>    which is unexpected and sometimes confusing behavior.  It's easy
>    enough to avoid the warning by placing the alias decl after the
>    target's definition.  Explicitly mangled C++ names need special
>    handling to avoid the warning, but I'm inclined to just let that
>    slide for now since aliases seem to be seldom, if ever, used in C++.

Don't everyone chime in at once!  8^)

Here's a better idea: As documented, the alias attribute takes a
literal-string argument, but the parser will accept an identifier as a
general attribute arg well.  Therefore, retain old behavior for
literal-string targets.  Implement new behavior when an identifier
appears as target name.  For C++, the parser should accept a
scope-qualified name (e.g., alias (a::b))

Example:

Old style:
	/* OK to reference "__foo" before __foo is defined.  */
	void foo () attribute ((alias ("__foo")));
	void __foo () {}

New style:
	void __foo () {}
	/* Must define __foo before referencing it.  */
	void foo () attribute ((alias (__foo)));

Basically, the new style gives better error checking, since it will
ensure (a) that a target name is declared before being referenced as
an alias target, (b) that the decls of alias and target are consistent
(same flavor; and for functions, that arg signatures match), (c)
the alias target is automatically mangled.

Comments?

Greg

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: RFC: adding lookups on the target names for alias attributes
  2000-09-20 18:22 RFC: adding lookups on the target names for alias attributes Greg McGary
  2000-09-21  0:35 ` Greg McGary
@ 2000-09-21 14:22 ` llewelly
  1 sibling, 0 replies; 3+ messages in thread
From: llewelly @ 2000-09-21 14:22 UTC (permalink / raw)
  To: Greg McGary; +Cc: gcc

Greg McGary <greg@mcgary.org> writes:

> The target name in an alias attribute is always used verbatim and
> never looked-up.  The programmer needed to explicitly mangle C++
> function names, and if the alias attribute didn't name a valid program
> object it was silently ineffectual, passing from compiler to
> assembler, then silently ignored by the assembler.
> 
> I would like to change that, to the degree that seems reasonable,
> primarily for the benefit of bounded-pointer name mangling.
> 
> For C++, it seems reasonable, though painful, to require that the
> programmer explicitly mangle the target name in order to disambiguate
> overloaded names.

I do not think alias attributes are often needed in C++ (C++ provides
  a number of standard conforming ways to get vaguely similar
  effects), so I am not suggesting your improvement is bad or
  inadequate, but in my opinion, a feature that requires a C++
  programer to provide a mangled name is a feature which is not merely
  painful to use, but infeasible to use. E.g., the current semantics
  of alias mean it is no better than an alias which did not work at
  all for C++ functions, and your suggestion suggestion means it is
  (nearly) unusable for overloaded C++ functions. 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-09-21 14:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-20 18:22 RFC: adding lookups on the target names for alias attributes Greg McGary
2000-09-21  0:35 ` Greg McGary
2000-09-21 14:22 ` llewelly

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).