Skip to content

Implement RISC-V dynamic linking#323

Draft
DrXiao wants to merge 4 commits intosysprog21:masterfrom
DrXiao:feat/dynlink-for-rv32
Draft

Implement RISC-V dynamic linking#323
DrXiao wants to merge 4 commits intosysprog21:masterfrom
DrXiao:feat/dynlink-for-rv32

Conversation

@DrXiao
Copy link
Copy Markdown
Collaborator

@DrXiao DrXiao commented Apr 23, 2026

The proposed changes primarily improve the ELF generation and the RISC-V backend, enabling the build system to generate a dynamically linked shecc targeting the RISC-V architecture.

Although the current changes allow both bootstrapping and test suite to complete successfully, this is still a work in progress. The TODO items are listed as follows:

  • Enhance code quality, comments and commit messages.
  • Confirm the RISC-V ABI compliance.
  • Add a new script (riscv-abi.sh) to validate the RISC-V ABI.
  • Improve the documentation and README.
  • Consolidate arm.mk and riscv.mk into a common build logic (e.g.: configure RUNNER_LD_PREFIX).
  • (Any new requirements ...)

Summary by cubic

Adds dynamic linking support for RISC-V (rv32). The compiler now emits RELA-based PLT/GOT, calls external functions via PLT, and starts via __libc_start_main; CI and build updates validate dynamic RV32 builds.

  • New Features

    • Enable RISC-V dynamic linking with .rela.plt, RELA entries, and RV32 GOT/PLT sizes; reserve 2 GOT slots for the resolver/link_map.
    • Generate RV32 PLT stubs and call externs via PLT; entry uses __libc_start_main; align stacks and preserve ra; keep syscall trampoline for static builds.
    • Refactor ELF to support REL or RELA via a use_relaplt flag, add arch constants, and emit correct dynamic tags/headers; initialize .got using RESERVED_GOT_NUM.
    • Build/test: allow DYNLINK=1 for RISC-V, add RV32 dynamic snapshots, and run static/dynamic matrices for ARM and RISC-V.
  • Dependencies

    • CI installs a RISC-V glibc toolchain and adds it to PATH; mk/riscv.mk locates ld-linux and sets RUNNER_LD_PREFIX under QEMU for dynamic runs.

Written for commit 446b538. Summary will update on new commits.

DrXiao added 4 commits April 11, 2026 11:44
Modify the 'update-snapshots' and 'check-snapshots' make targets to
include generation and validation of new snapshots for the RISC-V
architecture using dynamic linking.
The update workflow now downloads a RISC-V GNU toolchain to provide
necessary dependencies and validate the dynamically linked compiler
targeting the RISC-V architecture.
@DrXiao
Copy link
Copy Markdown
Collaborator Author

DrXiao commented Apr 23, 2026

As the apt package manager only provides a 64-bit RISC-V GNU cross-compilation toolchain, I utilize riscv-gnu-toolchain , which is a 32-bit variant, and leverage its artifacts for RISC-V dynamic linking development and validation.

The updated GitHub Actions also downloads the 32-bit variant to validate RISC-V dynamic linking.

@jserv
Copy link
Copy Markdown
Collaborator

jserv commented Apr 23, 2026

As the apt package manager only provides a 64-bit RISC-V GNU cross-compilation toolchain, I utilize riscv-gnu-toolchain , which is a 32-bit variant, and leverage its artifacts for RISC-V dynamic linking development and validation.
The updated GitHub Actions also downloads the 32-bit variant to validate RISC-V dynamic linking.

Evaluate Run 32-bit applications on 64-bit Linux kernel, which is exactly RV32-on-RV64 userspace compatibility, not emulation.

@DrXiao
Copy link
Copy Markdown
Collaborator Author

DrXiao commented Apr 24, 2026

Evaluate Run 32-bit applications on 64-bit Linux kernel, which is exactly RV32-on-RV64 userspace compatibility, not emulation.

I'm not sure whether I understand correctly. Do you mean that the proposed changes should be verified on a RISC-V machine?

@jserv
Copy link
Copy Markdown
Collaborator

jserv commented Apr 24, 2026

Do you mean that the proposed changes should be verified on a RISC-V machine?

See sysprog21/kbox#18
The RISE RISC-V Runners is a managed GitHub Actions runner service that executes CI/CD workflows on real RISC-V hardware.

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.

2 participants