vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.84k stars 2.17k forks source link

libbacktrace not supported on OpenBSD #22261

Open lcheylus opened 2 months ago

lcheylus commented 2 months ago

Describe the bug

libbacktrace is not supported on OpenBSD => error when building V code with -d use_libbacktrace flag.

Reproduction Steps

Expected Behavior

No error when building V code with -d use_libbacktrace on OpenBSD.

Current Behavior

Error when building v-analyzer on OpenBSD:

$ ~/dev/vlang.git/v build.vsh
Building v-analyzer at commit: 0086b35, build time: 2024-09-19 15:58:49 ...
✓ Prepared output directory
Building v-analyzer in debug mode, using: "/home/fox/dev/vlang.git/v" "/home/fox/dev/v-analyzer.git" -o "./bin/v-analyzer" -no-parallel   -g -d use_libbacktrace
To build in release mode, run v build.vsh release
Release mode is recommended for production use. At runtime, it is about 30-40% faster than debug mode.
[ERROR] Failed to build v-analyzer
failed thirdparty object build cmd:
'/home/fox/dev/vlang.git/thirdparty/tcc/tcc.exe' -std=c99 -D_DEFAULT_SOURCE   -g  -fPIC -D GC_BUILTIN_ATOMIC=1 -D GC_THREADS=1 -I "/usr/local/include" -I "/home/fox/dev/vlang.git/thirdparty/libbacktrace" -o '/home/fox/.vmodules/cache/c2/c260b323385da074280a69d697f32fd6.module.builtin.o' -c '/home/fox/dev/vlang.git/thirdparty/libbacktrace/backtrace.c'
builder error: In file included from /home/fox/dev/vlang.git/thirdparty/libbacktrace/backtrace.c:103:
/home/fox/dev/vlang.git/thirdparty/libbacktrace/base.c:3778: error: 'KERN_PROC_PATHNAME' undeclared

Possible Solution

In thirdparty/libbacktrace/base.c, symbol KERN_PROC_PATHNAME used by syscall is unknown on OpenBSD.

It's a known issue on OpenBSD => devs don't want implement KERN_PROC_PATHNAME for syscall to locate the current executable path. :( See this response from Theo on OpenBSD misc mailing-list https://marc.info/?l=openbsd-misc&m=144987773230417&w=2

An alternate solution is to use whereami library on OpenBSD to fix this issue in libbacktrace => https://github.com/gpakosz/whereami

I will try to reproduce this problem on OpenBSD with the current version of libbacktrace and to create a similar issue upstream.

After fix and merge upstream, I propose to update libbacktrace in Vlang sources (using amalgamation). Do you agree?

Additional Information/Context

No response

V version

./v version V 0.4.7 9a0f4d8

Environment details (OS name and version, etc.)

V full version: V 0.4.7 63957f2.9a0f4d8 OS: openbsd, 7.6, GENERIC.MP#312 Processor: 2 cpus, 64bit, little endian

getwd: /home/fox/dev/vlang.git vexe: /home/fox/dev/vlang.git/v vexe mtime: 2024-09-19 13:51:18

vroot: OK, value: /home/fox/dev/vlang.git VMODULES: OK, value: /home/fox/.vmodules VTMP: OK, value: /tmp/v_1000

Git version: git version 2.46.1 Git vroot status: weekly.2024.37-30-g9a0f4d84 .git/config present: true

CC version: OpenBSD clang version 16.0.6 thirdparty/tcc status: thirdparty-openbsd-amd64 8205cc59

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

lcheylus commented 2 months ago

Simple test to generate error when using libbacktrace on OpenBSD/amd64:

./v -d use_libbacktrace run ~/tmp/hello_world.v
failed thirdparty object build cmd:
'/home/fox/dev/vlang.git/thirdparty/tcc/tcc.exe' -std=c99 -D_DEFAULT_SOURCE    -fPIC -D GC_BUILTIN_ATOMIC=1 -D GC_THREADS=1 -I "/usr/local/include" -I "/home/fox/dev/vlang.git/thirdparty/libbacktrace" -o '/home/fox/.vmodules/cache/61/61fc8f5bdfdffed4bcf6b1b1604f5a61.module.builtin.o' -c '/home/fox/dev/vlang.git/thirdparty/libbacktrace/backtrace.c'
builder error: In file included from /home/fox/dev/vlang.git/thirdparty/libbacktrace/backtrace.c:103:
/home/fox/dev/vlang.git/thirdparty/libbacktrace/base.c:3778: error: 'KERN_PROC_PATHNAME' undeclared

=> error with KERN_PROC_PATHNAME' not defined on OpenBSD

spytheman commented 2 months ago

After fix and merge upstream, I propose to update libbacktrace in Vlang sources (using amalgamation). Do you agree?

Yes, that will be nice.

lcheylus commented 2 months ago

After fix and merge upstream, I propose to update libbacktrace in Vlang sources (using amalgamation). Do you agree?

Yes, that will be nice.

OK, I have created a specific issue #22268 to track this update of thirparty/libbacktrace sources. This issue is focused on OpenBSD support of libbacktrace.