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

Version 0.0.95 fails to compile on FreeBSD #105

Closed
ehaupt opened this issue Jan 26, 2024 · 11 comments
Closed

Version 0.0.95 fails to compile on FreeBSD #105

ehaupt opened this issue Jan 26, 2024 · 11 comments

Comments

@ehaupt
Copy link
Contributor

ehaupt commented Jan 26, 2024

Trying to compile version 0.0.95 I get:

cc -o gbsinfo gbsinfo.o libgbs.a -lintl -fstack-protector-strong -L/usr/local/lib  -lz -Wl,-z,relro -Wl,-z,now -pie -fstack-clash-protection -lm
In file included from plugout_devdsp.c:20:
/usr/include/sys/soundcard.h:243:5: error: unknown type name 'u_long'; did you mean 'long'?
    u_long      play_rate;      /* sampling rate                        */
    ^  
/usr/include/sys/soundcard.h:244:5: error: unknown type name 'u_long'; did you mean 'long'?
    u_long      rec_rate;       /* sampling rate                        */
    ^  
/usr/include/sys/soundcard.h:245:5: error: unknown type name 'u_long'; did you mean 'long'?
    u_long      play_format;    /* everything describing the format     */
    ^ 
/usr/include/sys/soundcard.h:246:5: error: unknown type name 'u_long'; did you mean 'long'?
    u_long      rec_format;     /* everything describing the format     */
    ^
/usr/include/sys/soundcard.h:256:5: error: unknown type name 'u_char'; did you mean 'char'?
    u_char      subdev; /* which output                         */
    ^
/usr/include/sys/soundcard.h:257:5: error: unknown type name 'u_char'; did you mean 'char'?
    u_char      line;   /* which input                          */
    ^
/usr/include/sys/soundcard.h:258:5: error: unknown type name 'u_char'; did you mean 'char'?
    u_char      left,right; /* volumes, 0..255, 0 = mute        */
    ^
/usr/include/sys/soundcard.h:297:5: error: unknown type name 'u_long'; did you mean 'long'?
    u_long      rate_min, rate_max;     /* min-max sampling rate */
    ^
/usr/include/sys/soundcard.h:298:5: error: unknown type name 'u_long'; did you mean 'long'?
    u_long      formats;
    ^
/usr/include/sys/soundcard.h:299:5: error: unknown type name 'u_long'; did you mean 'long'?
    u_long      bufsize; /* DMA buffer size */  
    ^
/usr/include/sys/soundcard.h:300:5: error: unknown type name 'u_long'; did you mean 'long'?
    u_long      mixers; /* bitmap of available mixers */
    ^
/usr/include/sys/soundcard.h:301:5: error: unknown type name 'u_long'; did you mean 'long'?
    u_long      inputs; /* bitmap of available inputs (per mixer) */
    ^
/usr/include/sys/soundcard.h:302:5: error: unknown type name 'u_short'; did you mean 'short'?
    u_short     left, right;    /* how many levels are supported */
    ^
/usr/include/sys/soundcard.h:337:2: error: unknown type name 'u_char'; did you mean 'char'?
        u_char arr[8];
        ^
/usr/include/sys/soundcard.h:381:2: error: unknown type name 'u_long'; did you mean 'long'?
        u_long mode;
        ^
/usr/include/sys/soundcard.h:419:2: error: unknown type name 'u_int'
        u_int base_freq;
        ^
/usr/include/sys/soundcard.h:420:2: error: unknown type name 'u_long'; did you mean 'long'?
        u_long base_note;
        ^
/usr/include/sys/soundcard.h:421:2: error: unknown type name 'u_long'; did you mean 'long'?
        u_long high_note;
        ^
/usr/include/sys/soundcard.h:422:2: error: unknown type name 'u_long'; did you mean 'long'?
        u_long low_note;
        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]

Including <sys/types.h> does not help.

Full build log

@mmitch
Copy link
Owner

mmitch commented Jan 27, 2024

Through some blind prodding I got it to compile:
I've added -D__BSD_VISIBLE=1 manually to the EXTRA_CFLAGS in config.mk after I ran the configure script.

I don't know if gbsplay really works that way, because I only have a remote shell account and can't test it properly.

We'll then have to find out how to set that flag automatically - or even better, what to do so we don't have to set it at all.
I've found this bug report kcat/openal-soft#4 that mentions some flags that should not be set or types like u_long and friends will become unavailable.

I think we need some BSD expertise here.

@ehaupt
Copy link
Contributor Author

ehaupt commented Jan 27, 2024

Through some blind prodding I got it to compile:
I've added -D__BSD_VISIBLE=1 manually to the EXTRA_CFLAGS in config.mk after I ran the configure script.

That worked. I'll further test the functionality.

@ehaupt
Copy link
Contributor Author

ehaupt commented Jan 27, 2024

From what I can tell, gbsplay works as expected. I was able to successfully play the nightmode.gbs sample.

ranma added a commit that referenced this issue Jan 27, 2024
@ehaupt
Copy link
Contributor Author

ehaupt commented Jan 27, 2024

Unfortunately dfa1f23 didn't solve the issue.

See:
curl https://critical.ch/people/gbsplay-issue-105/typescript-noextraflags.txt

Adding -D__BSD_VISIBLE=1 to CFLAGS is still required.

See:
curl https://critical.ch/people/gbsplay-issue-105/typescript-extraflags.txt

@mmitch
Copy link
Owner

mmitch commented Jan 28, 2024

I've tried to make a minimal broken example that we can include in our configure script to eg. detect if using sys/soundcard.h needs to have __BSD_VISIBLE set to true.

Unfortunately I could not get an example that does not compile. This compiles cleanly when just called as cc foo.c:

