[Issue 24815] New: betterC can not use alloca()
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Oct 14 20:58:44 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24815
Issue ID: 24815
Summary: betterC can not use alloca()
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: dfawcus+dlang at employees.org
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.
--
More information about the Digitalmars-d-bugs
mailing list