# Zig ELF binary entry is 0

**URL:** <https://ziggit.dev/t/zig-elf-binary-entry-is-0/2704>\
**Category:** Help\
**Tags:** language\
**Created:** [January 3, 2024, 5:34pm UTC](https://ziggit.dev/t/zig-elf-binary-entry-is-0/2704 "2024-01-03T17:34:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samuel-fiedler](https://ziggit.dev/user_avatar/ziggit.dev/samuel-fiedler/32/2801_2.png) [@samuel-fiedler](https://ziggit.dev/u/samuel-fiedler)\
**Post date:** [January 3, 2024, 5:34pm UTC](https://ziggit.dev/t/zig-elf-binary-entry-is-0/2704/1 "2024-01-03T17:34:01Z")

</div>

Hello there,

in my [last question](https://ziggit.dev/t/how-to-cross-compile-in-the-new-zig-master/2700/2) 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:

```plaintext
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](https://codeberg.org/samuel-fiedler/zig_os).  
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

---

<div class="post-metadata">

**Author:** ![nullptrdevs](https://ziggit.dev/user_avatar/ziggit.dev/nullptrdevs/32/1323_2.png) [@nullptrdevs](https://ziggit.dev/u/nullptrdevs)\
**Post date:** [January 4, 2024, 6:22am UTC](https://ziggit.dev/t/zig-elf-binary-entry-is-0/2704/2 "2024-01-04T06:22:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![squeek502](https://ziggit.dev/user_avatar/ziggit.dev/squeek502/32/409_2.png) [@squeek502](https://ziggit.dev/u/squeek502)\
**Post date:** [January 4, 2024, 7:28am UTC](https://ziggit.dev/t/zig-elf-binary-entry-is-0/2704/3 "2024-01-04T07:28:31Z")

</div>

> <https://github.com/ziglang/zig/blob/ecd520f6619c08cac17f8f662facc90595444ac5/lib/std/Build/Step/Compile.zig#L156>

> <https://github.com/ziglang/zig/blob/ecd520f6619c08cac17f8f662facc90595444ac5/lib/std/Build/Step/Compile.zig#L201-L211>

---

<div class="post-metadata">

**Author:** ![nullptrdevs](https://ziggit.dev/user_avatar/ziggit.dev/nullptrdevs/32/1323_2.png) [@nullptrdevs](https://ziggit.dev/u/nullptrdevs)\
**Post date:** [January 4, 2024, 7:36am UTC](https://ziggit.dev/t/zig-elf-binary-entry-is-0/2704/4 "2024-01-04T07:36:04Z")

</div>

🤦 me…

Thanks, @squeek502 🧡

Solutions:  
A. `kernel.entry = .disabled; // Set in linker script`  
B. Rename `kmain` → `_start`

---

<div class="post-metadata">

**Author:** ![samuel-fiedler](https://ziggit.dev/user_avatar/ziggit.dev/samuel-fiedler/32/2801_2.png) [@samuel-fiedler](https://ziggit.dev/u/samuel-fiedler)\
**Post date:** [January 4, 2024, 7:52am UTC](https://ziggit.dev/t/zig-elf-binary-entry-is-0/2704/5 "2024-01-04T07:52:14Z")

</div>

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