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

proposal: runtime: add go:linkname on runtime.firstmoduledata #68581

Closed
timandy opened this issue Jul 25, 2024 · 2 comments
Closed

proposal: runtime: add go:linkname on runtime.firstmoduledata #68581

timandy opened this issue Jul 25, 2024 · 2 comments
Labels
Milestone

Comments

@timandy
Copy link

timandy commented Jul 25, 2024

Goals

Add //go:linkname firstmoduledata on runtime.firstmoduledata with go1.23 release.

We want to access it by go:linkname, and keep compatibility with the old go versions.

Proposal Details

runtime.firstmoduledata provides many useful informations for low level develop.

For example: Get the file path of main function or test function.

// get path of the entry file, may be a /xx/xx_test.go or /xx/main.go
func getEntryFilePath() string {
	mainFile := getMainFile()
	if !isTestMode(mainFile) {
		return mainFile
	}
	firstModule := unsafe.Pointer(&firstmoduledata)
	fileTab := *(*[]byte)(reflection.Add(firstModule, filetabField.Offset))
	lastFiles := getLastFiles(fileTab)
	for _, file := range lastFiles {
		if isTestFile(file) {
			return file
		}
	}
	panic("can not found entry file path")
}
@tianon
Copy link
Contributor

tianon commented Jul 25, 2024

I think what Ian meant in #67401 (comment) was making proposals for actual exported interfaces for the data you need (such as your getEntryFilePath example), not just a proposal for more linkname (which is very very likely to be simply rejected, per the discussion in that other thread).

@ianlancetaylor
Copy link
Member

Yes. This is not the kind of proposal I meant. I meant a maintainable way to access whatever kind of information you are looking for from runtime.firstmoduledata. For example, a proposal for a function to return the file path of the main function. (If you write such a proposal, please be sure to explain why the information is useful.)

I'm going to close this proposal. There is simply no way that we will adopt it. Sorry.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants