Improved section offset calculation

This commit is contained in:
2025-01-20 13:51:47 +01:00
parent e2a6a31d8e
commit 4b7c9f387d
7 changed files with 56 additions and 38 deletions

View File

@ -9,6 +9,11 @@ import (
"git.akyoto.dev/cli/q/src/fs"
)
const (
SizeCommands = Segment64Size*3 + ThreadSize
HeaderEnd = HeaderSize + SizeCommands
)
// MachO is the executable format used on MacOS.
type MachO struct {
Header
@ -20,11 +25,6 @@ type MachO struct {
// Write writes the Mach-O format to the given writer.
func Write(writer io.Writer, code []byte, data []byte) {
const (
SizeCommands = Segment64Size*3 + ThreadSize
HeaderEnd = HeaderSize + SizeCommands
)
var (
codeStart, codePadding = fs.Align(HeaderEnd, config.Align)
dataStart, dataPadding = fs.Align(codeStart+len(code), config.Align)
@ -102,7 +102,7 @@ func Write(writer io.Writer, code []byte, data []byte) {
0, 0,
0, 0,
0, 0,
config.BaseAddress + config.CodeOffset, 0,
uint32(config.BaseAddress + codeStart), 0,
0, 0,
0, 0,
0, 0,