rizsotto / Bear

Bear is a tool that generates a compilation database for clang tooling.
GNU General Public License v3.0
4.76k stars 312 forks source link

build fails with Yocto Dunfell cross compiler #472

Open joakim-tjernlund opened 2 years ago

joakim-tjernlund commented 2 years ago
 ARCH=arm64 CROSS_COMPILE=/opt/infn-xr/1.0/sysroots/x86_64-xrsdk-linux/usr/bin/aarch64-xr-linux-musl/aarch64-xr-linux-musl- bear -- make  -j9
/opt/infn-xr/1.0/sysroots/x86_64-xrsdk-linux/usr/bin/aarch64-xr-linux-musl/aarch64-xr-linux-musl-gcc: /opt/infn-xr/1.0/sysroots/x86_64-xrsdk-linux/lib/libc.so.6: version `GLIBC_2.34' not found (required by /usr/lib64/bear/libexec.so)
/opt/infn-xr/1.0/sysroots/x86_64-xrsdk-linux/usr/bin/aarch64-xr-linux-musl/aarch64-xr-linux-musl-gcc: /opt/infn-xr/1.0/sysroots/x86_64-xrsdk-linux/lib/libc.so.6: version `GLIBC_2.33' not found (required by /usr/lib64/bear/libexec.so)
joakim-tjernlund commented 2 years ago

bear 3.0.19

joakim-tjernlund commented 2 years ago

readelf on the cross compiler gives:

 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2]
 0x000000000000000f (RPATH)              Library rpath: [$ORIGIN/../../lib]

[Requesting program interpreter: /opt/infn-xr/1.0/sysroots/x86_64-xrsdk-linux/lib/ld-linux-x86-64.so.2]

So I presume bear is then tricked into using this older glibc and it fails. Is it possible to build bear with static libs ?

rizsotto commented 2 years ago

Alternatively you can try --force-wrapper flag for Bear. That case it will use compiler wrappers, and won't clash with the libC. The only thing you might want to pay attention for that case, the build system needs to respect the CC and CXX environment variables.

rizsotto commented 2 years ago

Any luck @joakim-tjernlund ?

joakim-tjernlund commented 2 years ago

On vacation ATM but I did a test build with --force-wrapper and it built the kernel/u-boot so it looks better. Looking at the compile_commands.json generated file I only see a few files in there, only files that are built with the host gcc like scripts/sorttable.c or lib/gen_crc32table.c

rizsotto commented 2 years ago

The reason for that is, you specify the CROSS_COMPILE environment variable. The CC (or CXX) environment would be better for that. Can you change the build to use those environment variables instead? (Bear replace those env variables with a compile wrapper, and only those will get captured.)

joakim-tjernlund commented 2 years ago

The reason for that is, you specify the CROSS_COMPILE environment variable. The CC (or CXX) environment would be better for that. Can you change the build to use those environment variables instead? (Bear replace those env variables with a compile wrapper, and only those will get captured.)

I don't think I can do that, both Linux kernel and u-boot depends hard on CROSS_COMPILE. It is an common way to express cross compilation and I think the best would be if bear supports the CROSS_COMPILE variable.

rizsotto commented 2 years ago

Ok. Can you share some man page/link that explains this variable usage?

joakim-tjernlund commented 2 years ago

That was harder to find but this is one page: https://hugh712.gitbooks.io/embeddedsystem/content/cross-compiling_the_kernel.html

Basically it an prefix like arm-linux- , then the build system construct a compiler/linker by appending gcc or ld. The CROSS_COMPILE var can be an absolute path like /opt//my-cross/arm-linux- or just arm-linux- and then the normal PATH is searched.

rizsotto commented 2 years ago

Thanks @joakim-tjernlund , I see now... Can you try a workaround for me?

Bear install an executable called wrapper, which as the name suggests wraps program executions. It also install a directory called wrapper.d, which contains soft links to the wrapper. Could you create soft links in this directory with the cross compiler names? (eg.: arm-linux-gcc, arm-linux-ld, etc...)

Execute Bear with the --force-wrapper flag. You might also want to specify a config file location with --config <path>, where the config contains instructions to recognize these programs as compiler. (See more here .)

joakim-tjernlund commented 2 years ago

been on vacation a few weeks and forgot about this, sorry. Question though, both u-boot and kernel needs both the host compiler (aka plain gcc) and the cross compiler. Will bear manage both?