v icon indicating copy to clipboard operation
v copied to clipboard

execinfo.h is not available on MUSL

Open radare opened this issue 6 years ago • 13 comments

V version: OS:

What did you do?

try to build v for musl,

What did you expect to see?

a working build

What did you see instead?

a failure because the current ifndef is only for BIONIC

in fact execinfo is a gnuism, so it should be guarded like this:

#if (__linux__ && __GNU_LIBRARY__) || defined(NETBSD_WITH_BACKTRACE) || \
  defined(FREEBSD_WITH_BACKTRACE) || __DragonFly__
# include <execinfo.h>
#endif

IMG_1046

radare avatar Oct 17 '19 18:10 radare

alpineLinux has libexecinfo don´t know about other musl based distros.

unknown-v avatar Oct 18 '19 14:10 unknown-v

FED6CE15-EFF6-4825-9AD5-6ADE24555F1C

radare avatar Oct 19 '19 00:10 radare

@radare Good point. Aldo the current backtrace implementation rely's on functions from it, we should have a minimal or different backtrace implementation when it isn't available (or no backtrace in that case)

joe-conigliaro avatar Oct 19 '19 00:10 joe-conigliaro

@radare

Step 1/12 : FROM alpine:3.10.2
 ---> 961769676411
Step 2/12 : RUN         apk update apk upgrade &&       apk add --update gcc make       git musl-dev libexecinfo-dev    &&      mkdir -p 
/opt/v && cd /opt/v &&  git clone --quiet https://github.com/vlang/v .
 ---> Running in d45130455ecd
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
v3.10.2-189-g393dc02e8c [http://dl-cdn.alpinelinux.org/alpine/v3.10/main]
v3.10.2-189-g393dc02e8c [http://dl-cdn.alpinelinux.org/alpine/v3.10/community]
OK: 10337 distinct packages available
(1/20) Installing binutils (2.32-r0)
Step 3/12 : WORKDIR /opt/v
 ---> Running in 912eb8788caa
Removing intermediate container 912eb8788caa
 ---> 65d6a05e7ec2
Step 4/12 : RUN CC=gcc LDFLAGS=-lexecinfo make MAKE_VERBOSE=1
 ---> Running in 7b52a241035b
rm -rf vc/
git clone --depth 1 --quiet https://github.com/vlang/vc
rm -rf /var/tmp/tcc/
git clone --depth 1 --quiet https://github.com/vlang/tccbin /var/tmp/tcc
gcc -std=gnu11 -w -o v vc/v.c -lexecinfo -lm
rm -rf vc/
V has been successfully built
Removing intermediate container 7b52a241035b

unknown-v avatar Oct 19 '19 19:10 unknown-v

Ok i manage to compile it by adding the LDFLAGS=-lexecinfo env var but then it fails to do anything because:

  • theres no way to add -lexecinfo when compiling with v (theres -cflags but not -ldflags)
  • tcc fails hard. But using -cc gcc seems to work, is there a way to force this at compile time? May be better to fix tcc anyway

B898D1D3-2766-4C8C-A5F2-3E22EAB3F1E0

radare avatar Oct 19 '19 22:10 radare

3670BD72-625D-4CB9-AAFF-499D52BC1494 023109BF-C7ED-46EA-A311-0CCEDD3905ED

radare avatar Oct 19 '19 22:10 radare

tcc fails hard. But using -cc gcc seems to work, is there a way to force this at compile time?

export VFLAGS="-cc gcc"

unknown-v avatar Oct 19 '19 23:10 unknown-v

I got tcc to work by replacing what what was put in tmp.

$ cat /var/tmp/tcc/bin/tcc 
#!/usr/bin/env bash

tcc $@ -lexecinfo

What was put in tmp for tcc by the v update process did not work for me anyways on alpine.

bogen85 avatar Oct 23 '19 06:10 bogen85

@bogen85 so tcc works with musl with -lexecinfo?

medvednikov avatar Oct 23 '19 08:10 medvednikov

@medvednikov well, compiles and links on alpine with -lexecinfo... (and a lot works) but backtrace does not... See #2508

bogen85 avatar Oct 23 '19 08:10 bogen85

alpineLinux has libexecinfo don´t know about other musl based distros.

With Alpine Linux 3.17, they apparently removed libexecinfo-dev

Manually building and installing https://github.com/ronchaine/libexecinfo fixes the execinfo.h error though

comcloudway avatar Dec 06 '22 11:12 comcloudway

I just tried to compile V on chimera linux and got the following error:

clang -g -std=gnu11 -w -o v1 vc/v.c -lm -lexecinfo -lpthread 
ld: error: unable to find library -lexecinfo
clang: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

After compiling and installing the libexecinfo library (repo has been archived!) the error message when compiling V changed to

cc -pipe -g -std=gnu11 -w -o v1 vc/v.c -lm -lexecinfo -lpthread 
./v1 -no-parallel -o v2 -cc gcc cmd/v
================== C compilation error (from gcc): ==============
cc: /tmp/v_1000/v2.01J4S9AQENEY9DHCEQC23JYGSS.tmp.c:21879:19: error: call to undeclared function 'backtrace'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
cc:  21879 |                                 int nr_ptrs = backtrace(&buffer[0], 100);
cc:        |                                               ^
cc: /tmp/v_1000/v2.01J4S9AQENEY9DHCEQC23JYGSS.tmp.c:21886:23: error: call to undeclared function 'backtrace_symbols'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
cc:  21886 |                                 char** csymbols = backtrace_symbols(((voidptr)(&buffer[v_fixed_index(skipframes, 100)])), nr_actual_frames);
cc:        |                                                   ^
cc: /tmp/v_1000/v2.01J4S9AQENEY9DHCEQC23JYGSS.tmp.c:21886:12: error: incompatible integer to pointer conversion initializing 'char **' with an expression of type 'int' [-Wint-conversion]
cc:  21886 |                                 char** csymbols = backtrace_symbols(((voidptr)(&buffer[v_fixed_index(skipframes, 100)])), nr_actual_frames);
cc:        |                                        ^          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc: /tmp/v_1000/v2.01J4S9AQENEY9DHCEQC23JYGSS.tmp.c:29920:4: warning: expression result unused [-Wunused-value]
cc:  29920 |   (*(string*)_t3.data);
cc:        |    ^~~~~~~~~~~~~~~~~~
... (the original output was 244 lines long, and was truncated to 12 lines)
=================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).
builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .
*** Error code 1

Does anyone have any other ideas on how to get this to work reliably on a modern musl based distro? Thank you very much!

P.S.: Compiling V on alpine works.

Brixy avatar Aug 08 '24 15:08 Brixy

I think we only tested musl builds on alpine.

execinfo is a common source of issues, would be best to avoid this dep.

medvednikov avatar Aug 09 '24 10:08 medvednikov

Hello guys,

I just tried again to compile and run V on Chimera Linux, and it working perfectly now. But I don't know whether anything relevant in V, execinfo or Chimera has changed.

doas apk add gmake clang musl-devel

make

./v

>> Welcome to the V REPL ...

Brixy avatar Dec 27 '24 22:12 Brixy