File tree Expand file tree Collapse file tree 4 files changed +18
-13
lines changed Expand file tree Collapse file tree 4 files changed +18
-13
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ) ) ;
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments