Bug 24815 – betterC can not use alloca()

Status
NEW
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2024-10-14T20:58:44Z
Last change time
2024-12-13T19:38:10Z
Assigned to
No Owner
Creator
Derek Fawcus
Moved to GitHub: dmd#18276 →

Comments

Comment #0 by dfawcus+dlang — 2024-10-14T20:58:44Z
The following program fails to link due to alloca being a missing symbol, despite it being being declared in core.stdc.stdlib. The program compiles and runs with both GDC and LDC. This is with: DMD64 D Compiler v2.109.1 ```D import core.stdc.stdio; import core.stdc.string; import core.stdc.stdlib; extern(C) void main() { int len = 4; char *mem = cast(char*)alloca(len); memcpy(mem, cast(const char *)"Foo\0", len); char[] memS = mem[0..len]; printf("%s; %.*s\n", memS.ptr, cast(int)memS.length, memS.ptr); } ``` ``` $ dmd -betterC alloca1.d /usr/bin/ld: alloca1.o: in function `main': alloca1.d:(.text.main[main]+0x21): undefined reference to `__alloca' collect2: error: ld returned 1 exit status Error: undefined reference to `__alloca` referenced from `main` perhaps a library needs to be added with the `-L` flag or `pragma(lib, ...)` Error: linker exited with status 1 cc alloca1.o -o alloca1 -m64 -Xlinker --export-dynamic -L/usr/lib/x86_64-linux-gnu -lpthread -lm -lrt -ldl ``` A similar error is seen when using -m32.
Comment #1 by robert.schadek — 2024-12-13T19:38:10Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18276 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB