Open
Description
Derek Fawcus reported this on 2024-10-14T20:58:44Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=24815
Description
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
", 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.