Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CodingMarkus opened this issue Nov 1, 2023 · 3 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" platform:macos

Comments

@CodingMarkus
Copy link

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;
}
@github-actions github-actions bot added the clang Clang issues not falling into any other category label Nov 1, 2023
@CodingMarkus
Copy link
Author

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
Copy link
Collaborator

shafik commented Nov 1, 2023

CC @rjmccall

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" platform:macos and removed clang Clang issues not falling into any other category labels Nov 1, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 1, 2023

@llvm/issue-subscribers-clang-frontend

Author: None (CodingMarkus)

clang claims weak aliases are not supported on Darwin. The following code doesn't compile:
#include &lt;stdio.h&gt;

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 &lt;stdio.h&gt;

int func1( ) { return 42; }

#pragma weak func2 = func1
int func2( );

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

roxell pushed a commit to roxell/linux that referenced this issue Jan 29, 2024
Aiden Leong reported modpost fails to build on macOS since commit
16a473f ("modpost: inform compilers that fatal() never returns"):

  scripts/mod/modpost.c:93:21: error: aliases are not supported on darwin

Nathan's research indicates that Darwin seems to support weak aliases
at least [1]. Although the situation might be improved in future Clang
versions, we can achieve a similar outcome without relying on it.

This commit makes fatal() a macro of error() + exit(1) in modpost.h, as
compilers recognize that exit() never returns.

[1]: llvm/llvm-project#71001

Fixes: 16a473f ("modpost: inform compilers that fatal() never returns")
Reported-by: Aiden Leong <aiden.leong@aibsd.com>
Closes: https://lore.kernel.org/all/d9ac2960-6644-4a87-b5e4-4bfb6e0364a8@aibsd.com/
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
ColinIanKing pushed a commit to ColinIanKing/linux-next that referenced this issue Feb 1, 2024
Aiden Leong reported modpost fails to build on macOS since commit
16a473f ("modpost: inform compilers that fatal() never returns"):

  scripts/mod/modpost.c:93:21: error: aliases are not supported on darwin

Nathan's research indicates that Darwin seems to support weak aliases
at least [1]. Although the situation might be improved in future Clang
versions, we can achieve a similar outcome without relying on it.

This commit makes fatal() a macro of error() + exit(1) in modpost.h, as
compilers recognize that exit() never returns.

[1]: llvm/llvm-project#71001

Fixes: 16a473f ("modpost: inform compilers that fatal() never returns")
Reported-by: Aiden Leong <aiden.leong@aibsd.com>
Closes: https://lore.kernel.org/all/d9ac2960-6644-4a87-b5e4-4bfb6e0364a8@aibsd.com/
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" platform:macos
Projects
None yet
Development

No branches or pull requests

4 participants