Implemented dynamic section alignment
This commit is contained in:
@ -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,
|
||||
|
@ -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:
|
||||
|
@ -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]
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user