MCPcopy Create free account
hub / github.com/akyoto/q / Update

Method Update

src/exe/Executable.go:37–61  ·  view source on GitHub ↗

Update recalculates all section offsets.

()

Source from the content-addressed store, hash-verified

35 }
36}
37
38// update recalculates the section offsets.
39func (exe *Executable) update(section *Section, index int) {
40 if index == 0 {
41 exe.updateFirst(section)
42 return
43 }
44
45 previous := exe.Sections[index-1]
46 section.FileOffset, section.Padding = AlignPad(previous.FileOffset+len(previous.Bytes), exe.fileAlign)
47 section.MemoryOffset = Align(previous.MemoryOffset+len(previous.Bytes), exe.memoryAlign)
48
49 if exe.congruent && exe.fileAlign != exe.memoryAlign {
50 section.MemoryOffset += section.FileOffset % exe.memoryAlign
51 }
52}
53
54// updateFirst recalculates the section offsets for the first section.
55func (exe *Executable) updateFirst(section *Section) {
56 if exe.embedHeaders {
57 section.FileOffset, section.Padding = AlignPad(exe.headerEnd, 0x40)
58 section.MemoryOffset = section.FileOffset
59 } else {
60 section.FileOffset, section.Padding = AlignPad(exe.headerEnd, exe.fileAlign)
61 section.MemoryOffset = Align(exe.headerEnd, exe.memoryAlign)
62 }
63
64 if exe.congruent && exe.fileAlign != exe.memoryAlign {

Callers 1

NewFunction · 0.95

Calls 2

AlignPadFunction · 0.85
AlignFunction · 0.85

Tested by

no test coverage detected