1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00
Achilleas Anagnostopoulos 275664219e Implement tool to detect redirects and to populate the redirect table
The tool scans all go sources (excluding tests) in the "kernel" package
and its subpackages looking for functions with a "go:redirect-from
symbol_name" comment. The go:redirect-from directive implies that a
function serves as a redirect target for s symbol name.  For example,
the following block:

//go:redirect-from runtime.gopanic
func foo(_ interface{}){
	...
}

specifies that calls to "runtime.gopanic" should be redirected to "foo".

The tool provides two commands:
- count: prints the count of redirections
- populate-table: resolve redirect symbols and populate the
  _rt0_rediret_table entries in the kernel image.

As the final virtual addresses for the symbols are only known after
linking, populating this table is a 2-step process. At first, the
"count" command is used to allocate enough space for 2 x NUM_REDIRECTS
pointers. The table itself is placed with the help of the linker script
in a separate section making it easy to find its offset in the ELF
image.

After the kernel is linked, the "populate-table" command use the
debug/elf package to scan the image file and resolve the addresses for
the src and dst redirection symbols. The tool will then open the image
file in RW mode, seek to the location of the table and write the symbol
addresses for each (src, dst) tuple.
2017-06-25 21:39:16 +01:00
..