#include <sys/soundcard.h>
#include <stdio.h>
int main(int argc, char **argv) {
        snd_capabilities capabilites;  
        printf("%ld\n", sizeof(capabilites));
        return 0;
}

The snd_capabilites struct contains 5 u_longs and 1 u_short.
So it seems that our other compile flags somehow play into this, this needs further testing.

I have also found out that sys/soundcard.h contains multiple sound systems: The basic OSS /dev/dsp interface as well as a new FreeBSD AIO interface. Only the AIO interface uses the u_* types so theoretically we would be fine if the header file was split into two…
Apart from https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=de5df6489b6b425b8c626a7e524808ef6dc277ba I did not find any real documentation on how to use AIO yet.
With more information we could write a FreeBSD specific AIO audio driver, just like DirectSound for Windows. But without fixing the compile problems this would not help us anyway.

@mmitch
Copy link
Owner

mmitch commented Jan 28, 2024

I have bisected the code and found the culprit:

Commit fad6a3e introduces the POSIX-enablement flags

GBSCFLAGS  := -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=200809L

which seem to disable __BSD_VISIBLE.

@mmitch
Copy link
Owner

mmitch commented Jan 28, 2024

We now have a CI pipeline that is able to reproduce this very bug and thus fails 😉
https://github.com/mmitch/gbsplay/actions?query=workflow%3A%22FreeBSD+Build%22

@ehaupt
Copy link
Contributor Author

ehaupt commented Jan 29, 2024

@mmitch Big thanks for sorting out the FreeBSD issue with GBSplay. Really appreciate your effort! Having a FreeBSD pipeline is an awesome bonus!

mmitch added a commit that referenced this issue Jan 30, 2024
The FreeBSD build was broken because special typedefs like `u_long`
and `u_char` weren't known when including `sys/soundcard.h` during
compile.

When we introduced some strict POSIX/C11 flags with commit
fad6a3e, this seems to have disabled the __BSD_VISIBLE flag on
FreeBSD which made these typedefs disappear (there is a
`#if __BSD_VISIBLE` guard in `sys/types.h`).

We don't know the reason for disabling `__BSD_VISIBLE` (perhaps it is
along the line of "if you want POSIX, you don't get BSD enhancements")
and we don't know if there are adverse side-effects to manually
enabling `__BSD_VISIBLE`, but for now it works.

If anybody has deeper understanding of this and a better way to fix
this, please speak up :)

This fixes issue #105.

(n.b.: `sys/soundcard.h` contains two sound systems: AIO and OSS.  The
 missing typedefs are only used for AIO while we only need OSS.  So if
 that header file would have been split into two seperate files, we
 would not have run into this problem.  The OSS part should work fine
 with the POSIX/C11 flags without setting `__BSD_VISIBLE`.)
mmitch added a commit that referenced this issue Jan 30, 2024
The FreeBSD build was broken because special typedefs like `u_long`
and `u_char` weren't known when including `sys/soundcard.h` during
compile.

When we introduced some strict POSIX/C11 flags with commit
fad6a3e, this seems to have disabled the __BSD_VISIBLE flag on
FreeBSD which made these typedefs disappear (there is a
`#if __BSD_VISIBLE` guard in `sys/types.h`).

We don't know the reason for disabling `__BSD_VISIBLE` (perhaps it is
along the line of "if you want POSIX, you don't get BSD enhancements")
and we don't know if there are adverse side-effects to manually
enabling `__BSD_VISIBLE`, but for now it works.

If anybody has deeper understanding of this and a better way to fix
this, please speak up :)

This fixes issue #105.

(n.b.: `sys/soundcard.h` contains two sound systems: AIO and OSS.  The
 missing typedefs are only used for AIO while we only need OSS.  So if
 that header file would have been split into two seperate files, we
 would not have run into this problem.  The OSS part should work fine
 with the POSIX/C11 flags without setting `__BSD_VISIBLE`.)
mmitch added a commit that referenced this issue Jan 30, 2024
The FreeBSD build was broken because special typedefs like `u_long`
and `u_char` weren't known when including `sys/soundcard.h` during
compile.

When we introduced some strict POSIX/C11 flags with commit
fad6a3e, this seems to have disabled the __BSD_VISIBLE flag on
FreeBSD which made these typedefs disappear (there is a
`#if __BSD_VISIBLE` guard in `sys/types.h`).

We don't know the reason for disabling `__BSD_VISIBLE` (perhaps it is
along the line of "if you want POSIX, you don't get BSD enhancements")
and we don't know if there are adverse side-effects to manually
enabling `__BSD_VISIBLE`, but for now it works.

If anybody has deeper understanding of this and a better way to fix
this, please speak up :)

This fixes issue #105.

(n.b.: `sys/soundcard.h` contains two sound systems: AIO and OSS.  The
 missing typedefs are only used for AIO while we only need OSS.  So if
 that header file would have been split into two seperate files, we
 would not have run into this problem.  The OSS part should work fine
 with the POSIX/C11 flags without setting `__BSD_VISIBLE`.)
@mmitch
Copy link
Owner

mmitch commented Jan 30, 2024

@ehaupt Could you please test it?
The fix has been merged to the master branch.
The configure script should now automatically set __BSD_VISIBLE on FreeBSD.

@ehaupt
Copy link
Contributor Author

ehaupt commented Jan 31, 2024

@mmitch, I can confirm that e59ba36 fixes the issue. Thank you!

@mmitch
Copy link
Owner

mmitch commented Feb 1, 2024

I think we'll do another release then, even if it breaks our habit of multiple years going by between releases…

@mmitch mmitch closed this as completed Feb 1, 2024
@mmitch mmitch added this to the 0.0.96 milestone Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants