Repository: ldc-developers/ldc

Issue #2777: Compiler crash using `main` in a package.d file
Created: 2018-07-16T02:36:51Z
board/package.d
module board;

extern void main();
extern(C) void reset()
{
    main();
}
runtime/object.d
module object;
Compile
$ ldc2 -c -defaultlib= -conf= -Iruntime board/package.d
LLVMSymbolizer: error reading file: No such file or directory
#0 0x000000000289061a (ldc2+0x289061a)
#1 0x000000000288e8de (ldc2+0x288e8de)
#2 0x000000000288ea02 (ldc2+0x288ea02)
#3 0x00007f1e3b2c7a80 __restore_rt (/usr/lib/libpthread.so.0+0x11a80)
#4 0x0000000000c8729a (ldc2+0xc8729a)
#5 0x0000000000c90c3b (ldc2+0xc90c3b)
#6 0x0000000000c90eff (ldc2+0xc90eff)
#7 0x0000000000c8da7d (ldc2+0xc8da7d)
#8 0x0000000000c798d0 (ldc2+0xc798d0)
#9 0x0000000000c7b044 (ldc2+0xc7b044)
#10 0x0000000000c794d4 (ldc2+0xc794d4)
#11 0x0000000000c3eaab (ldc2+0xc3eaab)
#12 0x0000000000c33523 (ldc2+0xc33523)
#13 0x0000000000c36634 (ldc2+0xc36634)
#14 0x0000000000c55ec5 (ldc2+0xc55ec5)
#15 0x0000000000d01449 (ldc2+0xd01449)
#16 0x0000000000cd7226 (ldc2+0xcd7226)
#17 0x0000000000afa990 (ldc2+0xafa990)
#18 0x0000000000cd5007 (ldc2+0xcd5007)
#19 0x00000000029d5420 (ldc2+0x29d5420)
#20 0x00000000029d52a6 (ldc2+0x29d52a6)
#21 0x00007f1e3a97006b __libc_start_main (/usr/lib/libc.so.6+0x2306b)
#22 0x0000000000a22455 (ldc2+0xa22455)
Segmentation fault (core dumped)

Commenting out the call to main avoids the crash.
module board;

extern void main();
extern(C) void reset()
{
    // main();
}
The above is just a reduced test to reproduce the error.  In my actual application I receive an additional error message "only one main function allowed"
$ ldc2 -c -Os -mtriple=thumb-none-eabi -float-abi=hard -mcpu=cortex-m4 -Isource/runtime source/board/random.d source/board/spi5.d source/board/lcd.d source/board/ltdc.d source/board/statusLED.d source/board/ILI9341.d source/board/package.d source/main.d source/stm32f42/pwr.d source/stm32f42/scb.d source/stm32f42/mmio.d source/stm32f42/dma2d.d source/stm32f42/spi.d source/stm32f42/bus.d source/stm32f42/flash.d source/stm32f42/ltdc.d source/stm32f42/rcc.d source/stm32f42/rng.d source/stm32f42/trace.d source/stm32f42/nvic.d source/stm32f42/gpio.d -of=binary/firmware.o
source/board/package.d(36): Error: only one main function allowed
LLVMSymbolizer: error reading file: No such file or directory
#0 0x000000000289061a (ldc2+0x289061a)
#1 0x000000000288e8de (ldc2+0x288e8de)
#2 0x000000000288ea02 (ldc2+0x288ea02)
#3 0x00007f7a125f8a80 __restore_rt (/usr/lib/libpthread.so.0+0x11a80)
#4 0x0000000000c8729a (ldc2+0xc8729a)
#5 0x0000000000c90c3b (ldc2+0xc90c3b)
#6 0x0000000000c90eff (ldc2+0xc90eff)
#7 0x0000000000c8da7d (ldc2+0xc8da7d)
#8 0x0000000000c798d0 (ldc2+0xc798d0)
#9 0x0000000000c7b044 (ldc2+0xc7b044)
#10 0x0000000000c7b044 (ldc2+0xc7b044)
#11 0x0000000000c794d4 (ldc2+0xc794d4)
#12 0x0000000000c3eaab (ldc2+0xc3eaab)
#13 0x0000000000c33523 (ldc2+0xc33523)
#14 0x0000000000c36634 (ldc2+0xc36634)
#15 0x0000000000c55ec5 (ldc2+0xc55ec5)
#16 0x0000000000d01449 (ldc2+0xd01449)
#17 0x0000000000cd7226 (ldc2+0xcd7226)
#18 0x0000000000afa990 (ldc2+0xafa990)
#19 0x0000000000cd5007 (ldc2+0xcd5007)
#20 0x00000000029d5420 (ldc2+0x29d5420)
#21 0x00000000029d52a6 (ldc2+0x29d52a6)
#22 0x00007f7a11ca106b __libc_start_main (/usr/lib/libc.so.6+0x2306b)
#23 0x0000000000a22455 (ldc2+0xa22455)
Segmentation fault (core dumped)

But I haven't found a way to reproduce that error in a reduced test yet.
Compiler Information:
$ ldc2 --version
LDC - the LLVM D compiler (1.11.0-beta2):
  based on DMD v2.081.1 and LLVM 6.0.1
  built with LDC - the LLVM D compiler (1.11.0-beta2)
  Default target: x86_64-unknown-linux-gnu
  Host CPU: skylake
  http://dlang.org - http://wiki.dlang.org/LDC

  Registered Targets:
    aarch64    - AArch64 (little endian)
    aarch64_be - AArch64 (big endian)
    arm        - ARM
    arm64      - ARM64 (little endian)
    armeb      - ARM (big endian)
    mips       - Mips
    mips64     - Mips64 [experimental]
    mips64el   - Mips64el [experimental]
    mipsel     - Mipsel
    msp430     - MSP430 [experimental]
    nvptx      - NVIDIA PTX 32-bit
    nvptx64    - NVIDIA PTX 64-bit
    ppc32      - PowerPC 32
    ppc64      - PowerPC 64
    ppc64le    - PowerPC 64 LE
    riscv32    - 32-bit RISC-V
    riscv64    - 64-bit RISC-V
    thumb      - Thumb
    thumbeb    - Thumb (big endian)
    wasm32     - WebAssembly 32-bit
    wasm64     - WebAssembly 64-bit
    x86        - 32-bit X86: Pentium-Pro and above
    x86-64     - 64-bit X86: EM64T and AMD64

Duplicate issue #4412: Recursive main call causes a segfault in the compiler.
Created: 2023-05-27T16:54:09Z
int main() {
    main();
}
This segfaults ldc2 somehow?

Closing comment (2023-05-30T10:48:17Z): This is a duplicate of #2777; see #2777 (comment) for an explanation (=> actual signature is int _Dmain(string[] args); this magic isn't handled when calling it manually).