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

1.8.0: alloca not portable #6807

Open
0-wiz-0 opened this issue May 7, 2024 · 4 comments
Open

1.8.0: alloca not portable #6807

0-wiz-0 opened this issue May 7, 2024 · 4 comments

Comments

@0-wiz-0
Copy link
Contributor

0-wiz-0 commented May 7, 2024

We've updated libgit2 to 1.8.0 in pkgsrc. Now the build on Illumos fails with:

[ 29%] Building C object src/cli/CMakeFiles/git2_cli.dir/opt.c.o
/home/pbulk/build/devel/libgit2/work/libgit2-1.8.0/src/cli/opt.c: In function 'cli_opt_parse':
/home/pbulk/build/devel/libgit2/work/libgit2-1.8.0/src/cli/opt.c:560:23: warning: implicit declaration of function 'alloca'; did you mean 'valloc'? [-Wimplicit-function-declaration]
  560 |         given_specs = alloca(sizeof(const cli_opt_spec *) * (args_len + 1));
      |                       ^~~~~~
      |                       valloc
/home/pbulk/build/devel/libgit2/work/libgit2-1.8.0/src/cli/opt.c:560:21: warning: assignment to 'const cli_opt_spec **' from 'int' makes pointer from integer without a cast [-Wint-conversion]
  560 |         given_specs = alloca(sizeof(const cli_opt_spec *) * (args_len + 1));
      |                     ^
At top level:
cc1: note: unrecognized command-line option '-Wno-documentation-deprecated-sync' may have been intended to silence earlier diagnostics
[ 29%] Building C object src/cli/CMakeFiles/git2_cli.dir/opt_usage.c.o
[ 29%] Building C object src/cli/CMakeFiles/git2_cli.dir/progress.c.o
[ 29%] Building C object src/cli/CMakeFiles/git2_cli.dir/unix/sighandler.c.o
[ 30%] Linking C executable ../../git2
Undefined			first referenced
 symbol  			    in file
alloca                              CMakeFiles/git2_cli.dir/opt.c.o
ld: fatal: symbol referencing errors. No output written to ../../git2
collect2: error: ld returned 1 exit status
*** [git2] Error code 1

The NetBSD man page lists a lot of limitations for alloca and recommend it not be used in portable code. Also, on NetBSD it's provided by stdlib.h, while on Illumos it's in alloca.h. The Illumos man page also strongly discourages its use.

@boretrk
Copy link
Contributor

boretrk commented May 14, 2024

Yep, alloca is non-posix.
const cli_opt_spec *given_specs[args_len + 1]; would probably be a better option in this case.

Pretty much any argument that can be made against using VLA will apply to alloca, but VLA has the benefit of being part of C99.

@ethomson
Copy link
Member

Do you know offhand whether MSVC supports VLA and if so, when that support started? alloca sort of sucks, but it's mostly portable. (Having to include alloc.h is hardly a deal-breaker. Once the AmigaOS folks start trying to use this, though, that's when we'll need to deal with this.)

Anyway, v1.8.1 should properly support Illumos, Solaris, SunOS and include alloc.h (@0-wiz-0 please let me know if it does not).

I'll leave this open since no, it's not really that portable, as the issue title describes. It's something to chew on but it's pretty low-priority.

@boretrk
Copy link
Contributor

boretrk commented May 16, 2024

Oh, my bad, I honestly thought MSVC had full C99 support but it seems like they never made any such claim.
It does however seem like they have deprecated alloca but as you say it still compiles.

@ethomson
Copy link
Member

They've been slowly chipping away at improving their C compiler. I'll take a look and see where VLA support starts and we can decide how we should attack this. (Could be ifdefs, even.)

Could also just do a malloc. Might be the simplest path forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants