Zig ELF binary entry is 0

Hello there,

in my last question I mentioned the x64 exception from QEMU.
I tried to solve it by myself, but it still does not work. But, at least, I think I found the cause: the entry of the kernel (ELF) binary is zero.
Below is the output of llvm-readelf:

ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          64 (bytes into file)
  Start of section headers:          24344 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         4
  Size of section headers:           64 (bytes)
  Number of section headers:         18
  Section header string table index: 16
There are 18 section headers, starting at offset 0x5f18:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        0000000000100000 001000 0006a6 00  AX  0   0 4096
  [ 2] .rodata           PROGBITS        0000000000101000 002000 0000d8 00  AM  0   0 4096
  [ 3] .data             PROGBITS        0000000000102000 003000 00006e 00  WA  0   0 4096
  [ 4] .bss              NOBITS          0000000000103000 00306e 0040c0 00  WA  0   0 4096
  [ 5] .debug_loc        PROGBITS        0000000000000000 00306e 000143 00      0   0  1
  [ 6] .debug_abbrev     PROGBITS        0000000000000000 0031b1 00016b 00      0   0  1
  [ 7] .debug_info       PROGBITS        0000000000000000 00331c 000bd0 00      0   0  1
  [ 8] .debug_ranges     PROGBITS        0000000000000000 003eec 000070 00      0   0  1
  [ 9] .debug_str        PROGBITS        0000000000000000 003f5c 000d10 01  MS  0   0  1
  [10] .debug_pubnames   PROGBITS        0000000000000000 004c6c 00036c 00      0   0  1
  [11] .debug_pubtypes   PROGBITS        0000000000000000 004fd8 000359 00      0   0  1
  [12] .debug_frame      PROGBITS        0000000000000000 005338 0001a8 00      0   0  8
  [13] .debug_line       PROGBITS        0000000000000000 0054e0 000380 00      0   0  1
  [14] .comment          PROGBITS        0000000000000000 005860 000013 01  MS  0   0  1
  [15] .symtab           SYMTAB          0000000000000000 005878 000390 18     17  30  8
  [16] .shstrtab         STRTAB          0000000000000000 005c08 0000b4 00      0   0  1
  [17] .strtab           STRTAB          0000000000000000 005cbc 00025a 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  R (retain), l (large), p (processor specific)

Elf file type is EXEC (Executable file)
Entry point 0x0
There are 4 program headers, starting at offset 64

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  LOAD           0x001000 0x0000000000100000 0x0000000000100000 0x0006a6 0x0006a6 R E 0x1000
  LOAD           0x002000 0x0000000000101000 0x0000000000101000 0x0000d8 0x0000d8 R   0x1000
  LOAD           0x003000 0x0000000000102000 0x0000000000102000 0x00006e 0x0050c0 RW  0x1000
  GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x1000000 RW  0x0

 Section to Segment mapping:
  Segment Sections...
   00     .text 
   01     .rodata 
   02     .data .bss 
   03     .bss 
   None   .debug_loc .debug_abbrev .debug_info .debug_ranges .debug_str .debug_pubnames .debug_pubtypes .debug_frame .debug_line .comment .symtab .shstrtab .strtab 

My build.zig and kernel.ld can be found on codeberg.
Now, what could be the cause of this problem? Or could it be a ZIG internal and should I report it on GitHub?

Looking forwards,
Samuel Fiedler

It seems Zig has started insisting on a default entry point, _start.

I found no way to override it via build.zig, only via args to zig build-exe on the cli.

:person_facepalming: me…

Thanks, @squeek502 :orange_heart:

Solutions:
A. kernel.entry = .disabled; // Set in linker script
B. Rename kmain_start

1 Like

Thanks!
This thing makes Zig even more explicit, but… well, the Linker Script is also very explicit.