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

nativesdk-clang does not find its sanitizer/*.h include files #978

Open
dkl opened this issue Jul 18, 2024 · 15 comments · Fixed by #994
Open

nativesdk-clang does not find its sanitizer/*.h include files #978

dkl opened this issue Jul 18, 2024 · 15 comments · Fixed by #994

Comments

@dkl
Copy link

dkl commented Jul 18, 2024

Hi,

Describe the bug
When trying to compile projects using #include <sanitizer/asan_interface.h> (for example libabsl) by using clang from the Yocto SDK with nativesdk-clang and compiler-rt-sanitizers, it shows fatal error: 'sanitizer/asan_interface.h' file not found. The file exists in $OECORE_TARGET_SYSROOT/usr/lib/clang/$version/include, but clang only uses $OECORE_NATIVE_SYSROOT/usr/lib/clang/$version/include and $OECORE_TARGET_SYSROOT/usr/include.

To Reproduce
Tested with poky + meta-clang, both branch scarthgap, with the following settings appended to local.conf:

CLANGSDK = "1"
TOOLCHAIN_TARGET_TASK:append = " compiler-rt-sanitizers"

and then

bitbake core-image-minimal -cpopulate_sdk

and then installing the SDK and using a compile command like $CLANGCC -fsanitize=address foo.c -c, where foo.c is simply

#include <sanitizer/asan_interface.h>

Expected behavior
With gcc and gcc-sanitizers it works fine, so I'm assuming that clang should automatically use the include path from compiler-rt-sanitizers too.

Additional context
Possible work-around: Add -isystem "$SDKTARGETSYSROOT/usr/lib/clang/18.1.5/include" when compiling affected projects

@FederAndInk
Copy link

I too have this issue for the native and target toolchain, clang is installed under /usr/lib/clang/$version but the sanitizers are under /usr/lib/clang/$version.$minor.$patch

kraj added a commit to YoeDistro/meta-clang that referenced this issue Aug 9, 2024
…issue

Instead of moving the whole install under major.minor.patch, create a symlink
so both can be included

Fixes kraj#978

Signed-off-by: Khem Raj <[email protected]>
@kraj
Copy link
Owner

kraj commented Aug 9, 2024

@dkl and @FederAndInk can you test the patch in #994 and report back ?

@FederAndInk
Copy link

Sure, thanks, testing this right now 👍

@kraj
Copy link
Owner

kraj commented Aug 9, 2024

Sure, thanks, testing this right now 👍

I think the problem is that the compiler headers path it pointing to recipe-sysroot-native and not recipe-sysroot. The patch I posted will not solve that problem. On the other hand if you add

TOOLCHAIN_TARGET_TASK:append = " nativesdk-compiler-rt-sanitizers"

This will work.

@FederAndInk
Copy link

Actually I am building clang for the target and using it on the "target", with the patch you posted, it is now working

@FederAndInk
Copy link

FederAndInk commented Aug 9, 2024

I will be testing the sdk variant soon

@FederAndInk
Copy link

TOOLCHAIN_TARGET_TASK:append = " nativesdk-compiler-rt-sanitizers"

This will work.

isn't a bit weird to put a nativesdk version in TOOLCHAIN_TARGET_TASK? What will that do? will the target libraries be generated and available to be linked against?

@FederAndInk
Copy link

ok so looks like you're right, trying ${CLANGCXX} test.cpp -v we can see clang search paths looking in target sysroot but 1 (usr/lib/clang/18) searching for it in the native sysroot:

Documents/sdk/sysroots/corei7-64-oe-linux/lib/x86_64-oe-linux/13.3.0/../../../include/c++/13.3.0                            
Documents/sdk/sysroots/corei7-64-oe-linux/lib/x86_64-oe-linux/13.3.0/../../../include/c++/13.3.0/x86_64-oe-linux            
Documents/sdk/sysroots/corei7-64-oe-linux/lib/x86_64-oe-linux/13.3.0/../../../include/c++/13.3.0/backward                   
Documents/sdk/sysroots/x86_64-vendor-linux/usr/lib/clang/18/include                                                           
Documents/sdk/sysroots/corei7-64-oe-linux/usr/include

@kraj
Copy link
Owner

kraj commented Aug 9, 2024

TOOLCHAIN_TARGET_TASK:append = " nativesdk-compiler-rt-sanitizers"
This will work.

isn't a bit weird to put a nativesdk version in TOOLCHAIN_TARGET_TASK? What will that do? will the target libraries be generated and available to be linked against?

yeah I dont think its the right solution, I was just saying this to prove the problem as we understand. I think correct fix would be to fix the compiler to look into target sysroot for compiler headers.

@kraj
Copy link
Owner

kraj commented Aug 9, 2024

Actually I am building clang for the target and using it on the "target", with the patch you posted, it is now working

OK, so this patch atleast fixes one case. So maybe we can merge this one and keep searching to solve the second one in nativesdk cross compiler include search path fixes.

@FederAndInk
Copy link

FederAndInk commented Aug 10, 2024

TOOLCHAIN_TARGET_TASK:append = " nativesdk-compiler-rt-sanitizers"
This will work.

isn't a bit weird to put a nativesdk version in TOOLCHAIN_TARGET_TASK? What will that do? will the target libraries be generated and available to be linked against?

yeah I dont think its the right solution, I was just saying this to prove the problem as we understand. I think correct fix would be to fix the compiler to look into target sysroot for compiler headers.

ok I see your point

Actually I am building clang for the target and using it on the "target", with the patch you posted, it is now working

OK, so this patch atleast fixes one case. So maybe we can merge this one and keep searching to solve the second one in nativesdk cross compiler include search path fixes.

right, thanks again :)
btw, I see that debian is doing a similar thing they install the toolchain under usr/lib/llvm-<major> and make usr/lib/clang/<major> and usr/lib/clang/<major>.<minor>.<patch> symlinks to ../llvm-<major>

@kraj kraj closed this as completed in #994 Aug 11, 2024
@kraj kraj closed this as completed in a219212 Aug 11, 2024
@FederAndInk
Copy link

Hey, thanks for merging a first part of the solution :)
Can we hope for a backport to the scarthgap branch?

Also, I think this issue should be re-openned as #994 only fixes the on-target part, what do you think @kraj?

@kraj
Copy link
Owner

kraj commented Aug 11, 2024

Yes reopen it and please sent a pull request for scarthgap

@kraj kraj reopened this Aug 11, 2024
FederAndInk pushed a commit to FederAndInk/meta-clang that referenced this issue Aug 12, 2024
…issue

Instead of moving the whole install under major.minor.patch, create a symlink
so both can be included

Fixes kraj#978

Signed-off-by: Khem Raj <[email protected]>
Signed-off-by: Ludovic Jozeau <[email protected]>

(cherry picked from commit a219212)
kraj added a commit that referenced this issue Aug 15, 2024
…issue

Instead of moving the whole install under major.minor.patch, create a symlink
so both can be included

Fixes #978

Signed-off-by: Khem Raj <[email protected]>
Signed-off-by: Ludovic Jozeau <[email protected]>

(cherry picked from commit a219212)
@dkl
Copy link
Author

dkl commented Aug 19, 2024

After the patch which adds the symlink to compiler-rt-sanitizers, there is a conflict with compiler-rt-dev which provides a single file /usr/lib/clang/18.1.8/include/orc/c_api.h. From dnf:

  file /usr/lib/clang/18.1.8 conflicts between attempted installs of compiler-rt-sanitizers-18.1.8-r0.core2_64 and compiler-rt-dev-18.1.8-r0.core2_64

(/usr/lib/clang/18.1.8 is a symlink in one, but a normal directory in the other)

@FederAndInk
Copy link

right, I guess the same logic should be applied to compiler-rt recipe too

jpuhlman pushed a commit to MontaVista-OpenSourceTechnology/meta-clang that referenced this issue Aug 19, 2024
…issue

Source: meta-clang
MR: 158405
Type: Integration
Disposition: Merged from meta-clang
ChangeID: 7d9bf6d
Description:

Instead of moving the whole install under major.minor.patch, create a symlink
so both can be included

Fixes kraj/meta-clang#978

Signed-off-by: Khem Raj <[email protected]>
Signed-off-by: Ludovic Jozeau <[email protected]>

(cherry picked from commit a219212)

Signed-off-by: Jeremy A. Puhlman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants