Created attachment 14273 [details] binutils-2.39-musl.log Attempt to build binutils-2.39 (enables gprofng by default) fails as: binutils> make all-am binutils> make[5]: Entering directory '/build/binutils-2.39/gprofng/libcollector' binutils> /nix/store/4k23hc0n15afv1nk951vh1c4c3f0yacz-bootstrap-tools/bin/bash ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -U_ASM -I.. -I. -I./../common -I./../src -I./../../include -I../../bfd -I./../.. -Wall -Wno-nonnull-compare -g -O2 -MT libgp_collector_la-gethrtime.lo -MD -MP -MF .deps/libgp_collector_la-gethrtime.Tpo -c -o libgp_collector_la-gethrtime.lo `test -f 'gethrtime.c' || echo './'`gethrtime.c binutils> libtool: compile: gcc -DHAVE_CONFIG_H -I. -U_ASM -I.. -I. -I./../common -I./../src -I./../../include -I../../bfd -I./../.. -Wall -Wno-nonnull-compare -g -O2 -MT libgp_collector_la-gethrtime.lo -MD -MP -MF .deps/libgp_collector_la-gethrtime.Tpo -c gethrtime.c -fPIC -DPIC -o .libs/libgp_collector_la-gethrtime.o binutils> mv -f .deps/libgp_collector_la-gethrtime.Tpo .deps/libgp_collector_la-gethrtime.Plo binutils> /nix/store/4k23hc0n15afv1nk951vh1c4c3f0yacz-bootstrap-tools/bin/bash ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -U_ASM -I.. -I. -I./../common -I./../src -I./../../include -I../../bfd -I./../.. -Wall -Wno-nonnull-compare -g -O2 -MT libgp_collector_la-dispatcher.lo -MD -MP -MF .deps/libgp_collector_la-dispatcher.Tpo -c -o libgp_collector_la-dispatcher.lo `test -f 'dispatcher.c' || echo './'`dispatcher.c binutils> libtool: compile: gcc -DHAVE_CONFIG_H -I. -U_ASM -I.. -I. -I./../common -I./../src -I./../../include -I../../bfd -I./../.. -Wall -Wno-nonnull-compare -g -O2 -MT libgp_collector_la-dispatcher.lo -MD -MP -MF .deps/libgp_collector_la-dispatcher.Tpo -c dispatcher.c -fPIC -DPIC -o .libs/libgp_collector_la-dispatcher.o binutils> In file included from dispatcher.c:35:0: binutils> /nix/store/4k23hc0n15afv1nk951vh1c4c3f0yacz-bootstrap-tools/include-libc/sys/signal.h:1:2: warning: #warning redirecting incorrect #include <sys/signal.h> to <signal.h> [-Wcpp] binutils> #warning redirecting incorrect #include <sys/signal.h> to <signal.h> binutils> ^~~~~~~ binutils> In file included from dispatcher.c:30:0: binutils> ./../src/collector_module.h:78:13: error: duplicate member ‘pwrite’ binutils> ssize_t (*pwrite64)(); binutils> ^ binutils> dispatcher.c: In function ‘collector_timer_create’: binutils> dispatcher.c:575:24: error: ‘SIGEV_THREAD_ID’ undeclared (first use in this function); did you mean ‘SIGEV_THREAD’? binutils> sigev.sigev_notify = SIGEV_THREAD_ID | SIGEV_SIGNAL; binutils> ^~~~~~~~~~~~~~~ binutils> SIGEV_THREAD
SIGEV_THREAD_ID is defined in /usr/include/bits/sigevent-consts.h on my OL8: % grep -ns SIGEV_THREAD_ID /usr/include/*/* /usr/include/asm-generic/siginfo.h:409:#define SIGEV_THREAD_ID 4 /* deliver to thread */ /usr/include/bits/sigevent-consts.h:36: SIGEV_THREAD_ID = 4 /* Send signal to specific thread. /usr/include/bits/sigevent-consts.h:38:#define SIGEV_THREAD_ID SIGEV_THREAD_ID What is an output of `grep -ns SIGEV_THREAD_ID /usr/include/*/*` on your build machine ? Also what is an output of `grep -ns pwrite /usr/include/*` on your build machine ? Thank you, -Vladimir
(In reply to Vladimir Mezentsev from comment #1) > SIGEV_THREAD_ID is defined in /usr/include/bits/sigevent-consts.h on my OL8: > % grep -ns SIGEV_THREAD_ID /usr/include/*/* > /usr/include/asm-generic/siginfo.h:409:#define SIGEV_THREAD_ID 4 /* deliver > to thread */ > /usr/include/bits/sigevent-consts.h:36: SIGEV_THREAD_ID = 4 /* Send signal > to specific thread. > /usr/include/bits/sigevent-consts.h:38:#define SIGEV_THREAD_ID > SIGEV_THREAD_ID > > > What is an output of `grep -ns SIGEV_THREAD_ID /usr/include/*/*` on your > build machine ? musl is an alternative implementation of libc for linux. It does not try to be fully compatible to GNU libc, but mostly targets POSIX. Thus a few glibc-specific things are missing and some things are in different locations. SIGEV_THREAD_ID is defined in http://git.musl-libc.org/cgit/musl/tree/include/signal.h#n205: include/signal.h:#define SIGEV_THREAD_ID 4 > Also what is an output of `grep -ns pwrite /usr/include/*` on your build > machine ? 'pwrite' is defined in unistd.h http://git.musl-libc.org/cgit/musl/tree/include/unistd.h#n204 But there is a catch: pwrite and pwrite64 are not different symbols and are macro aliases: ssize_t pwrite(int, const void *, size_t, off_t); #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) #define pwrite64 pwrite #endif Also, `dlvsym()` does not exist on musl, and GLIBC-specific symbol versions are not available, thus things like the below don't work: ptr = dlvsym (dlflag, "pthread_mutex_unlock", "GLIBC_2.0");
I cloned git://git.musl-libc.org/musl, built and installed. I fixed the build problems in gprofng/libcollector. But I see that only musl-gcc is installed. How can I install the musl c++ compiler ? musl-gcc can build the *.cc files but cannot find the header files like: #include <new> #include <set> #include <sstream> #include <istream> #include <iostream>
Yeah, getting musl toolchain is trickier than glibc's. I suggest using a chroot (or equivalent) of linux distribution that already supports it. I'm personally using nixpkgs. More conventional FHS-style distribution using musl would be adelie. Full session to reproduce the failure there: # Get smallest rootfs from https://www.adelielinux.org/download/ (10MB), # unpack and and enter the chroot: $ mkdir /tmp/repro && cd /tmp/repro $ wget https://distfiles.adelielinux.org/adelie/1.0/iso/rc2/adelie-rootfs-mini-x86_64-1.0-rc2.txz $ sudo tar xf adelie-rootfs-mini-x86_64-1.0-rc2.txz $ sudo systemd-nspawn --directory=. # Install bash (default shell is a bit clunky), # and build tools, fetch binutils and build it: $$ /sbin/apk add bash && bash $$ /sbin/apk add build-tools m4 bison flex gmp-dev texinfo $$ git clone --depth 1 https://sourceware.org/git/binutils-gdb.git $$ cd binutils-gdb/ $$ ./configure && make ... In file included from dispatcher.c:35: /usr/include/sys/signal.h:1:2: warning: #warning redirecting incorrect #include <sys/signal.h> to <signal.h> [-Wcpp] #warning redirecting incorrect #include <sys/signal.h> to <signal.h> ^~~~~~~ In file included from dispatcher.c:30: ./../src/collector_module.h:78:13: error: duplicate member ‘pwrite’ ssize_t (*pwrite64)(); ^~~~~~~~ It's a fully working basic c++ development environment: $$ printf "#include <iostream>\nint main() { std::cout << \"yay\" << std::endl; }" | g++ -x c++ - -o a && ./a yay Hope that helps.
You can also try, per #musl on IRC's recommendations, http://musl.cc/ which is designed for this sort of thing.
The master branch has been updated by Vladimir Mezentsev <vmezents@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=fe39ffdc202f04397f31557f17170b40bc42b77a commit fe39ffdc202f04397f31557f17170b40bc42b77a Author: Vladimir Mezentsev <vladimir.mezentsev@oracle.com> Date: Wed Sep 14 01:11:45 2022 -0700 gprofng: fix build issues on musl gprofng/ChangeLog 2022-09-14 Vladimir Mezentsev <vladimir.mezentsev@oracle.com> PR gprofng/29477 * configure.ac: Set __MUSL_LIBC. * configure: Rebuild. * common/config.h.in: Rebuild. * src/collector_module.h: Fix compiler errors because mmap64, open64, pwrite64 are macros and getcontext() is absent on musl. * libcollector/collector.c: Likewise. * libcollector/hwprofile.c: Likewise. * libcollector/iolib.c: Likewise. * libcollector/libcol_util.c: Likewise. * libcollector/linetrace.c: Likewise. * libcollector/memmgr.c: Likewise. * libcollector/profile.c: Likewise. * libcollector/unwind.c: Likewise. * libcollector/dispatcher.c: Likewise. * src/Experiment.cc: Likewise. * libcollector/collector.h: Use dlsym() because dlvsym() is not defined on musl. * libcollector/iotrace.c: Remove interposition of versioned functions. * libcollector/mmaptrace.c: Likewise. * libcollector/libcol_util.h: Fix -Wint-to-pointer-cast warnings. * libcollector/jprofile.c: Likewise. * libcollector/synctrace.c: Include "collector.h". * src/Print.cc: Use get_basename() because basename() is not defined on musl. * common/hwcdrv.c: Fix -Wformat= warnings.
I fixed build issues. But the run time problem is not fixed. getcontext() is absent in libc on musl. Why ?
Good question. Looking around it looks like musl elected not to implement it: https://www.openwall.com/lists/musl/2018/01/29/2