mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-15 08:23:41 +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
@@ -52,7 +52,7 @@ var module *exeHeader
|
||||
// around 160 bytes of amd64 instructions.
|
||||
// Most of this function is based on the documentation in
|
||||
// https://docs.microsoft.com/en-us/windows/win32/debug/pe-format.
|
||||
func markGlobals() {
|
||||
func findGlobals(found func(start, end uintptr)) {
|
||||
// Constants used in this function.
|
||||
const (
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulehandleexa
|
||||
@@ -85,7 +85,7 @@ func markGlobals() {
|
||||
// Found a writable section. Scan the entire section for roots.
|
||||
start := uintptr(unsafe.Pointer(module)) + uintptr(section.virtualAddress)
|
||||
end := uintptr(unsafe.Pointer(module)) + uintptr(section.virtualAddress) + uintptr(section.virtualSize)
|
||||
markRoots(start, end)
|
||||
found(start, end)
|
||||
}
|
||||
section = (*peSection)(unsafe.Add(unsafe.Pointer(section), unsafe.Sizeof(peSection{})))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user