Bug 29477 - Build failure on musl: collector_module.h:78:13: error: duplicate member ‘pwrite’
Summary: Build failure on musl: collector_module.h:78:13: error: duplicate member ‘pwr...
Alias: None
Product: binutils
Classification: Unclassified
Component: gprofng (show other bugs)
Version: 2.39
: P3 normal
Target Milestone: ---
Assignee: Vladimir Mezentsev
Depends on:
Reported: 2022-08-12 08:18 UTC by Sergei Trofimovich
Modified: 2023-12-21 06:40 UTC (History)
4 users (show)

See Also:
Last reconfirmed: 2022-08-18 00:00:00

binutils-2.39-musl.log (15.92 KB, text/x-log)
2022-08-12 08:18 UTC, Sergei Trofimovich

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Trofimovich 2022-08-12 08:18:34 UTC
Created attachment 14273 [details]

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
Comment 1 Vladimir Mezentsev 2022-08-18 19:37:16 UTC
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,
Comment 2 Sergei Trofimovich 2022-08-18 20:44:32 UTC
(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
>  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

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");
Comment 3 Vladimir Mezentsev 2022-09-02 02:39:43 UTC
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>
Comment 4 Sergei Trofimovich 2022-09-02 08:02:53 UTC
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

Hope that helps.
Comment 5 Sam James 2022-09-06 19:20:09 UTC
You can also try, per #musl on IRC's recommendations, http://musl.cc/ which is designed for this sort of thing.
Comment 6 Sourceware Commits 2022-09-15 01:44:06 UTC
The master branch has been updated by Vladimir Mezentsev <vmezents@sourceware.org>:


commit fe39ffdc202f04397f31557f17170b40bc42b77a
Author: Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
Date:   Wed Sep 14 01:11:45 2022 -0700

    gprofng: fix build issues on musl
    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.
Comment 7 Vladimir Mezentsev 2022-09-15 01:55:03 UTC
I fixed build issues.
But the run time problem is not fixed.
getcontext() is absent in libc on musl. Why ?
Comment 8 Sergei Trofimovich 2022-09-15 06:36:19 UTC
Good question. Looking around it looks like musl elected not to implement it: https://www.openwall.com/lists/musl/2018/01/29/2