cl: go:linkname specifies call convention by C.xxx

This commit is contained in:
xushiwei
2024-04-26 13:09:24 +08:00
parent 33716a3385
commit f86cd74a98
9 changed files with 27 additions and 13 deletions

View File

@@ -98,9 +98,13 @@ func (p *context) initLinkname(pkgPath, line string) {
if strings.HasPrefix(line, linkname) {
text := strings.TrimSpace(line[len(linkname):])
if idx := strings.IndexByte(text, ' '); idx > 0 {
name := pkgPath + "." + text[:idx]
link := strings.TrimLeft(text[idx+1:], " ")
p.link[name] = link
if strings.Contains(link, ".") { // eg. C.printf, C.strlen
name := pkgPath + "." + text[:idx]
p.link[name] = link[2:]
} else {
panic(line + ": no specified call convention. eg. //go:linkname Printf C.printf")
}
}
}
}