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

Toxcore does not build with cmake on OpenBSD. #881

Closed
ghost opened this issue Apr 22, 2018 · 7 comments
Closed

Toxcore does not build with cmake on OpenBSD. #881

ghost opened this issue Apr 22, 2018 · 7 comments
Labels
P3 Low priority
Milestone

Comments

@ghost
Copy link

ghost commented Apr 22, 2018

I've taken a look into toxcore/ccompat.h and this is what worries me:

#ifdef _WIN32
#include <malloc.h>
#elif defined(__FreeBSD__)
#include <stdlib.h>
#if !defined(alloca) && defined(__GNUC__)
#define alloca __builtin_alloca
#endif
#else
#include <alloca.h>
#endif

As far as I know <alloca.h> is a Linux-specific header (and perhaps also MacOS-specific header). That means toxcore works only at Windows, Linux and FreeBSD...
@iphydf Do you know that alloca(3) and malloc(3) are supposed to be at <stdlib.h> at any OS, including Windows and Linux? So this should work not only for FreeBSD:

-#ifdef _WIN32
-#include <malloc.h>
-#elif defined(__FreeBSD__)
 #include <stdlib.h>
 #if !defined(alloca) && defined(__GNUC__)
 #define alloca __builtin_alloca
 #endif
-#else
-#include <alloca.h>
-#endif

But quickly patching that doesn't help, I get a spam of undefined references: https://pastebin.com/raw/NbrasTWR
What have you done? You made toxcore completely non portable!

@jhert0
Copy link
Member

jhert0 commented Apr 22, 2018

What operating system are you trying to build toxcore on?

@ghost
Copy link
Author

ghost commented Apr 22, 2018

@endoffile78 OpenBSD

@jhert0
Copy link
Member

jhert0 commented Apr 22, 2018

I just tried on my OpenBSD virtual machine and I get the same thing. I tried both gcc and clang. I'm running OpenBSD 6.3.

@iphydf
Copy link
Member

iphydf commented Apr 23, 2018

If you leave it as is, does it build on OpenBSD? I.e. does removing those lines cause the undefined references?

According to which standard is alloca supposed to be available in stdlib.h? It's inherently a non-standard function, neither in any C nor in any POSIX standard document.

On Linux/glibc, if you ask the compiler for C99 compliance, alloca is not available, hence the ifdef mess. Long term, I'd like to get rid of stack allocated buffers or at least allocate the maximum buffer every time (so no VLAs or alloca) so we can calculate the maximum stack depth.

@ghost
Copy link
Author

ghost commented Apr 23, 2018

@iphydf

First, I don't have <alloca.h> header:

test.c:1:10: fatal error: 'alloca.h' file not found
#include <alloca.h>
         ^~~~~~~~~~
1 error generated.

Second, leaving it as is does not help to build (it didn't start building toxcore/ccompat.h, but at release 0.2.0 it returned error because toxcore/ccompat.h tried to include <alloca.h>), still a flood of undefined references: https://pastebin.com/raw/8g9iyw2i

Third, according to man pages at Linux, FreeBSD, NetBSD and OpenBSD alloca() is terrible.

Fourth, it seems that including <stdlib.h> at Linux will work if you don't use -ansi and -std=c* with gcc https://man.openbsd.org/Linux-4.13/alloca#Notes_on_the_GNU_version

@iphydf
Copy link
Member

iphydf commented Apr 23, 2018

Thanks for reporting this. I'm very keen on making things portable. The introduction of alloca was to allow compilation on MSVC and other compilers not supporting VLAs. The gcc compilation shouldn't need it. The linker errors you're getting are not related to alloca, but are interesting. It seems the libc is not linked to the library, which can make sense. Some build systems do this on systems where undefined references are supported in dynamic libraries. The linker flag "-z defs" is the likely reason for these errors. I'll check with endoffile78 whether removing that flag fixes it.

@iphydf iphydf changed the title Why are you making code completely non-portable? Toxcore does not build with cmake on OpenBSD. Apr 23, 2018
@ghost
Copy link
Author

ghost commented Apr 24, 2018

@iphydf If some compilers don't support VLAs, what's wrong with using malloc(3) (or calloc(3)) instead of alloca(3)? Anyway, I am going to make 0.2.2 port.

@robinlinden robinlinden modified the milestone: v0.2.11 Mar 20, 2020
@iphydf iphydf added the P3 Low priority label Feb 4, 2022
@iphydf iphydf added this to the v0.2.3 milestone Feb 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 Low priority
Projects
None yet
Development

No branches or pull requests

3 participants