llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.03k stars 11.97k forks source link

clang claims weak aliases are not supported on Darwin but only when using __attribute__, works fine with #pragma #71001

Open CodingMarkus opened 1 year ago

CodingMarkus commented 1 year ago

clang claims weak aliases are not supported on Darwin. The following code doesn't compile:

#include <stdio.h>

int func1( ) { return 42; }
__attribute__((weak, alias("func1")))  int func2( );

int main( )
{
    printf("%d\n", func2());
    return 0;
}

Output:

test1.c:4:22: error: aliases are not supported on darwin
__attribute__((weak, alias("func1")))  int func2( );
                     ^
1 error generated.

But that's not true. Weak aliases are supported on Darwin. The following code will compile and will behave correctly:

#include <stdio.h>

int func1( ) { return 42; }

#pragma weak func2 = func1
int func2( );

int main( )
{
    printf("%d\n", func2());
    return 0;
}
CodingMarkus commented 1 year ago

This could be seen as a dupe of #11488, albeit that report was about the error message which used to be only weak aliases are supported on darwin at that time and made even less sense to me, since it came when the code was trying to make exactly that, a weak alias.

shafik commented 1 year ago

CC @rjmccall

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-frontend

Author: None (CodingMarkus)

clang claims weak aliases are not supported on Darwin. The following code doesn't compile: ``` #include <stdio.h> int func1( ) { return 42; } __attribute__((weak, alias("func1"))) int func2( ); int main( ) { printf("%d\n", func2()); return 0; } ``` Output: ``` test1.c:4:22: error: aliases are not supported on darwin __attribute__((weak, alias("func1"))) int func2( ); ^ 1 error generated. ``` But that's not true. Weak aliases are supported on Darwin. The following code will compile and will behave correctly: ``` #include <stdio.h> int func1( ) { return 42; } #pragma weak func2 = func1 int func2( ); int main( ) { printf("%d\n", func2()); return 0; } ```