summaryrefslogtreecommitdiffhomepage
path: root/tools/checklinkname/README.md
blob: 06b3c302d380a5bb180f2e6d583666088f7e1b4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# `checklinkname` Analyzer

`checklinkname` is an analyzer to provide rudimentary type-checking for
`//go:linkname` directives. Since `//go:linkname` only affects linker behavior,
there is no built-in type safety and it is the programmer's responsibility to
ensure the types on either side are compatible.

`checklinkname` helps with this by checking that uses match expectations, as
defined in this package.

`known.go` contains the set of known linkname targets. For most functions, we
expect identical types on both sides of the linkname. In a few cases, the types
may be slightly different (e.g., local redefinition of internal type). It is
still the responsibility of the programmer to ensure the signatures in
`known.go` are compatible and safe.

## Findings

Here are the most common findings from this package, and how to resolve them.

### `runtime.foo signature got "BAR" want "BAZ"; stdlib type changed?`

The definition of `runtime.foo` in the standard library does not match the
expected type in `known.go`. This means that the function signature in the
standard library changed.

Addressing this will require creating a new linkname directive in a new Go
version build-tagged in any packages using this symbol. Be sure to also check to
ensure use with the new version is safe, as function constraints may have
changed in addition to the signature.

<!-- TODO(b/165820485): This isn't yet explicitly supported. -->

`known.go` will also need to be updated to accept the new signature for the new
version of Go.

### `Cannot find known symbol "runtime.foo"`

The standard library has removed runtime.foo entirely. Handling is similar to
above, except existing code must transition away from the symbol entirely (note
that is may simply be renamed).

### `linkname to unknown symbol "mypkg.foo"; add this symbol to checklinkname.knownLinknames type-check against the remote type`

A package has added a new linkname directive for a symbol not listed in
`known.go`. Address this by adding a new entry for the target symbol. The
`local` field should be the expected type in your package, while `remote` should
be expected type in the remote package (e.g., in the standard library). These
are typically identical, in which case `remote` can be omitted.

### `usage: //go:linkname localname [linkname]`

Malformed `//go:linkname` directive. This should be accompanied by a build
failure in the package.