Implemented dynamic section alignment

This commit is contained in:
2025-03-09 00:23:23 +01:00
parent b67f3b0977
commit 947a8db937
9 changed files with 35 additions and 23 deletions

View File

@ -18,7 +18,7 @@ func Finalize(a asm.Assembler, dlls dll.List) ([]byte, []byte) {
code: make([]byte, 0, len(a.Instructions)*8),
codeLabels: make(map[string]Address, 32),
codePointers: make([]*pointer, 0, len(a.Instructions)*8),
codeStart: codeOffset(),
codeStart: uint32(codeOffset()),
data: data,
dataLabels: dataLabels,
dlls: dlls,

View File

@ -9,8 +9,8 @@ import (
)
// codeOffset returns the file offset of the code section.
func codeOffset() Address {
headerEnd := Address(0)
func codeOffset() int {
headerEnd := 0
switch config.TargetOS {
case config.Linux:

View File

@ -19,15 +19,14 @@ func (c *compiler) move(x asm.Instruction) {
start := Address(len(c.code))
c.code = x86.LoadAddress(c.code, operands.Register, 0x00_00_00_00)
end := Address(len(c.code))
size := uint32(4)
position := end - size
position := end - 4
opSize := position - start
if strings.HasPrefix(operands.Label, "data ") {
c.dataPointers = append(c.dataPointers, &pointer{
Position: position,
OpSize: uint8(opSize),
Size: uint8(size),
Size: uint8(4),
Resolve: func() Address {
destination, exists := c.dataLabels[operands.Label]
@ -44,7 +43,7 @@ func (c *compiler) move(x asm.Instruction) {
c.codePointers = append(c.codePointers, &pointer{
Position: position,
OpSize: uint8(opSize),
Size: uint8(size),
Size: uint8(4),
Resolve: func() Address {
destination, exists := c.codeLabels[operands.Label]

View File

@ -77,7 +77,7 @@ restart:
}
}
sections := exe.MakeSections(int(codeOffset()), c.code, c.data, nil)
sections := exe.MakeSections(codeOffset(), c.code, c.data, nil)
data := sections[1]
c.dataStart = Address(data.MemoryOffset)