[cfe-dev] __attribute__((alias))

Eli Friedman eli.friedman at gmail.com
Sat Jul 5 14:13:36 PDT 2008


On Sat, Jul 5, 2008 at 12:24 PM, Nuno Lopes <nunoplopes at sapo.pt> wrote:
> Hi,
>
> Some time ago I added support for __attribute__((alias)). However it is not
> working when referencing an aliased function from a different file where it
> was defined.
> Take a look at this example:
>
> foo.ll:
> declare void @zend_error(i32, i8*, ...)
> ;declare void @zend_error_noreturn(i32, i8*, ...) noreturn
> @zend_error_noreturn = alias void (i32, i8*, ...)* @zend_error  ; <void
> (i32, i8*, ...)*> [#uses=0]
>
>
> bar.ll:
> declare void @zend_error_noreturn(i32, i8*, ...) noreturn
>
> linking those files leads to:
> llvm-as foo.ll; llvm-as bar.ll
> llvm-ld -native -o xpto foo.bc bar.bc
>
> llvm-ld: LinkModules.cpp:425: void ForceRenaming(llvm::GlobalValue*, const
> std::string&): Assertion `ConflictGV->hasInternalLinkage() && "Not
> conflicting with a static global, should link instead!"' failed.
>
> If you uncomment the 2nd line of foo.ll it doesn't trigger that exception.
> Is this a bug in the linker or should clang generate the extra declaration?

Mmm, yes, I remember seeing that alias when I tried compiling PHP; I
got around it by tweaking a couple of ifdefs.

I think llvm-ld is doing the wrong thing here.  Testcase:
x.c:
int a() {return 0;}int b() __attribute((alias("a")));
y.c:
int b(); int main() {return b();}

Both clang and llvm-gcc generate approximately the same thing, the
results of both cause link errors with llvm-ld, and both work fine if
compiled separately.

-Eli



More information about the cfe-dev mailing list