Skip to content

Add a minimal UEFI target#5362

Draft
sparques wants to merge 6 commits intotinygo-org:devfrom
sparques:pr/minimal-uefi-target-support
Draft

Add a minimal UEFI target#5362
sparques wants to merge 6 commits intotinygo-org:devfrom
sparques:pr/minimal-uefi-target-support

Conversation

@sparques
Copy link
Copy Markdown
Contributor

@sparques sparques commented May 1, 2026

Summary

This PR adds a minimal uefi-amd64 target to TinyGo.

The intent is to land the smallest useful slice of UEFI support first:

  • target definition for uefi-amd64
  • PE/COFF linking support through ld.lld
  • minimal UEFI runtime entry/exit path
  • minimal firmware bindings needed for startup, console output, timing, and heap allocation
  • a tiny clean-exit example for validation

This PR does not try to upstream the larger protocol surface from the previous UEFI branch. It is intentionally limited
to getting a basic UEFI application built and run as a TinyGo baremetal target.

What this adds

  • targets/uefi-amd64.json
  • generic target-controlled linker flavor selection, so a target can request PE/COFF-style ld.lld handling without a UEFI-
    specific builder special case
  • minimal machine/uefi support for:
    • system table access
    • boot services calls
    • text output
    • simple timing support
  • minimal UEFI runtime support for:
    • efi_main entry
    • heap allocation through AllocatePages
    • clean return from a do-nothing application
  • minimal amd64 support code needed by this target
  • examples/uefi-exit as a simple regression-style smoke example

What this does not add

This PR intentionally leaves out higher-level UEFI features, including:

  • filesystem protocols
  • graphics output
  • networking
  • serial I/O
  • environment variables / argument handling
  • broader protocol coverage

Those can be added in follow-up PRs once the target itself is established.

Design notes

TinyGo baremetal targets commonly use goos: "linux" for runtime selection, and this target follows that existing
convention.

The unusual part of UEFI is not the runtime model, but the output format: the target must produce a valid PE/COFF image. The linker changes here keep the working ld.lld-based approach, but move it behind a generic target property instead of a UEFI-specific special case in the builder.

The runtime in this PR is intentionally minimal:

  • gc=leaking
  • scheduler=none

That keeps the initial target small and reduces the number of moving pieces needed for first upstream support.

Testing

Built successfully with:

./build/tinygo build -size short -o /tmp/tinygo-uefi-empty.exe -target=uefi-amd64 examples/empty
./build/tinygo build -size short -o /tmp/tinygo-uefi-exit.exe -target=uefi-amd64 ./examples/uefi-exit

Observed behavior:

- firmware accepts the generated PE/COFF image
- examples/empty runs as expected
- examples/uefi-exit cleanly returns to firmware (this is more of a challenge than it sounds)

@sparques sparques marked this pull request as draft May 1, 2026 23:35
@sparques sparques changed the title Add a minima UEFI target Add a minimal UEFI target May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant