rizsotto / Bear

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

Bear spawns an endless number of processes on FreeBSD #557

Open Jehops opened 6 months ago

Jehops commented 6 months ago

After this commit on FreeBSD's main branch, bear will indefinitely spawn new processes.

root@15amd64-default:~ # uname -a
FreeBSD 15amd64-default 15.0-CURRENT FreeBSD 15.0-CURRENT 1500008 amd64

root@15amd64-default:~ # pkg info bear | head -11
bear-3.1.3_4
Name           : bear
Version        : 3.1.3_4
Installed on   : Tue Jan  2 13:54:27 2024 UTC
Origin         : devel/bear
Architecture   : FreeBSD:15:amd64
Prefix         : /usr/local
Categories     : devel
Licenses       : GPLv3+
Maintainer     : jrm@FreeBSD.org
WWW            : https://github.com/rizsotto/Bear

root@15amd64-default:~ # bear --verbose -- ls bear_ls_output_freebsd15.txt Until SIGKILL is sent, new process will be spawned indefinitely.

Bear runs as expected on FreeBSD systems built prior to that commit.

root@14amd64-default:~ # uname -a
FreeBSD 14amd64-default 14.0-RC4 FreeBSD 14.0-RC4 amd64

root@14amd64-default:~ # pkg info bear | head -11
bear-3.1.3_4
Name           : bear
Version        : 3.1.3_4
Installed on   : Tue Jan  2 13:38:57 2024 UTC
Origin         : devel/bear
Architecture   : FreeBSD:14:amd64
Prefix         : /usr/local
Categories     : devel
Licenses       : GPLv3+
Maintainer     : jrm@FreeBSD.org
WWW            : https://github.com/rizsotto/Bear

root@14amd64-default:~ # bear --verbose -- ls bear_ls_output_freebsd14.txt

illegalcoding commented 4 months ago

I just upgraded to 14.0-STABLE and I'm getting the same issue, just endless wrappers spawning. If I run with --force-wrapper it seems to run the Makefile and exit, but it doesn't write anything in compile_commands.json.

rizsotto commented 3 months ago

Thanks guys for the reporting... Yes, if the newly introduced execve is causing the issue. (The fact that the posix_spawn is calling execve is the problem for this application.)

The potential workarounds are not easy with my time budget this time... Static linking of the wrapper could fix that. (A lot of work on the build system, which will not be as portable as it is today.) Instead of calling posix_spawn the wrapper should call the execve directly. (Seems like the cheapest solution.)

Using the --force-wapper is the no-code-change workaround. This mode of the interception is more depending on the build system... This page might be helpful to set it up.

Jehops commented 3 days ago

Unfortunately, --force-wrapper doesn't seem to be a viable workaround. Using bear --force-wrapper -- make on a project gives a compile_commands.json that only contains [].

rizsotto commented 3 days ago

I think it depends on the project @Jehops .

Three things have to match: the makefile should call the compiler not with an absolute path, and the compiler should have a matching wrapper (you can create a soft link), and if the compiler name is not recognized you need to register in the config file.

The link I've posted helps this to set up.

If you have a specific problem I can try to help you, but need more details.