Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: add runtime.fnctl link directives #4481

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

leongross
Copy link
Contributor

Building u-root commands with tinygo (see u-root/u-root#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

//go:linkname syscall_fcntl runtime/runtime.fcntl
func syscall_fcntl(fd, cmd, arg int32) (ret int32, errno int32) {
// https://cs.opensource.google/go/go/+/master:src/runtime/os_linux.go;l=452?q=runtime.fcntl&ss=go%2Fgo
r, _, err := Syscall6(SYS_FCNTL, uintptr(fd), uintptr(cmd), uintptr(arg), 0, 0, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you trying to do a direct system call in syscall_libc.go? Syscall6 and the like are only supported on Windows and Linux, not on many other systems.

What about calling the libc function fcntl instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a wrapper to the libc sounds like a good idea.

Comment on lines 145 to 147
func fcntl(fd, cmd, arg int32) (ret int32, errno int32){
return 0, 0
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bad idea. It should not just ignore the call and return without an error.
Is this intended to call syscall_fcntl perhaps?

And then, any reason not to call the libc function instead (like with syscall_Getpagesize for example).

@@ -212,6 +212,13 @@ func Truncate(path string, length int64) (err error) {
return
}

//go:linkname syscall_fcntl runtime/runtime.fcntl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant runtime.fcntl?

Suggested change
//go:linkname syscall_fcntl runtime/runtime.fcntl
//go:linkname syscall_fcntl runtime.fcntl

@leongross leongross changed the title runtime: add runtime.fcntl link directives runtime: add runtime.fnctl link directives Oct 3, 2024
@leongross
Copy link
Contributor Author

leongross commented Oct 4, 2024

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.

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