2 use core
::{iter, slice, str}
;
5 use crate::endian
::{Endianness, U32Bytes}
;
6 use crate::read
::{self, ComdatKind, ObjectComdat, ReadError, ReadRef, SectionIndex, SymbolIndex}
;
8 use super::{ElfFile, FileHeader, SectionHeader, Sym}
;
10 /// An iterator over the COMDAT section groups of an `ElfFile32`.
11 pub type ElfComdatIterator32
<'data
, 'file
, Endian
= Endianness
, R
= &'data
[u8]> =
12 ElfComdatIterator
<'data
, 'file
, elf
::FileHeader32
<Endian
>, R
>;
13 /// An iterator over the COMDAT section groups of an `ElfFile64`.
14 pub type ElfComdatIterator64
<'data
, 'file
, Endian
= Endianness
, R
= &'data
[u8]> =
15 ElfComdatIterator
<'data
, 'file
, elf
::FileHeader64
<Endian
>, R
>;
17 /// An iterator over the COMDAT section groups of an `ElfFile`.
19 pub struct ElfComdatIterator
<'data
, 'file
, Elf
, R
= &'data
[u8]>
24 pub(super) file
: &'file ElfFile
<'data
, Elf
, R
>,
25 pub(super) iter
: iter
::Enumerate
<slice
::Iter
<'data
, Elf
::SectionHeader
>>,
28 impl<'data
, 'file
, Elf
, R
> Iterator
for ElfComdatIterator
<'data
, 'file
, Elf
, R
>
33 type Item
= ElfComdat
<'data
, 'file
, Elf
, R
>;
35 fn next(&mut self) -> Option
<Self::Item
> {
36 for (_index
, section
) in self.iter
.by_ref() {
37 if let Some(comdat
) = ElfComdat
::parse(self.file
, section
) {
45 /// A COMDAT section group of an `ElfFile32`.
46 pub type ElfComdat32
<'data
, 'file
, Endian
= Endianness
, R
= &'data
[u8]> =
47 ElfComdat
<'data
, 'file
, elf
::FileHeader32
<Endian
>, R
>;
48 /// A COMDAT section group of an `ElfFile64`.
49 pub type ElfComdat64
<'data
, 'file
, Endian
= Endianness
, R
= &'data
[u8]> =
50 ElfComdat
<'data
, 'file
, elf
::FileHeader64
<Endian
>, R
>;
52 /// A COMDAT section group of an `ElfFile`.
54 pub struct ElfComdat
<'data
, 'file
, Elf
, R
= &'data
[u8]>
59 file
: &'file ElfFile
<'data
, Elf
, R
>,
60 section
: &'data Elf
::SectionHeader
,
61 sections
: &'data
[U32Bytes
<Elf
::Endian
>],
64 impl<'data
, 'file
, Elf
, R
> ElfComdat
<'data
, 'file
, Elf
, R
>
70 file
: &'file ElfFile
<'data
, Elf
, R
>,
71 section
: &'data Elf
::SectionHeader
,
72 ) -> Option
<ElfComdat
<'data
, 'file
, Elf
, R
>> {
73 let (flag
, sections
) = section
.group(file
.endian
, file
.data
).ok()??
;
74 if flag
!= elf
::GRP_COMDAT
{
85 impl<'data
, 'file
, Elf
, R
> read
::private
::Sealed
for ElfComdat
<'data
, 'file
, Elf
, R
>
92 impl<'data
, 'file
, Elf
, R
> ObjectComdat
<'data
> for ElfComdat
<'data
, 'file
, Elf
, R
>
97 type SectionIterator
= ElfComdatSectionIterator
<'data
, 'file
, Elf
, R
>;
100 fn kind(&self) -> ComdatKind
{
105 fn symbol(&self) -> SymbolIndex
{
106 SymbolIndex(self.section
.sh_info(self.file
.endian
) as usize)
109 fn name_bytes(&self) -> read
::Result
<&[u8]> {
110 // FIXME: check sh_link
111 let index
= self.section
.sh_info(self.file
.endian
) as usize;
112 let symbol
= self.file
.symbols
.symbol(index
)?
;
113 symbol
.name(self.file
.endian
, self.file
.symbols
.strings())
116 fn name(&self) -> read
::Result
<&str> {
117 let name
= self.name_bytes()?
;
120 .read_error("Non UTF-8 ELF COMDAT name")
123 fn sections(&self) -> Self::SectionIterator
{
124 ElfComdatSectionIterator
{
126 sections
: self.sections
.iter(),
131 /// An iterator over the sections in a COMDAT section group of an `ElfFile32`.
132 pub type ElfComdatSectionIterator32
<'data
, 'file
, Endian
= Endianness
, R
= &'data
[u8]> =
133 ElfComdatSectionIterator
<'data
, 'file
, elf
::FileHeader32
<Endian
>, R
>;
134 /// An iterator over the sections in a COMDAT section group of an `ElfFile64`.
135 pub type ElfComdatSectionIterator64
<'data
, 'file
, Endian
= Endianness
, R
= &'data
[u8]> =
136 ElfComdatSectionIterator
<'data
, 'file
, elf
::FileHeader64
<Endian
>, R
>;
138 /// An iterator over the sections in a COMDAT section group of an `ElfFile`.
140 pub struct ElfComdatSectionIterator
<'data
, 'file
, Elf
, R
= &'data
[u8]>
145 file
: &'file ElfFile
<'data
, Elf
, R
>,
146 sections
: slice
::Iter
<'data
, U32Bytes
<Elf
::Endian
>>,
149 impl<'data
, 'file
, Elf
, R
> Iterator
for ElfComdatSectionIterator
<'data
, 'file
, Elf
, R
>
154 type Item
= SectionIndex
;
156 fn next(&mut self) -> Option
<Self::Item
> {
157 let index
= self.sections
.next()?
;
158 Some(SectionIndex(index
.get(self.file
.endian
) as usize))