mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-09 05:23:40 +00:00
runtime: refactor markGlobals to findGlobals
Instead of markGlobals calling markRoots unconditionally (which doesn't
make sense for -gc=none and -gc=leaking), provide markRoots as a
callback function.
This is in preparation for -gc=boehm, where the previous design is even
more awkward and a callback makes far more sense.
I've tested the size impact using `make smoketest XTENSA=0`. There is
none, except for two cases:
* One with `-opt=0` so const-propagation for the callback didn't take
place.
* One other on AVR, I don't know why but as it's only 16 bytes in a
very specific case I'm going to assume it's just a random change in
compiler output that caused a size difference.
This commit is contained in:
committed by
Ron Evans
parent
dc449882ad
commit
4643401a1d
@@ -77,9 +77,9 @@ type elfProgramHeader32 struct {
|
||||
//go:extern __ehdr_start
|
||||
var ehdr_start elfHeader
|
||||
|
||||
// markGlobals marks all globals, which are reachable by definition.
|
||||
// findGlobals finds globals in the .data/.bss sections.
|
||||
// It parses the ELF program header to find writable segments.
|
||||
func markGlobals() {
|
||||
func findGlobals(found func(start, end uintptr)) {
|
||||
// Relevant constants from the ELF specification.
|
||||
// See: https://refspecs.linuxfoundation.org/elf/elf.pdf
|
||||
const (
|
||||
@@ -99,14 +99,14 @@ func markGlobals() {
|
||||
if header._type == PT_LOAD && header.flags&PF_W != 0 {
|
||||
start := header.vaddr
|
||||
end := start + header.memsz
|
||||
markRoots(start, end)
|
||||
found(start, end)
|
||||
}
|
||||
} else {
|
||||
header := (*elfProgramHeader32)(headerPtr)
|
||||
if header._type == PT_LOAD && header.flags&PF_W != 0 {
|
||||
start := header.vaddr
|
||||
end := start + header.memsz
|
||||
markRoots(start, end)
|
||||
found(start, end)
|
||||
}
|
||||
}
|
||||
headerPtr = unsafe.Add(headerPtr, ehdr_start.phentsize)
|
||||
|
||||
Reference in New Issue
Block a user