You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.gofuncgetEntryFilePath() string {
mainFile:=getMainFile()
if!isTestMode(mainFile) {
returnmainFile
}
firstModule:=unsafe.Pointer(&firstmoduledata)
fileTab:=*(*[]byte)(reflection.Add(firstModule, filetabField.Offset))
lastFiles:=getLastFiles(fileTab)
for_, file:=rangelastFiles {
ifisTestFile(file) {
returnfile
}
}
panic("can not found entry file path")
}
The text was updated successfully, but these errors were encountered:
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).
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.
Goals
Add
//go:linkname firstmoduledata
onruntime.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.
The text was updated successfully, but these errors were encountered: