Skip to content

Commit e5320f4

Browse files
committed
Fix no bits section
1 parent a406b84 commit e5320f4

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

src/LibObjectFile/Elf/ElfFile.Read.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ private unsafe void VerifyAndFixProgramHeadersAndSections(ElfReader reader)
129129
for (int i = 0; i < contentList.Count; i++)
130130
{
131131
var part = contentList[i];
132+
if (part is ElfSection section && !section.HasContent)
133+
{
134+
if (section is ElfNoBitsSection noBitsSection)
135+
{
136+
noBitsSection.PositionOffsetFromPreviousContent = part.Position - contentList[i - 1].Position;
137+
}
138+
continue;
139+
}
140+
132141
if (part.Position > currentPosition)
133142
{
134143
var streamContent = new ElfStreamContentData(true)
@@ -141,16 +150,7 @@ private unsafe void VerifyAndFixProgramHeadersAndSections(ElfReader reader)
141150
currentPosition = part.Position;
142151
i++;
143152
}
144-
else if (part.Position < currentPosition && part is ElfNoBitsSection notBitsSection)
145-
{
146-
notBitsSection.PositionOffsetIntoPreviousSection = part.Position - contentList[i-1].Position;
147-
}
148-
149-
if (part is ElfSection section && !section.HasContent)
150-
{
151-
continue;
152-
}
153-
153+
154154
currentPosition += part.Size;
155155
}
156156

src/LibObjectFile/Elf/ElfFile.Write.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public override void Write(ElfWriter writer)
2121
for (var i = 0; i < contentList.Count; i++)
2222
{
2323
var content = contentList[i];
24+
if (content is ElfSection section && section.Type == ElfSectionType.NoBits)
25+
{
26+
continue;
27+
}
28+
2429
if (content.Position > writer.Position)
2530
{
2631
writer.WriteZero((int)(content.Position - writer.Position));

src/LibObjectFile/Elf/ElfFile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,9 @@ public unsafe void UpdateLayout(DiagnosticBag diagnostics)
317317
var content = contentList[i];
318318
if (content is ElfNullSection) continue;
319319

320-
if (content is ElfNoBitsSection noBitsSection && noBitsSection.PositionOffsetIntoPreviousSection.HasValue)
320+
if (content is ElfNoBitsSection noBitsSection && noBitsSection.PositionOffsetFromPreviousContent.HasValue)
321321
{
322-
content.Position = contentList[i-1].Position + noBitsSection.PositionOffsetIntoPreviousSection.Value;
322+
content.Position = contentList[i-1].Position + noBitsSection.PositionOffsetFromPreviousContent.Value;
323323
}
324324
else
325325
{

src/LibObjectFile/Elf/Sections/ElfNoBitsSection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public ElfNoBitsSection() : base(ElfSectionType.NoBits)
1010
{
1111
}
1212

13-
public ulong? PositionOffsetIntoPreviousSection { get; set; }
13+
public ulong? PositionOffsetFromPreviousContent { get; set; }
1414

1515
public override void Read(ElfReader reader)
1616
{

0 commit comments

Comments
 (0)