[patch] Don't allow alias to point to declarations

Rafael EspĂ­ndola rafael.espindola at gmail.com
Wed Oct 23 12:00:01 PDT 2013


Ping. The clang side has been fixed.

On Wednesday, October 16, 2013, Rafael EspĂ­ndola wrote:

> A long time ago (before r97733) we used to model the weakref attribute
> by outputting a new declaration and a weak alias to it. This was
> fairly buggy and we now implement weakref directly in clang, with the
> same logic an assembler uses to implement .weakref (which is what gcc
> prints).
>
> One thing that was left from that old implementation is that we still
> have alias to declarations and they are a very different concept from
> alias to definitions.
>
> Alias to definitions are just another symbol pointing to the same
> position in the object file. For example, given
>
> @bar = alias void ()* @foo
> define void @foo() {
>   ret void
> }
>
> Both ELF end COFF just get two symbols (foo and bar or _foo and _bar)
> pointing to the same section and offset.
>
> Alias to declarations are a lot fuzzier. They are still considered
> definitions according to GlobalValue::isDeclaration(), but the IR
>
> @bar = alias void ()* @foo
> declare void @foo()
>
> produces an empty ELF file and COFF files with two undefined symbols,
> but no connection between them. There is no good answer, since neither
> COFF nor ELF have an alias directive to pass the connection down to
> the linker.
>
> The only possible use right now seems to be what we used to do for
> weakref. Given
>
> @bar = hidden alias void ()* @foo
> declare void @foo()
> define void @zed() {
>        call void @foo()
>        call void @bar()
>        ret void
> }
>
> llc with the pic relocation model will produce a R_X86_64_PLT32 and a
> R_X86_64_PC32, both pointing to foo. That is, the alias acts as an
> alternative declaration.
>
> The supported way of doing this is to have a proper declaration in the
> file using the symbol:
>
> declare hidden void @bar()
> declare void @foo()
> define void @zed() {
>        call void @foo()
>        call void @bar()
>        ret void
> }
>
> and an alias on the file defining foo:
>
> @bar = hidden alias void ()* @foo
> define void @foo() {
>        ret void
> }
>
> With all that in mind, the attached patch changes the verifier to
> reject aliases to declarations and updates that language reference.
> The patch also updates the testcases. They seem to be almost all from
> the old weakref implementation.
>
> The patch itself depends on the patch to fix pr17535 so that clang
> detects the error before hitting the verifier on invalid input, but
> can hopefully be reviewed in parallel.
>
> Cheers,
> Rafael
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131023/f1f291dd/attachment.html>


More information about the llvm-commits mailing list