tinygo icon indicating copy to clipboard operation
tinygo copied to clipboard

runtime: add runtime.fcntl link directives

Open leongross opened this issue 1 year ago • 1 comments

Building u-root commands with tinygo (see https://github.com/u-root/u-root/issues/2979) returns linking errors for the system runtime function runtime.fcntl. This PR intends to fix this issue. Affected u-root cmdlets:

  • localboot
  • netbootxyz
  • newsshd
  • systemboot

leongross avatar Sep 24 '24 13:09 leongross

I am perplexed by the linker's behavior. After reconsidering your design choices, what I want to do is the following:

  • create function Fcntl in syscall_unix and syscall_libc
  • in os_linux add the function declaration for fcntl
  • link the syscall function over the runtime.fcntl function (since we cannot import the syscall package due to circular dependencies)

I tried:

  • link the runtime/fcnlt function to syscall.Fcntl -> did not work
  • link the syscall.Fcntl function(s) to runtime.fcntl -> did not work
  • declare runtime.fcntl as linkable (//go:linkname fcntl) and link from the syscall package up -> did not work

I realized it only worked when I defined runtime.fcntl to return nothing. I would really appreciate your input on this.

leongross avatar Oct 04 '24 09:10 leongross