Menu

#6 Compilation with musl fails

v1.0 (example)
pending
None
5
2022-02-25
2022-02-09
ConiKost
No

If serdisplib is being compiled with musl (a glibc replacement), compilation will fail.

make -j2 
gmake[1]: Entering directory '/var/tmp/portage/dev-libs/serdisplib-2.02-r1/work/serdisplib-2.02/src'
x86_64-gentoo-linux-musl-gcc -I../include -I.. -O2 -pipe -march=x86-64 -frecord-gcc-switches -fno-diagnostics-color -fmessage-length=0  -I/usr/include/libusb-1.0  -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -Wall -Wpedantic -Wextra -fPIC  -c serdisp_fctptr.c
x86_64-gentoo-linux-musl-gcc -I../include -I.. -O2 -pipe -march=x86-64 -frecord-gcc-switches -fno-diagnostics-color -fmessage-length=0  -I/usr/include/libusb-1.0  -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -Wall -Wpedantic -Wextra -fPIC  -c serdisp_control.c
In file included from serdisp_control.c:43:
../include/serdisplib/serdisp_gpevents.h:75:18: error: expected identifier or '(' before 'unsigned'
   75 |   #define ushort unsigned short
      |                  ^~~~~~~~
serdisp_fctptr.c: In function 'SDFCTPTR_init':
serdisp_fctptr.c:890:38: warning: cast between incompatible function types from 'int (*)(const struct sockaddr * restrict,  socklen_t,  char * restrict,  socklen_t,  char * restrict,  socklen_t,  int)' {aka 'int (*)(const struct sockaddr * restrict,  unsigned int,  char * restrict,  unsigned int,  char * restrict,  unsigned int,  int)'} to 'int (*)(const struct sockaddr *, socklen_t,  char *, size_t,  char *, size_t,  int)' {aka 'int (*)(const struct sockaddr *, unsigned int,  char *, long unsigned int,  char *, long unsigned int,  int)'} [-Wcast-function-type[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wcast-function-type]]
  890 |     fp_getnameinfo                 = (int(*)(const struct sockaddr*, socklen_t, char*, size_t, char *, size_t, int)) getnameinfo;
      |                                      ^
