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

Always use builtin alloca() #666

Merged
merged 1 commit into from Jun 23, 2020
Merged

Conversation

sjmulder
Copy link
Collaborator

Fixes the build on NetBSD 9 on arm64.

GCC expands alloca() to __builtin_alloca() but only in nonstandard mode,
e.g. when -std=... is not supplied. In standards mode (with -std=...)
alloca() is left undefined by GCC. The C library may define it but it
also may not, as on NetBSD on arm64:

$ uname -srp
NetBSD 9.0 aarch64

$ cat alloca.c
#include <stdlib.h>
int main() { char *p = alloca(10); }

$ gcc alloca.c

$ gcc -std=c99 alloca.c
alloca.c:(.text+0xc): warning: Warning: reference to the libc
 supplied alloca(3); this most likely will not work. Please use the
 compiler provided version of alloca(3), by supplying the
 appropriate compiler flags (e.g. not -std=c89).
ld: alloca.c:(.text+0xc): undefined reference to `alloca'

The fix is to either not use standards mode (undesirable) or to
explicitly use the builtin, which is what this patch does.

This is also sufficient for Solarius/Illumos so that check and include
are removed.

Fixes the build on NetBSD 9 on arm64.

GCC expands alloca() to __builtin_alloca() but only in nonstandard mode,
e.g. when -std=... is not supplied.  In standards mode (with -std=...)
alloca() is left undefined by GCC. The C library may define it but it
also may not, as on NetBSD on arm64:

    $ uname -srp
    NetBSD 9.0 aarch64

    $ cat alloca.c
    #include <stdlib.h>
    int main() { char *p = alloca(10); }

    $ gcc alloca.c

    $ gcc -std=c99 alloca.c
    alloca.c:(.text+0xc): warning: Warning: reference to the libc
     supplied alloca(3); this most likely will not work. Please use the
     compiler provided version of alloca(3), by supplying the
     appropriate compiler flags (e.g. not -std=c89).
    ld: alloca.c:(.text+0xc): undefined reference to `alloca'

The fix is to either not use standards mode (undesirable) or to
explicitly use the builtin, which is what this patch does.

This is also sufficient for Solarius/Illumos so that check and include
are removed.
@sjmulder
Copy link
Collaborator Author

Sorry for all the revisions – first pushed an older commit, then forgot to check Linux.

@leovilok
Copy link
Collaborator

We might want to check if this works in a non GNU environment, e.g. clang+musl.

@sjmulder
Copy link
Collaborator Author

Good point, successfully tested on macOS Catalina (10.15) with clang now.

@jarun jarun merged commit 3686ef7 into jarun:master Jun 23, 2020
@jarun
Copy link
Owner

jarun commented Jun 23, 2020

Thank you!

@sjmulder sjmulder deleted the pr/builtin-alloca branch June 23, 2020 22:47
@github-actions github-actions bot locked and limited conversation to collaborators Jul 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants