authorgravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2021-10-18 15:54:56-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-10-21 17:03:44-04:00
loge2a2e6c14fe181989187d6b59a79c5fc32961250
tree1eb9ff3e9cadb2f8499e65e779090775607eef1d
parentda2b615efb14f662bf3aac1f9050174966acd17d

InstallRawStep: handle empty segments

This fixes InstallRawStep to handle the cases when there are empty segments (segments with no sections). Before this change, if there was an empty segment with no sections, then the fixup of binaryOffsets is skipped. This fixes that by looping through each segment until a non-empty one is found and then fixing up the sections. This fixed an issue I was having with InstallRawStep for a bootloader I'm writing.

1 files changed, 3 insertions(+), 3 deletions(-)

lib/std/build/InstallRawStep.zig+3-3
......@@ -96,8 +96,7 @@ const BinaryElfOutput = struct {
9696
9797 sort.sort(*BinaryElfSegment, self.segments.items, {}, segmentSortCompare);
9898
99 if (self.segments.items.len > 0) {
100 const firstSegment = self.segments.items[0];
99 for (self.segments.items) |firstSegment, i| {
101100 if (firstSegment.firstSection) |firstSection| {
102101 const diff = firstSection.elfOffset - firstSegment.elfOffset;
103102
......@@ -107,9 +106,10 @@ const BinaryElfOutput = struct {
107106
108107 const basePhysicalAddress = firstSegment.physicalAddress;
109108
110 for (self.segments.items) |segment| {
109 for (self.segments.items[i + 1 ..]) |segment| {
111110 segment.binaryOffset = segment.physicalAddress - basePhysicalAddress;
112111 }
112 break;
113113 }
114114 }
115115