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:
Ayke van Laethem
2023-09-01 17:50:41 +02:00
committed by Ron Evans
parent dc449882ad
commit 4643401a1d
8 changed files with 20 additions and 27 deletions
+3 -3
View File
@@ -54,12 +54,12 @@ type segmentLoadCommand struct {
//go:extern _mh_execute_header
var libc_mh_execute_header machHeader
// Mark global variables.
// Find global variables in .data/.bss sections.
// The MachO linker doesn't seem to provide symbols for the start and end of the
// data section. There is get_etext, get_edata, and get_end, but these are
// undocumented and don't work with ASLR (which is enabled by default).
// Therefore, read the MachO header directly.
func markGlobals() {
func findGlobals(found func(start, end uintptr)) {
// Here is a useful blog post to understand the MachO file format:
// https://h3adsh0tzz.com/2020/01/macho-file-format/
@@ -103,7 +103,7 @@ func markGlobals() {
// This could be improved by only reading the memory areas
// covered by sections. That would reduce the amount of memory
// scanned a little bit (up to a single VM page).
markRoots(offset+cmd.vmaddr, offset+cmd.vmaddr+cmd.vmsize)
found(offset+cmd.vmaddr, offset+cmd.vmaddr+cmd.vmsize)
}
}