@@ -116,7 +116,7 @@ impl<'data> Builder<'data> {
116
116
let header = Elf :: parse ( data) ?;
117
117
let endian = header. endian ( ) ?;
118
118
let is_mips64el = header. is_mips64el ( endian) ;
119
- let shstrndx = header. shstrndx ( endian, data) ? as usize ;
119
+ let section_strings_index = header. section_strings_index ( endian, data) ?;
120
120
let segments = header. program_headers ( endian, data) ?;
121
121
let sections = header. sections ( endian, data) ?;
122
122
let symbols = sections. symbols ( endian, data, elf:: SHT_SYMTAB ) ?;
@@ -179,8 +179,8 @@ impl<'data> Builder<'data> {
179
179
builder. load_align = 1 ;
180
180
}
181
181
182
- for ( index, section) in sections. iter ( ) . enumerate ( ) . skip ( 1 ) {
183
- let id = SectionId ( index - 1 ) ;
182
+ for ( index, section) in sections. enumerate ( ) . skip ( 1 ) {
183
+ let id = SectionId ( index. 0 - 1 ) ;
184
184
let relocations = if let Some ( ( rels, link) ) = section. rel ( endian, data) ? {
185
185
Self :: read_relocations (
186
186
index,
@@ -222,7 +222,7 @@ impl<'data> Builder<'data> {
222
222
| elf:: SHT_PREINIT_ARRAY => SectionData :: Data ( section. data ( endian, data) ?. into ( ) ) ,
223
223
elf:: SHT_REL | elf:: SHT_RELA => relocations,
224
224
elf:: SHT_SYMTAB => {
225
- if index == symbols. section ( ) . 0 {
225
+ if index == symbols. section ( ) {
226
226
SectionData :: Symbol
227
227
} else {
228
228
return Err ( Error ( format ! (
@@ -232,7 +232,7 @@ impl<'data> Builder<'data> {
232
232
}
233
233
}
234
234
elf:: SHT_SYMTAB_SHNDX => {
235
- if index == symbols. shndx_section ( ) . 0 {
235
+ if index == symbols. shndx_section ( ) {
236
236
SectionData :: SymbolSectionIndex
237
237
} else {
238
238
return Err ( Error ( format ! (
@@ -242,7 +242,7 @@ impl<'data> Builder<'data> {
242
242
}
243
243
}
244
244
elf:: SHT_DYNSYM => {
245
- if index == dynamic_symbols. section ( ) . 0 {
245
+ if index == dynamic_symbols. section ( ) {
246
246
SectionData :: DynamicSymbol
247
247
} else {
248
248
return Err ( Error ( format ! (
@@ -252,11 +252,11 @@ impl<'data> Builder<'data> {
252
252
}
253
253
}
254
254
elf:: SHT_STRTAB => {
255
- if index == symbols. string_section ( ) . 0 {
255
+ if index == symbols. string_section ( ) {
256
256
SectionData :: String
257
- } else if index == dynamic_symbols. string_section ( ) . 0 {
257
+ } else if index == dynamic_symbols. string_section ( ) {
258
258
SectionData :: DynamicString
259
- } else if index == shstrndx {
259
+ } else if index == section_strings_index {
260
260
SectionData :: SectionString
261
261
} else {
262
262
return Err ( Error ( format ! (
@@ -372,7 +372,7 @@ impl<'data> Builder<'data> {
372
372
373
373
#[ allow( clippy:: too_many_arguments) ]
374
374
fn read_relocations < Elf , Rel , R > (
375
- index : usize ,
375
+ index : read :: SectionIndex ,
376
376
endian : Elf :: Endian ,
377
377
is_mips64el : bool ,
378
378
section : & ' data Elf :: SectionHeader ,
@@ -427,7 +427,7 @@ impl<'data> Builder<'data> {
427
427
}
428
428
429
429
fn read_relocations_impl < Elf , Rel , const DYNAMIC : bool > (
430
- index : usize ,
430
+ index : read :: SectionIndex ,
431
431
endian : Elf :: Endian ,
432
432
is_mips64el : bool ,
433
433
rels : & ' data [ Rel ] ,
@@ -440,17 +440,16 @@ impl<'data> Builder<'data> {
440
440
let mut relocations = Vec :: new ( ) ;
441
441
for rel in rels {
442
442
let rel = ( * rel) . into ( ) ;
443
- let r_sym = rel. r_sym ( endian, is_mips64el) ;
444
- let symbol = if r_sym == 0 {
445
- None
446
- } else {
447
- if r_sym as usize >= symbols_len {
443
+ let symbol = if let Some ( symbol) = rel. symbol ( endian, is_mips64el) {
444
+ if symbol. 0 >= symbols_len {
448
445
return Err ( Error ( format ! (
449
446
"Invalid symbol index {} in relocation section at index {}" ,
450
- r_sym , index,
447
+ symbol , index,
451
448
) ) ) ;
452
449
}
453
- Some ( SymbolId ( r_sym as usize - 1 ) )
450
+ Some ( SymbolId ( symbol. 0 - 1 ) )
451
+ } else {
452
+ None
454
453
} ;
455
454
relocations. push ( Relocation {
456
455
r_offset : rel. r_offset ( endian) . into ( ) ,
@@ -523,8 +522,8 @@ impl<'data> Builder<'data> {
523
522
Elf : FileHeader < Endian = Endianness > ,
524
523
R : ReadRef < ' data > ,
525
524
{
526
- for ( index, symbol) in symbols. iter ( ) . enumerate ( ) . skip ( 1 ) {
527
- let id = SymbolId ( index - 1 ) ;
525
+ for ( index, symbol) in symbols. enumerate ( ) . skip ( 1 ) {
526
+ let id = SymbolId ( index. 0 - 1 ) ;
528
527
let section =
529
528
if let Some ( section_index) = symbols. symbol_section ( endian, symbol, index) ? {
530
529
let section_id = section_index. 0 . wrapping_sub ( 1 ) ;
@@ -553,7 +552,7 @@ impl<'data> Builder<'data> {
553
552
}
554
553
555
554
fn read_attributes < Elf > (
556
- index : usize ,
555
+ index : read :: SectionIndex ,
557
556
attributes : read:: elf:: AttributesSection < ' data , Elf > ,
558
557
sections_len : usize ,
559
558
symbols_len : usize ,
0 commit comments