@@ -169,54 +169,56 @@ public List<ElfSymbol> RelocateDynamicSymbols(Program program)
169
169
Loader . DynamicEntries . TryGetValue ( ElfDynamicEntry . DT_RELENT , out var relent ) ;
170
170
171
171
Loader . DynamicEntries . TryGetValue ( ElfDynamicEntry . DT_SYMENT , out var syment ) ;
172
- if ( symtab == null || ( rela == null && rel == null ) )
172
+ if ( symtab is null )
173
173
continue ;
174
- if ( strtab == null )
174
+ if ( strtab is null )
175
175
throw new BadImageFormatException ( "ELF dynamic segment lacks a string table." ) ;
176
- if ( syment == null )
176
+ if ( syment is null )
177
177
throw new BadImageFormatException ( "ELF dynamic segment lacks the size of symbol table entries." ) ;
178
- RelocationTable relTable ;
179
- if ( rela != null )
178
+ var offStrtab = Loader . AddressToFileOffset ( strtab . UValue ) ;
179
+ var offSymtab = Loader . AddressToFileOffset ( symtab . UValue ) ;
180
+
181
+ RelocationTable ? relTable = null ;
182
+ if ( rela is { } )
180
183
{
181
- if ( relasz == null )
184
+ if ( relasz is null )
182
185
throw new BadImageFormatException ( "ELF dynamic segment lacks the size of the relocation table." ) ;
183
- if ( relaent == null )
186
+ if ( relaent is null )
184
187
throw new BadImageFormatException ( "ELF dynamic segment lacks the size of relocation table entries." ) ;
185
188
relTable = new RelaTable ( this , rela . UValue , relasz . UValue ) ;
186
189
}
187
- else
190
+ else if ( rel != null )
188
191
{
189
- Debug . Assert ( rel != null ) ;
190
- if ( relsz == null )
192
+ if ( relsz is null )
191
193
throw new BadImageFormatException ( "ELF dynamic segment lacks the size of the relocation table." ) ;
192
- if ( relent == null )
194
+ if ( relent is null )
193
195
throw new BadImageFormatException ( "ELF dynamic segment lacks the size of relocation table entries." ) ;
194
196
relTable = new RelTable ( this , rel . UValue , relsz . UValue ) ;
195
197
}
196
198
197
- var offStrtab = Loader . AddressToFileOffset ( strtab . UValue ) ;
198
- var offSymtab = Loader . AddressToFileOffset ( symtab . UValue ) ;
199
-
200
- LoadSymbolsFromDynamicSegment ( dynSeg , symtab , syment , offStrtab , offSymtab ) ;
201
-
202
- // Generate a symbol for each relocation.
203
- ElfImageLoader . trace . Inform ( "Relocating entries in .dynamic:" ) ;
204
- foreach ( var ( _, elfSym , _) in relTable . RelocateEntries ( program , offStrtab , offSymtab , syment . UValue ) )
199
+ if ( relTable is { } )
205
200
{
206
- symbols . Add ( elfSym ) ;
207
- var imgSym = Loader . CreateImageSymbol ( elfSym , true ) ;
208
- // Symbols need to refer to the loaded image, if their value is 0,
209
- // they are imported symbols.
210
- if ( imgSym == null || imgSym . Address ! . ToLinear ( ) == 0 )
211
- continue ;
212
- imageSymbols [ imgSym . Address ] = imgSym ;
201
+ LoadSymbolsFromDynamicSegment ( dynSeg , symtab , syment , offStrtab , offSymtab ) ;
202
+
203
+ // Generate a symbol for each relocation.
204
+ ElfImageLoader . trace . Inform ( "Relocating entries in .dynamic:" ) ;
205
+ foreach ( var ( _, elfSym , _) in relTable . RelocateEntries ( program , offStrtab , offSymtab , syment . UValue ) )
206
+ {
207
+ symbols . Add ( elfSym ) ;
208
+ var imgSym = Loader . CreateImageSymbol ( elfSym , true ) ;
209
+ // Symbols need to refer to the loaded image, if their value is 0,
210
+ // they are imported symbols.
211
+ if ( imgSym == null || imgSym . Address ! . ToLinear ( ) == 0 )
212
+ continue ;
213
+ imageSymbols [ imgSym . Address ] = imgSym ;
214
+ }
213
215
}
214
216
215
217
// Relocate the DT_JMPREL table.
216
218
Loader . DynamicEntries . TryGetValue ( ElfDynamicEntry . DT_JMPREL , out var jmprel ) ;
217
219
Loader . DynamicEntries . TryGetValue ( ElfDynamicEntry . DT_PLTRELSZ , out var pltrelsz ) ;
218
220
Loader . DynamicEntries . TryGetValue ( ElfDynamicEntry . DT_PLTREL , out var pltrel ) ;
219
- if ( jmprel != null && pltrelsz != null && pltrel != null )
221
+ if ( jmprel is { } && pltrelsz is { } && pltrel is { } )
220
222
{
221
223
if ( pltrel . SValue == ElfDynamicEntry . DT_RELA ) // entries are in RELA format.
222
224
{
@@ -228,7 +230,8 @@ public List<ElfSymbol> RelocateDynamicSymbols(Program program)
228
230
}
229
231
else
230
232
{
231
- //$REVIEW: bad elf format!
233
+ var listener = Loader . Services . RequireService < DecompilerEventListener > ( ) ;
234
+ listener . Warn ( "Invalid value for DT_PLTREL: {0}" , pltrel . UValue ) ;
232
235
continue ;
233
236
}
234
237
@@ -411,7 +414,7 @@ public ElfRelocator32(ElfLoader32 loader, SortedList<Address, ImageSymbol> image
411
414
412
415
protected override void DumpDynamicSegment ( ElfSegment dynSeg )
413
416
{
414
- var renderer = new DynamicSectionRenderer32 ( Loader , null ! , ElfMachine . EM_NONE ) ;
417
+ var renderer = new DynamicSectionRenderer32 ( Loader , null ! , loader . Machine ) ;
415
418
var sw = new StringWriter ( ) ;
416
419
renderer . Render ( dynSeg . p_offset , new TextFormatter ( sw ) ) ;
417
420
Debug . WriteLine ( sw . ToString ( ) ) ;
@@ -462,7 +465,7 @@ protected void DumpRel32(ElfLoader32 loader)
462
465
{
463
466
foreach ( var section in loader . Sections . Where ( s => s . Type == SectionHeaderType . SHT_REL ) )
464
467
{
465
- ElfImageLoader . trace . Inform ( "REL: offset {0:X} symbol section {1}, relocating in section {2}" ,
468
+ ElfImageLoader . trace . Inform ( "REL: Offset {0:X} symbol section {1}, relocating in section {2}" ,
466
469
section . FileOffset ,
467
470
section . LinkedSection ? . Name ?? "?" ,
468
471
section . RelocatedSection ? . Name ?? "?" ) ;
@@ -487,7 +490,7 @@ protected void DumpRela32(ElfLoader32 loader)
487
490
foreach ( var section in loader . Sections . Where ( s => s . Type == SectionHeaderType . SHT_RELA ) )
488
491
{
489
492
ElfImageLoader . trace . Inform (
490
- "RELA: offset {0:X} symbol section {1}, relocating in section {2}" ,
493
+ "RELA: Offset {0:X} symbol section {1}, relocating in section {2}" ,
491
494
section . FileOffset ,
492
495
section . LinkedSection ! . Name ,
493
496
section . RelocatedSection ! . Name ) ;
@@ -573,7 +576,7 @@ protected void DumpRel64(ElfLoader64 loader)
573
576
{
574
577
foreach ( var section in loader . Sections . Where ( s => s . Type == SectionHeaderType . SHT_REL ) )
575
578
{
576
- ElfImageLoader . trace . Inform ( "REL: offset {0:X} symbol section {1}, relocating in section {2}" ,
579
+ ElfImageLoader . trace . Inform ( "REL: Offset {0:X} symbol section {1}, relocating in section {2}" ,
577
580
section . FileOffset ,
578
581
section . LinkedSection ? . Name ?? "?" ,
579
582
section . RelocatedSection ? . Name ?? "?" ) ;
@@ -600,7 +603,7 @@ protected void DumpRela64(ElfLoader64 loader)
600
603
s . LinkedSection != null &&
601
604
s . LinkedSection . FileOffset != 0 ) )
602
605
{
603
- Debug . Print ( "RELA: offset {0:X} symbol section {1}, relocating in section {2}" ,
606
+ Debug . Print ( "RELA: Offset {0:X} symbol section {1}, relocating in section {2}" ,
604
607
section . FileOffset ,
605
608
section . LinkedSection ? . Name ?? "?" ,
606
609
section . RelocatedSection ? . Name ?? "?" ) ;
0 commit comments