Compiling master from source on alpine fails with undefined reference to backtrace

I’m using this docker image with latest master (as well as v1.3.1) https://github.com/stephwag/pytorch-alpine/blob/master/Dockerfile

According to what I’ve found elsewhere, libexecinfo-dev provides /usr/lib/libexecinfo.so which provides backtrace, but it doesn’t seem to find it.

Here is the error I am seeing:

[ 36%] Linking CXX executable ../../bin/c10_tempfile_test
/usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../../lib/libc10.so: undefined reference to `backtrace'
/usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../../lib/libc10.so: undefined reference to `backtrace_symbols'
collect2: error: ld returned 1 exit status
make[2]: *** [c10/test/CMakeFiles/c10_tempfile_test.dir/build.make:89: bin/c10_tempfile_test] Error 1
make[1]: *** [CMakeFiles/Makefile2:2158: c10/test/CMakeFiles/c10_tempfile_test.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 36%] Building CXX object third_party/ideep/mkl-dnn/src/CMakeFiles/mkldnn.dir/cpu/gemm/s8x8s32/ref_gemm_s8x8s32.cpp.o
[ 36%] Generating src/x86_64-fma/blas/shdotxf.py.o
[ 37%] Linking CXX executable ../../bin/c10_typeid_test
/usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../../lib/libc10.so: undefined reference to `backtrace'
/usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: ../../lib/libc10.so: undefined reference to `backtrace_symbols'
collect2: error: ld returned 1 exit status
make[2]: *** [c10/test/CMakeFiles/c10_typeid_test.dir/build.make:89: bin/c10_typeid_test] Error 1
make[1]: *** [CMakeFiles/Makefile2:2118: c10/test/CMakeFiles/c10_typeid_test.dir/all] Error 2

From that google search: https://github.com/openalpr/openalpr/issues/566 it seems like musl does not provide the backtrace function. So I guess you will have to use glibc to be able to compute pytorch.

@gchanan is musl something we would like to add support for in the future?

My understanding is that libexecinfo-dev provides this library (https://www.freshports.org/devel/libexecinfo). It doesn’t seem to link it correctly, though.

Is our build system even trying to link to it? In the sense that we don’t need it with glibc.

Maybe try to LD_PRELOAD it to see if this is really the issue?

Sure, I’ll try LD_PRELOAD and see if that links it

1 Like

It won’t link it, but it will make these symbols available :smiley:

Got it - thanks! :slight_smile:

hmm, same error with LD_PRELOAD=/usr/lib/libexecinfo.so python setup.py install

1 Like

Were you able to solve this?

Unfortunately I was not able to resolve it. I ended up just using a non-alpine image.

If it’s not a ton of trouble, I would really appreciate being able to build PyTorch for Alpine.

execinfo is only used in 1-2 files so you could comment out the header and set SUPPORTS_BACKTRACE to 0 to remove it. worked for me on alpine and 1.4