x86_64-gentoo-linux-musl-gcc -I../include -I.. -O2 -pipe -march=x86-64 -frecord-gcc-switches -fno-diagnostics-color -fmessage-length=0  -I/usr/include/libusb-1.0  -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -Wall -Wpedantic -Wextra -fPIC  -c serdisp_connect.c
gmake[1]: *** [Makefile:184: serdisp_control.o] Error 1
gmake[1]: *** Waiting for unfinished jobs....
serdisp_connect.c: In function 'SDCONN_open':
serdisp_connect.c:475:27: warning: overflow in conversion from 'long unsigned int' to 'int' changes value from '2147577987' to '-2147389309' [-Woverflow[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Woverflow]]
  475 |       if (ioctl(sdcd->fd, PPRCONTROL, &mode) == -1) {
      |                           ^~~~~~~~~~
serdisp_connect.c:601:24: warning: overflow in conversion from 'long unsigned int' to 'int' changes value from '2150154243' to '-2144813053' [-Woverflow[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Woverflow]]
  601 |     if(ioctl(sdcd->fd, IOW_GETINFO, &info) < 0) {
      |                        ^~~~~~~~~~~
serdisp_connect.c: In function 'SDCONN_read':
serdisp_connect.c:1295:29: warning: overflow in conversion from 'long unsigned int' to 'int' changes value from '2147577989' to '-2147389307' [-Woverflow[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Woverflow]]
 1295 |         if (ioctl(sdcd->fd, PPRDATA, &t_data) < 0) {  /* read data-byte */
      |                             ^~~~~~~
serdisp_connect.c:1312:29: warning: overflow in conversion from 'long unsigned int' to 'int' changes value from '2147577987' to '-2147389309' [-Woverflow[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Woverflow]]
 1312 |         if (ioctl(sdcd->fd, PPRCONTROL, &t_data) < 0) {
      |                             ^~~~~~~~~~
serdisp_connect.c: In function 'SDCONN_commit':
serdisp_connect.c:1488:24: warning: overflow in conversion from 'long unsigned int' to 'int' changes value from '3222030345' to '-1072936951' [-Woverflow[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Woverflow]]
 1488 |     if(ioctl(sdcd->fd, HIDIOCGREPORTINFO, &rinfo) < 0) {
      |                        ^~~~~~~~~~~~~~~~~
serdisp_connect.c:1499:23: warning: overflow in conversion from 'long unsigned int' to 'int' changes value from '3222816781' to '-1072150515' [-Woverflow[https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Woverflow]]
 1499 |       ioctl(sdcd->fd, HIDIOCGUCODE, &uref);
      |                       ^~~~~~~~~~~~

Discussion

  • Wolfgang Astleitner

    Hi!
    Seems to be more like a compiler thing.
    Could you please try changing the following in serdisp_gpevents.h:

    change

    define ushort unsigned short

    to

    define ushort (unsigned short)

    and the same for

    define byte unsigned char

    to

    define byte (unsigned char)

    but as far as i know this is valid C and shouldn't cause an error. but give it a try and let me know if it works.

    as an alternative you could also try

    define ushort uint16_t

    define byte uint8_t

    (and i should get rid of ushort and byte in my code and stick to uint16_t/uint8_t ...)

    the other messages are warnings, and these are because ioctl in musl seems to adhere to posix-standard (ioctl (int fd, int request, ...) vs. linux / sys/ioctl.h: ioctl(int fd, unsigned long request, ...)

     
  • ConiKost

    ConiKost - 2022-02-10

    Hi!
    Changing did not help. But with the help of another developer, he was able to help me to solve it on musl.

    Proposed patch, which fixed the compilation: https://gist.github.com/floppym/689f380b8f1e8bd08207c8c7aa18038f

    Cheers
    Conrad

     
  • Wolfgang Astleitner

    i don't get it.
    i can't reproduce this error. neither with 'standard' gcc nor with musl-gcc:

    my simple test (test.c): - the / / are used so that the sourceforge comment-editor does not generate huge lines when starting with # ...

    / / #include <stdio.h>
    / / #include <inttypes.h>
    / / #include <stdint.h></stdint.h></inttypes.h></stdio.h>

    / / #define ushort unsigned short

    int main(void) {
    ushort test = 0;

    printf("test: %d\n", test);
    }

    this one compiled with standard gcc:
    gcc -O2 -pipe -march=x86-64 -frecord-gcc-switches -D_GNU_SOURCE=1 -D_REENTRANT -Wall -Wpedantic -Wextra -o test test.c
    or musl-gcc
    /usr/bin/musl-gcc -O2 -pipe -march=x86-64 -frecord-gcc-switches -D_GNU_SOURCE=1 -D_REENTRANT -Wall -Wpedantic -Wextra -o test test.c

    no warning, no error (well, musl-gcc at fedora is just gcc with another spec)

    both run on fedora 34
    version of gcc: gcc (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)

    could you please try compiling the short code example above with your musl-gcc?
    what is the version of this musl-gcc? (musl-gcc --version)

    thanks in advance.

     
  • Wolfgang Astleitner

    note: the stars have been removed by the sourceforge-editor (should have been starting and closing comments ...)

     

    Last edit: Wolfgang Astleitner 2022-02-21
  • Wolfgang Astleitner

    • status: open --> pending
    • assigned_to: Wolfgang Astleitner
     
  • ConiKost

    ConiKost - 2022-02-25

    Hi!
    I was able successfully to compile your snippet on my musl system.

    But: I digged further and noticed, that you can only get the compile failure on musl with, when setting '--disable-pthread'. With a glibc system, this works just fine.

    Cheers
    Conrad

     

    Last edit: ConiKost 2022-02-25

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.