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

execinfo.h is not available on MUSL #2397

Open
radare opened this issue Oct 17, 2019 · 13 comments
Open

execinfo.h is not available on MUSL #2397

radare opened this issue Oct 17, 2019 · 13 comments
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: vlib Bugs/feature requests, that are related to the vlib.

Comments

@radare
Copy link
Contributor

radare commented Oct 17, 2019

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 radare added the Bug This tag is applied to issues which reports bugs. label Oct 17, 2019
@unknown-v
Copy link
Contributor

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

@radare
Copy link
Contributor Author

radare commented Oct 19, 2019

FED6CE15-EFF6-4825-9AD5-6ADE24555F1C

@joe-conigliaro
Copy link
Member

@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)

@unknown-v
Copy link
Contributor

@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 https://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
v3.10.2-189-g393dc02e8c [https://dl-cdn.alpinelinux.org/alpine/v3.10/main]
v3.10.2-189-g393dc02e8c [https://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

@radare
Copy link
Contributor Author

radare commented Oct 19, 2019

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
Copy link
Contributor Author

radare commented Oct 19, 2019

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

@unknown-v
Copy link
Contributor

unknown-v commented Oct 19, 2019

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

export VFLAGS="-cc gcc"

@bogen85
Copy link
Member

bogen85 commented Oct 23, 2019

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.

@medvednikov
Copy link
Member

@bogen85 so tcc works with musl with -lexecinfo?

@bogen85
Copy link
Member

bogen85 commented Oct 23, 2019

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

@M4SSD35TRUCT10N M4SSD35TRUCT10N added this to the Beta Release milestone Apr 6, 2020
@M4SSD35TRUCT10N M4SSD35TRUCT10N added Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: vlib Bugs/feature requests, that are related to the vlib. Status: Confirmed This bug has been confirmed to be valid by a contributor. labels Apr 6, 2020
@comcloudway
Copy link

comcloudway commented Dec 6, 2022

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

@ArtemkaKun ArtemkaKun removed this from the Beta Release milestone May 26, 2023
@Brixy
Copy link

Brixy commented Aug 8, 2024

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.

@medvednikov
Copy link
Member

I think we only tested musl builds on alpine.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: vlib Bugs/feature requests, that are related to the vlib.
Projects
None yet
Development

No branches or pull requests

9 participants