mirror of
https://github.com/rui314/mold.git
synced 2026-11-09 04:49:33 -10:00
ran cargo clippy --allow-dirty --fix -- -Wclippy::use_self
This commit is contained in:
1 parent
6fad4d5cf1
commit
733952657a
45 files changed
+238
-238
No files matched your search
+4
-4
@@ -166,7 +166,7 @@ impl Arch for I386 {
|
||||
|
||||
fn apply_eh_reloc(
|
||||
_ctx: &Context<Self>,
|
||||
_isec: &InputSection<I386>,
|
||||
_isec: &InputSection<Self>,
|
||||
rel: &Self::Rel,
|
||||
loc: &mut [u8],
|
||||
p: u64,
|
||||
@@ -180,7 +180,7 @@ impl Arch for I386 {
|
||||
}
|
||||
}
|
||||
|
||||
fn scan_relocations(ctx: &Context<Self>, isec: &InputSection<I386>) {
|
||||
fn scan_relocations(ctx: &Context<Self>, isec: &InputSection<Self>) {
|
||||
debug_assert!(isec.is_alloc());
|
||||
let file = &ctx.objs[isec.file.index()];
|
||||
let rels = isec.rels(file);
|
||||
@@ -263,7 +263,7 @@ impl Arch for I386 {
|
||||
|
||||
fn apply_reloc_alloc(
|
||||
ctx: &Context<Self>,
|
||||
isec: &InputSection<I386>,
|
||||
isec: &InputSection<Self>,
|
||||
rels: &mut [Self::Rel],
|
||||
buf: &mut [u8],
|
||||
) {
|
||||
@@ -457,7 +457,7 @@ impl Arch for I386 {
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_reloc_nonalloc(ctx: &Context<Self>, isec: &InputSection<I386>, buf: &mut [u8]) {
|
||||
fn apply_reloc_nonalloc(ctx: &Context<Self>, isec: &InputSection<Self>, buf: &mut [u8]) {
|
||||
let mut fragment_cache = crate::input_sections::FragmentLookup::default();
|
||||
let file = &ctx.objs[isec.file.index()];
|
||||
for (i, rel) in isec.relocations(ctx).enumerate() {
|
||||
|
||||
+4
-4
@@ -178,7 +178,7 @@ impl Arch for S390x {
|
||||
|
||||
fn apply_eh_reloc(
|
||||
ctx: &Context<Self>,
|
||||
isec: &InputSection<S390x>,
|
||||
isec: &InputSection<Self>,
|
||||
rel: &Self::Rel,
|
||||
loc: &mut [u8],
|
||||
p: u64,
|
||||
@@ -196,7 +196,7 @@ impl Arch for S390x {
|
||||
}
|
||||
}
|
||||
|
||||
fn scan_relocations(ctx: &Context<Self>, isec: &InputSection<S390x>) {
|
||||
fn scan_relocations(ctx: &Context<Self>, isec: &InputSection<Self>) {
|
||||
debug_assert!(isec.is_alloc());
|
||||
let file = &ctx.objs[isec.file.index()];
|
||||
// Scan relocations
|
||||
@@ -259,7 +259,7 @@ impl Arch for S390x {
|
||||
|
||||
fn apply_reloc_alloc(
|
||||
ctx: &Context<Self>,
|
||||
isec: &InputSection<S390x>,
|
||||
isec: &InputSection<Self>,
|
||||
rels: &mut [Self::Rel],
|
||||
buf: &mut [u8],
|
||||
) {
|
||||
@@ -465,7 +465,7 @@ impl Arch for S390x {
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_reloc_nonalloc(ctx: &Context<Self>, isec: &InputSection<S390x>, buf: &mut [u8]) {
|
||||
fn apply_reloc_nonalloc(ctx: &Context<Self>, isec: &InputSection<Self>, buf: &mut [u8]) {
|
||||
let mut fragment_cache = crate::input_sections::FragmentLookup::default();
|
||||
let file = &ctx.objs[isec.file.index()];
|
||||
for (i, rel) in isec.relocations(ctx).enumerate() {
|
||||
|
||||
+4
-4
@@ -147,7 +147,7 @@ impl Arch for X86_64 {
|
||||
|
||||
fn apply_eh_reloc(
|
||||
ctx: &Context<Self>,
|
||||
isec: &InputSection<X86_64>,
|
||||
isec: &InputSection<Self>,
|
||||
rel: &Self::Rel,
|
||||
loc: &mut [u8],
|
||||
p: u64,
|
||||
@@ -170,7 +170,7 @@ impl Arch for X86_64 {
|
||||
}
|
||||
}
|
||||
|
||||
fn scan_relocations(ctx: &Context<Self>, isec: &InputSection<X86_64>) {
|
||||
fn scan_relocations(ctx: &Context<Self>, isec: &InputSection<Self>) {
|
||||
// Linker has to create data structures in an output file to apply
|
||||
// some type of relocations. For example, if a relocation refers a GOT
|
||||
// or a PLT entry of a symbol, linker has to create an entry in .got
|
||||
@@ -290,7 +290,7 @@ impl Arch for X86_64 {
|
||||
// scan_relocations().
|
||||
fn apply_reloc_alloc(
|
||||
ctx: &Context<Self>,
|
||||
isec: &InputSection<X86_64>,
|
||||
isec: &InputSection<Self>,
|
||||
rels: &mut [Self::Rel],
|
||||
buf: &mut [u8],
|
||||
) {
|
||||
@@ -528,7 +528,7 @@ impl Arch for X86_64 {
|
||||
//
|
||||
// Relocations against non-SHF_ALLOC sections are not scanned by
|
||||
// scan_relocations.
|
||||
fn apply_reloc_nonalloc(ctx: &Context<Self>, isec: &InputSection<X86_64>, buf: &mut [u8]) {
|
||||
fn apply_reloc_nonalloc(ctx: &Context<Self>, isec: &InputSection<Self>, buf: &mut [u8]) {
|
||||
let mut fragment_cache = crate::input_sections::FragmentLookup::default();
|
||||
let file = &ctx.objs[isec.file.index()];
|
||||
for (i, rel) in isec.relocations(ctx).enumerate() {
|
||||
|
||||
@@ -138,7 +138,7 @@ fn contents<E: Arch>(ctx: &Context<E>) -> Vec<u8> {
|
||||
output_section::write_to(ctx, sec.output_section, &mut buf);
|
||||
let sentinel_addr = base + ((num_entries - 1) * ENTRY_SIZE) as u64;
|
||||
let mut entries: Vec<(u32, u32)> = buf
|
||||
.chunks_exact(ENTRY_SIZE)
|
||||
.as_chunks::<ENTRY_SIZE>().0.iter()
|
||||
.map(|e| (E::Endian::read_u32(e), E::Endian::read_u32(&e[4..])))
|
||||
.collect();
|
||||
// Fill in sentinel fields
|
||||
|
||||
@@ -16,11 +16,11 @@ pub struct BuildIdSection<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Layout> BuildIdSection<E> {
|
||||
pub fn new() -> BuildIdSection<E> {
|
||||
pub fn new() -> Self {
|
||||
let mut hdr = ChunkHeader::<E>::new(".note.gnu.build-id", SHT_NOTE, SHF_ALLOC as u64);
|
||||
hdr.shdr.sh_addralign.set(4);
|
||||
hdr.shdr.sh_size.set(1);
|
||||
BuildIdSection { hdr, contents: Vec::new() }
|
||||
Self { hdr, contents: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,12 +17,12 @@ pub struct ComdatGroupSection<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Layout> ComdatGroupSection<E> {
|
||||
pub fn new(sym: SymbolId, members: Vec<ChunkId>) -> ComdatGroupSection<E> {
|
||||
pub fn new(sym: SymbolId, members: Vec<ChunkId>) -> Self {
|
||||
let mut hdr = ChunkHeader::<E>::new(".group", SHT_GROUP, 0);
|
||||
hdr.shdr.sh_entsize.set(4);
|
||||
hdr.shdr.sh_addralign.set(4);
|
||||
hdr.shdr.sh_size.set((members.len() * 4 + 4) as u64);
|
||||
ComdatGroupSection { hdr, sym, members }
|
||||
Self { hdr, sym, members }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@ pub struct CopyrelSection<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Layout> CopyrelSection<E> {
|
||||
pub fn new(is_relro: bool) -> CopyrelSection<E> {
|
||||
pub fn new(is_relro: bool) -> Self {
|
||||
let name = if is_relro { ".copyrel.rel.ro" } else { ".copyrel" };
|
||||
let mut hdr = ChunkHeader::<E>::new(name, SHT_NOBITS, (SHF_ALLOC | SHF_WRITE) as u64);
|
||||
hdr.is_relro = is_relro;
|
||||
CopyrelSection { hdr, symbols: Vec::new() }
|
||||
Self { hdr, symbols: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ pub struct DynstrSection<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Layout> DynstrSection<E> {
|
||||
pub fn new() -> DynstrSection<E> {
|
||||
DynstrSection {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
hdr: ChunkHeader::<E>::new(".dynstr", SHT_STRTAB, SHF_ALLOC as u64),
|
||||
strings: HashMap::new(),
|
||||
}
|
||||
|
||||
@@ -29,12 +29,12 @@ pub struct DynstrEntry {
|
||||
}
|
||||
|
||||
impl<E: Arch> DynsymSection<E> {
|
||||
pub fn new() -> DynsymSection<E> {
|
||||
pub fn new() -> Self {
|
||||
let mut hdr = ChunkHeader::<E>::new(".dynsym", SHT_DYNSYM, SHF_ALLOC as u64);
|
||||
let entsize = std::mem::size_of::<ElfSym<E>>() as u64;
|
||||
hdr.shdr.sh_entsize.set(entsize);
|
||||
hdr.shdr.sh_addralign.set(E::WORD_SIZE as u64);
|
||||
DynsymSection { hdr, symbols: Vec::new(), dynstr_entries: Vec::new() }
|
||||
Self { hdr, symbols: Vec::new(), dynstr_entries: Vec::new() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -20,11 +20,11 @@ pub struct EhFrameHdrSection<E: Layout> {
|
||||
impl<E: Layout> EhFrameHdrSection<E> {
|
||||
pub const HEADER_SIZE: u64 = 12;
|
||||
|
||||
pub fn new() -> EhFrameHdrSection<E> {
|
||||
pub fn new() -> Self {
|
||||
let mut hdr = ChunkHeader::<E>::new(".eh_frame_hdr", SHT_PROGBITS, SHF_ALLOC as u64);
|
||||
hdr.shdr.sh_addralign.set(4);
|
||||
hdr.shdr.sh_size.set(Self::HEADER_SIZE);
|
||||
EhFrameHdrSection { hdr, num_fdes: 0 }
|
||||
Self { hdr, num_fdes: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@ pub struct GnuDebuglinkSection<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Layout> GnuDebuglinkSection<E> {
|
||||
pub fn new() -> GnuDebuglinkSection<E> {
|
||||
pub fn new() -> Self {
|
||||
let mut hdr = ChunkHeader::<E>::new(".gnu_debuglink", SHT_PROGBITS, 0);
|
||||
hdr.shdr.sh_addralign.set(4);
|
||||
GnuDebuglinkSection { hdr, crc32: 0 }
|
||||
Self { hdr, crc32: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,10 +38,10 @@ impl<E: Arch> GnuHashSection<E> {
|
||||
pub const HEADER_SIZE: u64 = 16;
|
||||
pub const BLOOM_SHIFT: u32 = 26;
|
||||
|
||||
pub fn new() -> GnuHashSection<E> {
|
||||
pub fn new() -> Self {
|
||||
let mut hdr = ChunkHeader::<E>::new(".gnu.hash", SHT_GNU_HASH, SHF_ALLOC as u64);
|
||||
hdr.shdr.sh_addralign.set(E::WORD_SIZE as u64);
|
||||
GnuHashSection { hdr, num_buckets: 0, num_bloom: 1, num_exported: 0 }
|
||||
Self { hdr, num_buckets: 0, num_bloom: 1, num_exported: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ pub struct GotSection<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Arch> GotSection<E> {
|
||||
pub fn new() -> GotSection<E> {
|
||||
pub fn new() -> Self {
|
||||
let mut hdr = ChunkHeader::<E>::new(".got", SHT_PROGBITS, (SHF_ALLOC | SHF_WRITE) as u64);
|
||||
hdr.is_relro = true;
|
||||
hdr.shdr.sh_addralign.set(E::WORD_SIZE as u64);
|
||||
@@ -31,7 +31,7 @@ impl<E: Arch> GotSection<E> {
|
||||
// as reserved slots, so we allocate two more for them.
|
||||
let reserved = if E::FAMILY == Family::S390x { 3 } else { 1 };
|
||||
hdr.shdr.sh_size.set(reserved * E::WORD_SIZE as u64);
|
||||
GotSection {
|
||||
Self {
|
||||
hdr,
|
||||
got_syms: Vec::new(),
|
||||
tlsgd_syms: Vec::new(),
|
||||
|
||||
@@ -242,10 +242,10 @@ fn merged_output_name(
|
||||
}
|
||||
|
||||
impl<E: Layout> MergedSection<E> {
|
||||
fn new(name: &'static BStr, flags: u64, sh_type: u32, entsize: u64) -> MergedSection<E> {
|
||||
fn new(name: &'static BStr, flags: u64, sh_type: u32, entsize: u64) -> Self {
|
||||
let mut hdr = ChunkHeader::<E>::with_name(name, sh_type, flags);
|
||||
hdr.shdr.sh_entsize.set(entsize);
|
||||
MergedSection {
|
||||
Self {
|
||||
hdr,
|
||||
members: Vec::new(),
|
||||
map: ConcurrentMap::default(),
|
||||
@@ -262,7 +262,7 @@ impl<E: Layout> MergedSection<E> {
|
||||
/// existing section, so the list is only write-locked to add one.
|
||||
pub fn get_instance(
|
||||
args: &Args,
|
||||
sections: &RwLock<Vec<MergedSection<E>>>,
|
||||
sections: &RwLock<Vec<Self>>,
|
||||
name: &'static BStr,
|
||||
shdr: &ElfShdr<E>,
|
||||
cache: &mut MergedSectionCache,
|
||||
@@ -295,7 +295,7 @@ impl<E: Layout> MergedSection<E> {
|
||||
}
|
||||
Some(id)
|
||||
};
|
||||
let find = |sections: &[MergedSection<E>]| {
|
||||
let find = |sections: &[Self]| {
|
||||
sections
|
||||
.iter()
|
||||
.enumerate()
|
||||
@@ -323,7 +323,7 @@ impl<E: Layout> MergedSection<E> {
|
||||
Cow::Borrowed(name) => name,
|
||||
Cow::Owned(name) => crate::util::leak_bytes(name),
|
||||
});
|
||||
sections.push(MergedSection::new(name, flags, sh_type, entsize));
|
||||
sections.push(Self::new(name, flags, sh_type, entsize));
|
||||
remember(MergedSectionId(sections.len() as u32 - 1), name)
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -66,9 +66,9 @@ pub struct OutputSectionId(NonZeroU32);
|
||||
|
||||
impl OutputSectionId {
|
||||
#[inline]
|
||||
pub fn new(index: u32) -> OutputSectionId {
|
||||
pub fn new(index: u32) -> Self {
|
||||
let encoded = index.checked_add(1).expect("too many output sections");
|
||||
OutputSectionId(NonZeroU32::new(encoded).unwrap())
|
||||
Self(NonZeroU32::new(encoded).unwrap())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -133,12 +133,12 @@ pub enum ChunkId {
|
||||
impl ChunkId {
|
||||
/// Whether the chunk is one of the ELF headers rather than a section.
|
||||
pub fn is_header(self) -> bool {
|
||||
matches!(self, ChunkId::Ehdr | ChunkId::Phdr | ChunkId::Shdr)
|
||||
matches!(self, Self::Ehdr | Self::Phdr | Self::Shdr)
|
||||
}
|
||||
|
||||
pub fn as_output_section(self) -> Option<OutputSectionId> {
|
||||
match self {
|
||||
ChunkId::Output(id) => Some(id),
|
||||
Self::Output(id) => Some(id),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -173,8 +173,8 @@ pub struct ChunkHeader<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Layout> ChunkHeader<E> {
|
||||
pub fn new(name: &'static str, sh_type: u32, sh_flags: u64) -> ChunkHeader<E> {
|
||||
ChunkHeader {
|
||||
pub fn new(name: &'static str, sh_type: u32, sh_flags: u64) -> Self {
|
||||
Self {
|
||||
name: BStr::new(name.as_bytes()),
|
||||
shdr: {
|
||||
let mut shdr = ElfShdr::<E>::default();
|
||||
@@ -196,8 +196,8 @@ impl<E: Layout> ChunkHeader<E> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_name(name: &'static BStr, sh_type: u32, sh_flags: u64) -> ChunkHeader<E> {
|
||||
ChunkHeader { name, ..ChunkHeader::<E>::new("", sh_type, sh_flags) }
|
||||
pub fn with_name(name: &'static BStr, sh_type: u32, sh_flags: u64) -> Self {
|
||||
Self { name, ..Self::new("", sh_type, sh_flags) }
|
||||
}
|
||||
|
||||
pub fn is_alloc(&self) -> bool {
|
||||
@@ -236,10 +236,10 @@ pub struct OutputPhdr<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Arch> OutputPhdr<E> {
|
||||
pub fn new(sh_flags: u64) -> OutputPhdr<E> {
|
||||
pub fn new(sh_flags: u64) -> Self {
|
||||
let mut hdr = ChunkHeader::<E>::new("PHDR", 0, sh_flags);
|
||||
hdr.shdr.sh_addralign.set(E::WORD_SIZE as u64);
|
||||
OutputPhdr { hdr, phdrs: Vec::new() }
|
||||
Self { hdr, phdrs: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ pub struct NotePropertySection<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Arch> NotePropertySection<E> {
|
||||
pub fn new() -> NotePropertySection<E> {
|
||||
pub fn new() -> Self {
|
||||
let mut hdr = ChunkHeader::<E>::new(".note.gnu.property", SHT_NOTE, SHF_ALLOC as u64);
|
||||
hdr.shdr.sh_addralign.set(E::WORD_SIZE as u64);
|
||||
NotePropertySection { hdr, contents: Vec::new() }
|
||||
Self { hdr, contents: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -24,10 +24,10 @@ pub struct Ppc64OpdSection<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Layout> Ppc64OpdSection<E> {
|
||||
pub fn new() -> Ppc64OpdSection<E> {
|
||||
pub fn new() -> Self {
|
||||
let mut hdr = ChunkHeader::<E>::new(".opd", SHT_PROGBITS, (SHF_ALLOC | SHF_WRITE) as u64);
|
||||
hdr.shdr.sh_addralign.set(8);
|
||||
Ppc64OpdSection { hdr, symbols: Vec::new() }
|
||||
Self { hdr, symbols: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ unsafe impl Sync for OutputBuffer<'_> {}
|
||||
|
||||
impl<'a> OutputBuffer<'a> {
|
||||
#[inline]
|
||||
pub(crate) fn new(buf: &'a mut [u8]) -> OutputBuffer<'a> {
|
||||
pub(crate) fn new(buf: &'a mut [u8]) -> Self {
|
||||
OutputBuffer { ptr: buf.as_mut_ptr(), len: buf.len(), marker: PhantomData }
|
||||
}
|
||||
|
||||
@@ -117,8 +117,8 @@ impl<'a> OutputBuffer<'a> {
|
||||
pub const DYNREL_SHARD_SIZE: usize = 65536;
|
||||
|
||||
impl<E: Layout> OutputSection<E> {
|
||||
pub fn new(name: &'static BStr, sh_type: u32) -> OutputSection<E> {
|
||||
OutputSection {
|
||||
pub fn new(name: &'static BStr, sh_type: u32) -> Self {
|
||||
Self {
|
||||
hdr: ChunkHeader::<E>::with_name(name, sh_type, 0),
|
||||
members: Vec::new(),
|
||||
thunks: Vec::new(),
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ pub struct PltSection<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Arch> PltSection<E> {
|
||||
pub fn new() -> PltSection<E> {
|
||||
pub fn new() -> Self {
|
||||
let mut hdr =
|
||||
ChunkHeader::<E>::new(".plt", SHT_PROGBITS, (SHF_ALLOC | SHF_EXECINSTR) as u64);
|
||||
if E::IS_SPARC {
|
||||
@@ -29,7 +29,7 @@ impl<E: Arch> PltSection<E> {
|
||||
} else {
|
||||
hdr.shdr.sh_addralign.set(16);
|
||||
}
|
||||
PltSection { hdr, symbols: Vec::new() }
|
||||
Self { hdr, symbols: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@ pub struct PltGotSection<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Layout> PltGotSection<E> {
|
||||
pub fn new() -> PltGotSection<E> {
|
||||
pub fn new() -> Self {
|
||||
let mut hdr =
|
||||
ChunkHeader::<E>::new(".plt.got", SHT_PROGBITS, (SHF_ALLOC | SHF_EXECINSTR) as u64);
|
||||
hdr.shdr.sh_addralign.set(16);
|
||||
PltGotSection { hdr, symbols: Vec::new() }
|
||||
Self { hdr, symbols: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ pub struct RelDynSection<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Arch> RelDynSection<E> {
|
||||
pub fn new(args: &crate::cmdline::Args) -> RelDynSection<E> {
|
||||
pub fn new(args: &crate::cmdline::Args) -> Self {
|
||||
let (name, ty, android_ty) = if E::IS_RELA {
|
||||
(".rela.dyn", SHT_RELA, SHT_ANDROID_RELA)
|
||||
} else {
|
||||
@@ -33,7 +33,7 @@ impl<E: Arch> RelDynSection<E> {
|
||||
let mut hdr = ChunkHeader::<E>::new(name, ty, SHF_ALLOC as u64);
|
||||
hdr.shdr.sh_entsize.set(entsize);
|
||||
hdr.shdr.sh_addralign.set(align);
|
||||
RelDynSection { hdr, android_encoded: Vec::new(), keep_android_size: false }
|
||||
Self { hdr, android_encoded: Vec::new(), keep_android_size: false }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ pub struct RiscvAttributesSection<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Layout> RiscvAttributesSection<E> {
|
||||
pub fn new() -> RiscvAttributesSection<E> {
|
||||
RiscvAttributesSection {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
hdr: ChunkHeader::<E>::new(".riscv.attributes", SHT_RISCV_ATTRIBUTES, 0),
|
||||
contents: Vec::new(),
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@ pub struct SFrameSection<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Layout> SFrameSection<E> {
|
||||
pub fn new() -> SFrameSection<E> {
|
||||
pub fn new() -> Self {
|
||||
let mut hdr = ChunkHeader::<E>::new(".sframe", SHT_GNU_SFRAME, SHF_ALLOC as u64);
|
||||
hdr.shdr.sh_addralign.set(8);
|
||||
SFrameSection { hdr, header: SFrameHeader::<E>::default(), fdes: Vec::new() }
|
||||
Self { hdr, header: SFrameHeader::<E>::default(), fdes: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,10 +21,10 @@ pub struct VerdefSection<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Layout> VerdefSection<E> {
|
||||
pub fn new() -> VerdefSection<E> {
|
||||
pub fn new() -> Self {
|
||||
let mut hdr = ChunkHeader::<E>::new(".gnu.version_d", SHT_GNU_VERDEF, SHF_ALLOC as u64);
|
||||
hdr.shdr.sh_addralign.set(4);
|
||||
VerdefSection { hdr, contents: Vec::new() }
|
||||
Self { hdr, contents: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ pub struct VerneedSection<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Layout> VerneedSection<E> {
|
||||
pub fn new() -> VerneedSection<E> {
|
||||
pub fn new() -> Self {
|
||||
let mut hdr = ChunkHeader::<E>::new(".gnu.version_r", SHT_GNU_VERNEED, SHF_ALLOC as u64);
|
||||
hdr.shdr.sh_addralign.set(4);
|
||||
VerneedSection { hdr, contents: Vec::new() }
|
||||
Self { hdr, contents: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ pub struct VersymSection<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Layout> VersymSection<E> {
|
||||
pub fn new() -> VersymSection<E> {
|
||||
pub fn new() -> Self {
|
||||
let mut hdr = ChunkHeader::<E>::new(".gnu.version", SHT_GNU_VERSYM, SHF_ALLOC as u64);
|
||||
hdr.shdr.sh_entsize.set(2);
|
||||
hdr.shdr.sh_addralign.set(2);
|
||||
VersymSection { hdr, contents: Vec::new() }
|
||||
Self { hdr, contents: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -246,10 +246,10 @@ pub enum BuildId {
|
||||
impl BuildId {
|
||||
pub fn size(&self) -> usize {
|
||||
match self {
|
||||
BuildId::None => 0,
|
||||
BuildId::Hex(value) => value.len(),
|
||||
BuildId::Hash(size) => *size,
|
||||
BuildId::Uuid => 16,
|
||||
Self::None => 0,
|
||||
Self::Hex(value) => value.len(),
|
||||
Self::Hash(size) => *size,
|
||||
Self::Uuid => 16,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -396,7 +396,7 @@ pub struct ReaderContext {
|
||||
|
||||
impl ReaderContext {
|
||||
// Returns a context for the next file found inside the current file.
|
||||
pub fn next_child(&mut self) -> ReaderContext {
|
||||
pub fn next_child(&mut self) -> Self {
|
||||
let mut child = self.clone();
|
||||
child.pos.push(self.num_children);
|
||||
child.num_children = 0;
|
||||
@@ -553,7 +553,7 @@ pub struct Args {
|
||||
|
||||
impl Default for Args {
|
||||
fn default() -> Self {
|
||||
Args {
|
||||
Self {
|
||||
bsymbolic: BsymbolicKind::None,
|
||||
build_id: BuildId::default(),
|
||||
z_cet_report: CetReportKind::None,
|
||||
|
||||
+2
-2
@@ -269,7 +269,7 @@ pub struct Context<E: Arch> {
|
||||
}
|
||||
|
||||
impl<E: Arch> Context<E> {
|
||||
pub fn new(mut args: Args, cmdline_args: impl Into<Arc<[Cow<'static, OsStr>]>>) -> Context<E> {
|
||||
pub fn new(mut args: Args, cmdline_args: impl Into<Arc<[Cow<'static, OsStr>]>>) -> Self {
|
||||
let mut symbols = SymbolTable::new();
|
||||
let syms = SyntheticSymbols {
|
||||
entry: symbols.intern(crate::util::leak_bytes(std::mem::take(&mut args.entry))),
|
||||
@@ -279,7 +279,7 @@ impl<E: Arch> Context<E> {
|
||||
};
|
||||
let timers = if args.perf { Timers::new() } else { Timers::disabled() };
|
||||
|
||||
Context {
|
||||
Self {
|
||||
reldyn: RelDynSection::<E>::new(&args),
|
||||
got: GotSection::<E>::new(),
|
||||
gotplt: chunks::gotplt::new_header::<E>(&args),
|
||||
|
||||
+7
-7
@@ -445,17 +445,17 @@ impl<E: Endian> ElfWord for U32<E> {
|
||||
|
||||
#[inline(always)]
|
||||
fn new(value: u64) -> Self {
|
||||
U32::new(value as u32)
|
||||
Self::new(value as u32)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn get(&self) -> u64 {
|
||||
u64::from(U32::get(self))
|
||||
u64::from(Self::get(self))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn set(&mut self, value: u64) {
|
||||
U32::set(self, value as u32);
|
||||
Self::set(self, value as u32);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,17 +467,17 @@ impl<E: Endian> ElfWord for U64<E> {
|
||||
|
||||
#[inline(always)]
|
||||
fn new(value: u64) -> Self {
|
||||
U64::new(value)
|
||||
Self::new(value)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn get(&self) -> u64 {
|
||||
U64::get(self)
|
||||
Self::get(self)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn set(&mut self, value: u64) {
|
||||
U64::set(self, value);
|
||||
Self::set(self, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -620,7 +620,7 @@ impl UnsignedField for u8 {
|
||||
|
||||
#[inline(always)]
|
||||
fn set_u64(&mut self, value: u64) {
|
||||
*self = value as u8;
|
||||
*self = value as Self;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -93,8 +93,8 @@ struct NameType {
|
||||
}
|
||||
|
||||
impl NameType {
|
||||
fn new(hash: u64, kind: u8, name: &'static [u8]) -> NameType {
|
||||
NameType { hash_and_type: (hash << 8) | kind as u64, name: name.as_ptr() as usize }
|
||||
fn new(hash: u64, kind: u8, name: &'static [u8]) -> Self {
|
||||
Self { hash_and_type: (hash << 8) | kind as u64, name: name.as_ptr() as usize }
|
||||
}
|
||||
|
||||
fn hash(self) -> u64 {
|
||||
@@ -105,7 +105,7 @@ impl NameType {
|
||||
self.hash_and_type as u8
|
||||
}
|
||||
|
||||
fn same_name(self, other: NameType) -> bool {
|
||||
fn same_name(self, other: Self) -> bool {
|
||||
self.hash_and_type == other.hash_and_type
|
||||
// SAFETY: public names point into NUL-terminated debug sections
|
||||
// that remain live for the complete link.
|
||||
@@ -137,7 +137,7 @@ union NameRecord {
|
||||
}
|
||||
|
||||
impl NameRecord {
|
||||
fn new(hash: u64, kind: u8, name: &'static [u8]) -> NameRecord {
|
||||
fn new(hash: u64, kind: u8, name: &'static [u8]) -> Self {
|
||||
NameRecord { nametype: NameType::new(hash, kind, name) }
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ struct Reader<'a, E: Arch> {
|
||||
}
|
||||
|
||||
impl<'a, E: Arch> Reader<'a, E> {
|
||||
fn new(data: &'a [u8], pos: usize) -> Reader<'a, E> {
|
||||
fn new(data: &'a [u8], pos: usize) -> Self {
|
||||
Reader { data, pos, marker: std::marker::PhantomData }
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -107,8 +107,8 @@ impl Digest {
|
||||
hasher.update_u64(u64::from_le(self.lo));
|
||||
}
|
||||
|
||||
fn from_ne_bytes(bytes: [u8; 16]) -> Digest {
|
||||
Digest {
|
||||
fn from_ne_bytes(bytes: [u8; 16]) -> Self {
|
||||
Self {
|
||||
hi: u64::from_ne_bytes(bytes[..8].try_into().unwrap()),
|
||||
lo: u64::from_ne_bytes(bytes[8..].try_into().unwrap()),
|
||||
}
|
||||
@@ -165,9 +165,9 @@ struct DigestSlot {
|
||||
}
|
||||
|
||||
impl DigestMap {
|
||||
fn new(n: usize) -> DigestMap {
|
||||
fn new(n: usize) -> Self {
|
||||
let len = n.saturating_mul(2).next_power_of_two();
|
||||
DigestMap {
|
||||
Self {
|
||||
round: 1,
|
||||
mask: len - 1,
|
||||
slots: (0..len).map(|_| DigestSlot::default()).collect(),
|
||||
|
||||
+35
-35
@@ -45,12 +45,12 @@ impl NameLen {
|
||||
const LONG_NAME: usize = 240;
|
||||
|
||||
#[inline]
|
||||
fn new(len: usize) -> NameLen {
|
||||
fn new(len: usize) -> Self {
|
||||
if len < Self::LONG_NAME {
|
||||
return NameLen(len as u8);
|
||||
return Self(len as u8);
|
||||
}
|
||||
let log2 = (len - Self::LONG_NAME + 1).ilog2() as usize;
|
||||
NameLen((Self::LONG_NAME + log2.min(u8::MAX as usize - Self::LONG_NAME)) as u8)
|
||||
Self((Self::LONG_NAME + log2.min(u8::MAX as usize - Self::LONG_NAME)) as u8)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -136,8 +136,8 @@ pub trait FileInPool {
|
||||
}
|
||||
|
||||
impl<T: FileInPool> Default for FileList<T> {
|
||||
fn default() -> FileList<T> {
|
||||
FileList { pool: Vec::new(), live: Vec::new() }
|
||||
fn default() -> Self {
|
||||
Self { pool: Vec::new(), live: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,19 +340,19 @@ pub enum FileId {
|
||||
|
||||
impl FileId {
|
||||
pub fn is_dso(self) -> bool {
|
||||
matches!(self, FileId::Dso(_))
|
||||
matches!(self, Self::Dso(_))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ObjId> for FileId {
|
||||
fn from(id: ObjId) -> FileId {
|
||||
FileId::Obj(id)
|
||||
fn from(id: ObjId) -> Self {
|
||||
Self::Obj(id)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DsoId> for FileId {
|
||||
fn from(id: DsoId) -> FileId {
|
||||
FileId::Dso(id)
|
||||
fn from(id: DsoId) -> Self {
|
||||
Self::Dso(id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -404,8 +404,8 @@ pub struct InputFile<E: Layout> {
|
||||
}
|
||||
|
||||
impl<E: Layout> InputFile<E> {
|
||||
fn empty(filename: Cow<'static, str>) -> InputFile<E> {
|
||||
InputFile {
|
||||
fn empty(filename: Cow<'static, str>) -> Self {
|
||||
Self {
|
||||
mf: None,
|
||||
filename,
|
||||
priority: 0,
|
||||
@@ -432,7 +432,7 @@ impl<E: Layout> InputFile<E> {
|
||||
}
|
||||
|
||||
/// Reads the ELF and section headers.
|
||||
fn parse(mf: &'static MappedFile, display: &dyn fmt::Display) -> InputFile<E> {
|
||||
fn parse(mf: &'static MappedFile, display: &dyn fmt::Display) -> Self {
|
||||
let data = mf.data();
|
||||
if data.len() < std::mem::size_of::<ElfEhdr<E>>() {
|
||||
fatal!("{display}: file too small");
|
||||
@@ -464,12 +464,12 @@ impl<E: Layout> InputFile<E> {
|
||||
};
|
||||
let shdrs = records_from_bytes::<ElfShdr<E>>(shdr_bytes);
|
||||
|
||||
let mut file = InputFile {
|
||||
let mut file = Self {
|
||||
mf: Some(mf),
|
||||
is_little_endian: E::Endian::IS_LITTLE,
|
||||
e_flags: ehdr.e_flags.get(),
|
||||
shdrs,
|
||||
..InputFile::empty(mf.name.to_string_lossy())
|
||||
..Self::empty(mf.name.to_string_lossy())
|
||||
};
|
||||
|
||||
// e_shstrndx is a 16-bit field. If .shstrtab's section index is
|
||||
@@ -604,9 +604,9 @@ pub struct ComdatGroupRef {
|
||||
impl ComdatGroupRef {
|
||||
const IS_OWNER: u32 = 1 << 31;
|
||||
|
||||
fn new(sect_idx: u32, signature: SymbolId) -> ComdatGroupRef {
|
||||
fn new(sect_idx: u32, signature: SymbolId) -> Self {
|
||||
assert!(signature.0 < Self::IS_OWNER);
|
||||
ComdatGroupRef { sect_idx, signature_and_owner: signature.0 }
|
||||
Self { sect_idx, signature_and_owner: signature.0 }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -670,8 +670,8 @@ struct DecodedRelocations<R> {
|
||||
}
|
||||
|
||||
impl<R> DecodedRelocations<R> {
|
||||
fn new(records: Box<[R]>) -> DecodedRelocations<R> {
|
||||
DecodedRelocations { records: UnsafeCell::new(records) }
|
||||
fn new(records: Box<[R]>) -> Self {
|
||||
Self { records: UnsafeCell::new(records) }
|
||||
}
|
||||
|
||||
fn as_slice(&self) -> &[R] {
|
||||
@@ -1050,8 +1050,8 @@ impl<E: Arch> ObjectFile<E> {
|
||||
|
||||
/// Creates the internal object file that holds linker-synthesized
|
||||
/// symbols.
|
||||
pub fn internal() -> ObjectFile<E> {
|
||||
let mut file = ObjectFile::with_base(
|
||||
pub fn internal() -> Self {
|
||||
let mut file = Self::with_base(
|
||||
InputFile::<E>::empty(Cow::Borrowed("<internal>")),
|
||||
Path::new(""),
|
||||
);
|
||||
@@ -1060,8 +1060,8 @@ impl<E: Arch> ObjectFile<E> {
|
||||
file
|
||||
}
|
||||
|
||||
fn with_base(base: InputFile<E>, archive_name: &'static Path) -> ObjectFile<E> {
|
||||
ObjectFile {
|
||||
fn with_base(base: InputFile<E>, archive_name: &'static Path) -> Self {
|
||||
Self {
|
||||
num_elf_sections: base.shdrs.len(),
|
||||
base,
|
||||
archive_name,
|
||||
@@ -1105,10 +1105,10 @@ impl<E: Arch> ObjectFile<E> {
|
||||
|
||||
/// Opens an object file and reads its symbol table. Sections are read
|
||||
/// later, once COMDAT group selection is done.
|
||||
pub fn new(mf: &'static MappedFile, archive_name: &'static Path) -> ObjectFile<E> {
|
||||
pub fn new(mf: &'static MappedFile, archive_name: &'static Path) -> Self {
|
||||
let base =
|
||||
InputFile::<E>::parse(mf, &display_file(&mf.name.to_string_lossy(), archive_name));
|
||||
let mut file = ObjectFile::with_base(base, archive_name);
|
||||
let mut file = Self::with_base(base, archive_name);
|
||||
file.parse_symbols();
|
||||
file
|
||||
}
|
||||
@@ -1122,13 +1122,13 @@ impl<E: Arch> ObjectFile<E> {
|
||||
elf_syms: Vec<ElfSym<E>>,
|
||||
strtab: &'static [u8],
|
||||
comdat_keys: Vec<Option<&'static [u8]>>,
|
||||
) -> ObjectFile<E> {
|
||||
) -> Self {
|
||||
let mut base = InputFile::<E>::empty(mf.name.to_string_lossy());
|
||||
base.mf = Some(mf);
|
||||
base.elf_syms = Cow::Owned(elf_syms);
|
||||
base.symbol_strtab = strtab;
|
||||
base.first_global = 1;
|
||||
let mut file = ObjectFile::with_base(base, archive_name);
|
||||
let mut file = Self::with_base(base, archive_name);
|
||||
file.origin = ObjectOrigin::LtoInput;
|
||||
file.lto_comdat_signatures = vec![None; comdat_keys.len()];
|
||||
file.lto_comdat_discarded = vec![false; comdat_keys.len()];
|
||||
@@ -1352,7 +1352,7 @@ impl<E: Arch> ObjectFile<E> {
|
||||
let start = sh_offset as usize;
|
||||
let bytes = &data[start..start + sh_size as usize];
|
||||
let is_little_endian = self.base.is_little_endian;
|
||||
bytes.chunks_exact(4).skip(1).map(move |b| {
|
||||
bytes.as_chunks::<4>().0.iter().skip(1).map(move |b| {
|
||||
let b = [b[0], b[1], b[2], b[3]];
|
||||
if is_little_endian { u32::from_le_bytes(b) } else { u32::from_be_bytes(b) }
|
||||
})
|
||||
@@ -2135,7 +2135,7 @@ impl<E: Arch> ObjectFile<E> {
|
||||
|
||||
// We assume that FDEs for the same input sections are contiguous
|
||||
// in `fdes` vector.
|
||||
let section_of = |file: &ObjectFile<E>, fde: &FdeRecord| -> usize {
|
||||
let section_of = |file: &Self, fde: &FdeRecord| -> usize {
|
||||
let rel = fde.rels(file)[0];
|
||||
file.shndx_at_in(rel.r_sym() as usize)
|
||||
};
|
||||
@@ -2757,7 +2757,7 @@ pub struct SymtabEntries<'a> {
|
||||
}
|
||||
|
||||
impl<'a> SymtabEntries<'a> {
|
||||
pub fn new(syms: &'a mut [u8], xindex: Option<&'a mut [u8]>) -> SymtabEntries<'a> {
|
||||
pub fn new(syms: &'a mut [u8], xindex: Option<&'a mut [u8]>) -> Self {
|
||||
SymtabEntries { syms, xindex, len: 0 }
|
||||
}
|
||||
|
||||
@@ -2777,7 +2777,7 @@ impl<'a> SymtabBlock<'a> {
|
||||
globals: SymtabEntries<'a>,
|
||||
strtab: &'a mut [u8],
|
||||
strtab_base: u64,
|
||||
) -> SymtabBlock<'a> {
|
||||
) -> Self {
|
||||
SymtabBlock { locals, globals, strtab, strtab_base, strtab_len: 0 }
|
||||
}
|
||||
|
||||
@@ -3002,10 +3002,10 @@ impl<E: Arch> SharedFile<E> {
|
||||
DsoId(self.base.file_index)
|
||||
}
|
||||
|
||||
pub(crate) fn new(mf: &'static MappedFile, bins: &mut Bins<SymbolSlot>) -> SharedFile<E> {
|
||||
pub(crate) fn new(mf: &'static MappedFile, bins: &mut Bins<SymbolSlot>) -> Self {
|
||||
let base =
|
||||
InputFile::<E>::parse(mf, &display_file(&mf.name.to_string_lossy(), Path::new("")));
|
||||
let mut file = SharedFile {
|
||||
let mut file = Self {
|
||||
base,
|
||||
soname: b"",
|
||||
version_strings: Vec::new(),
|
||||
@@ -3428,7 +3428,7 @@ pub(crate) struct SymbolEditor<'a> {
|
||||
unsafe impl Sync for SymbolEditor<'_> {}
|
||||
|
||||
impl<'a> SymbolEditor<'a> {
|
||||
pub(crate) fn new(symbols: &'a mut [Symbol]) -> SymbolEditor<'a> {
|
||||
pub(crate) fn new(symbols: &'a mut [Symbol]) -> Self {
|
||||
SymbolEditor { symbols: symbols.as_mut_ptr(), len: symbols.len(), _symbols: PhantomData }
|
||||
}
|
||||
|
||||
@@ -3466,7 +3466,7 @@ impl<'a, E: Arch> SymbolResolver<'a, E> {
|
||||
objs: &'a FileList<ObjectFile<E>>,
|
||||
dsos: &'a FileList<SharedFile<E>>,
|
||||
default_version: u16,
|
||||
) -> SymbolResolver<'a, E> {
|
||||
) -> Self {
|
||||
SymbolResolver { editor: SymbolEditor::new(symbols), objs, dsos, default_version }
|
||||
}
|
||||
|
||||
|
||||
+25
-25
@@ -35,8 +35,8 @@ impl SectionRef {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn decode(value: u64) -> SectionRef {
|
||||
SectionRef { file: ObjId((value >> 32) as u32), shndx: value as u32 }
|
||||
pub(crate) fn decode(value: u64) -> Self {
|
||||
Self { file: ObjId((value >> 32) as u32), shndx: value as u32 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,20 +52,20 @@ const _: () = assert!(std::mem::size_of::<InputSectionId>() == 8);
|
||||
|
||||
impl InputSectionId {
|
||||
/// A placeholder used only while a member array is being filled.
|
||||
pub(crate) const NONE: InputSectionId = InputSectionId { file: ObjId(0), index: u32::MAX };
|
||||
pub(crate) const NONE: Self = Self { file: ObjId(0), index: u32::MAX };
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn new(file: ObjId, index: u32) -> InputSectionId {
|
||||
pub(crate) fn new(file: ObjId, index: u32) -> Self {
|
||||
// Origin reserves the low two bits of its u64 representation for a
|
||||
// tag, leaving 62 bits for this ID.
|
||||
debug_assert!(file.0 < 1 << 30);
|
||||
debug_assert_ne!(index, u32::MAX);
|
||||
InputSectionId { file, index }
|
||||
Self { file, index }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) const fn from_raw(value: u64) -> InputSectionId {
|
||||
InputSectionId { file: ObjId((value >> 32) as u32), index: (value as u32).wrapping_sub(1) }
|
||||
pub(crate) const fn from_raw(value: u64) -> Self {
|
||||
Self { file: ObjId((value >> 32) as u32), index: (value as u32).wrapping_sub(1) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -100,8 +100,8 @@ impl FragmentRef {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn from_raw(value: u64) -> FragmentRef {
|
||||
FragmentRef {
|
||||
pub(crate) fn from_raw(value: u64) -> Self {
|
||||
Self {
|
||||
section: MergedSectionId((value >> 32) as u32),
|
||||
entry: EntryId::from_raw(value as u32),
|
||||
}
|
||||
@@ -171,18 +171,18 @@ impl InputSectionExtra for () {}
|
||||
impl InputSectionExtra for u32 {
|
||||
#[inline]
|
||||
fn empty() -> Self {
|
||||
u32::MAX
|
||||
Self::MAX
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn exidx(&self) -> Option<u32> {
|
||||
(*self != u32::MAX).then_some(*self)
|
||||
(*self != Self::MAX).then_some(*self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_exidx(&mut self, exidx: u32) {
|
||||
debug_assert_ne!(exidx, 0);
|
||||
debug_assert_ne!(exidx, u32::MAX);
|
||||
debug_assert_ne!(exidx, Self::MAX);
|
||||
*self = exidx;
|
||||
}
|
||||
}
|
||||
@@ -268,7 +268,7 @@ impl<E: Arch> InputSection<E> {
|
||||
shndx: u32,
|
||||
shdr: &ElfShdr<E>,
|
||||
name: &'static BStr,
|
||||
) -> InputSection<E> {
|
||||
) -> Self {
|
||||
let contents: &'static [u8] =
|
||||
if shdr.sh_type.get() == SHT_NOBITS || (shndx as usize) >= file.num_elf_sections {
|
||||
&[]
|
||||
@@ -283,7 +283,7 @@ impl<E: Arch> InputSection<E> {
|
||||
(shdr.sh_size.get(), to_p2align(shdr.sh_addralign.get()))
|
||||
};
|
||||
|
||||
let mut isec = InputSection {
|
||||
let mut isec = Self {
|
||||
file: file_id,
|
||||
shndx,
|
||||
name_offset: if (shndx as usize) < file.num_elf_sections {
|
||||
@@ -1236,8 +1236,8 @@ impl RelocationSpan {
|
||||
#[inline]
|
||||
fn rels<E: Arch>(self, file: &ObjectFile<E>) -> &[E::Rel] {
|
||||
match self {
|
||||
RelocationSpan::Input(data) => rels_from_bytes::<E>(data),
|
||||
RelocationSpan::SideTable(relsec_idx) => file.relocations(Some(relsec_idx)),
|
||||
Self::Input(data) => rels_from_bytes::<E>(data),
|
||||
Self::SideTable(relsec_idx) => file.relocations(Some(relsec_idx)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1316,8 +1316,8 @@ pub struct FdeRecord {
|
||||
|
||||
impl FdeRecord {
|
||||
#[inline]
|
||||
pub fn new(input_offset: u32, rel_idx: u32) -> FdeRecord {
|
||||
FdeRecord {
|
||||
pub fn new(input_offset: u32, rel_idx: u32) -> Self {
|
||||
Self {
|
||||
input_offset,
|
||||
output_offset: 0,
|
||||
rel_idx,
|
||||
@@ -1404,8 +1404,8 @@ pub struct SectionFragment {
|
||||
|
||||
impl SectionFragment {
|
||||
#[inline]
|
||||
pub fn new(is_alive: bool) -> SectionFragment {
|
||||
SectionFragment {
|
||||
pub fn new(is_alive: bool) -> Self {
|
||||
Self {
|
||||
p2align: AtomicU8::new(0),
|
||||
offset: AtomicU64::new(0),
|
||||
is_alive: AtomicBool::new(is_alive),
|
||||
@@ -1474,9 +1474,9 @@ impl MergeInfo {
|
||||
parent: MergedSectionId,
|
||||
input_index: u32,
|
||||
section: &InputSection<E>,
|
||||
) -> MergeInfo {
|
||||
) -> Self {
|
||||
section.kill();
|
||||
MergeInfo {
|
||||
Self {
|
||||
parent,
|
||||
p2align: section.p2align(),
|
||||
shndx: section.shndx,
|
||||
@@ -1642,16 +1642,16 @@ const SECTION_INDEX_MASK: u32 = !HAS_MERGE_INFO;
|
||||
|
||||
impl<E: Arch> Default for SectionList<E> {
|
||||
fn default() -> Self {
|
||||
SectionList { indices: Vec::new(), inputs: Vec::new(), merge_info: Vec::new() }
|
||||
Self { indices: Vec::new(), inputs: Vec::new(), merge_info: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Arch> SectionList<E> {
|
||||
/// A list for `nsections` section indices, none with a section yet.
|
||||
pub fn new(nsections: usize, additional: usize) -> SectionList<E> {
|
||||
pub fn new(nsections: usize, additional: usize) -> Self {
|
||||
let mut indices = vec![0; nsections];
|
||||
indices.reserve(additional);
|
||||
SectionList {
|
||||
Self {
|
||||
indices,
|
||||
// Most ELF headers describe relocations or metadata rather than
|
||||
// InputSections. Let this vector grow with the sections actually
|
||||
|
||||
+6
-6
@@ -137,12 +137,12 @@ struct TagValue {
|
||||
}
|
||||
|
||||
impl TagValue {
|
||||
fn int(tag: c_int, val: c_int) -> TagValue {
|
||||
TagValue { tag, data: TagData { val } }
|
||||
fn int(tag: c_int, val: c_int) -> Self {
|
||||
Self { tag, data: TagData { val } }
|
||||
}
|
||||
|
||||
fn ptr(tag: c_int, ptr: *const c_void) -> TagValue {
|
||||
TagValue { tag, data: TagData { ptr } }
|
||||
fn ptr(tag: c_int, ptr: *const c_void) -> Self {
|
||||
Self { tag, data: TagData { ptr } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,9 +227,9 @@ struct ClaimedSymbol {
|
||||
}
|
||||
|
||||
impl ClaimedSymbol {
|
||||
unsafe fn from_plugin(sym: &PluginSymbol) -> ClaimedSymbol {
|
||||
unsafe fn from_plugin(sym: &PluginSymbol) -> Self {
|
||||
let bytes = |p: *const c_char| unsafe { CStr::from_ptr(p) }.to_bytes().to_vec();
|
||||
ClaimedSymbol {
|
||||
Self {
|
||||
name: bytes(sym.name),
|
||||
comdat_key: (!sym.comdat_key.is_null()).then(|| bytes(sym.comdat_key)),
|
||||
def: sym.kinds.def,
|
||||
|
||||
+10
-10
@@ -83,10 +83,10 @@ pub struct MappedFile {
|
||||
pub given_fullpath: bool,
|
||||
|
||||
/// The archive this file is a member of.
|
||||
pub parent: Option<&'static MappedFile>,
|
||||
pub parent: Option<&'static Self>,
|
||||
|
||||
/// The thin archive this file is a member of.
|
||||
pub thin_parent: Option<&'static MappedFile>,
|
||||
pub thin_parent: Option<&'static Self>,
|
||||
|
||||
// For --dependency-file
|
||||
pub is_dependency: AtomicBool,
|
||||
@@ -98,7 +98,7 @@ unsafe impl Send for MappedFile {}
|
||||
unsafe impl Sync for MappedFile {}
|
||||
|
||||
impl MappedFile {
|
||||
fn open_impl(path: &Path) -> io::Result<&'static MappedFile> {
|
||||
fn open_impl(path: &Path) -> io::Result<&'static Self> {
|
||||
let file = File::open(path)?;
|
||||
|
||||
let display = path.display();
|
||||
@@ -136,7 +136,7 @@ impl MappedFile {
|
||||
NonNull::from(Box::leak(Box::new(map)).as_mut())
|
||||
};
|
||||
|
||||
let mf = util::leak(MappedFile {
|
||||
let mf = util::leak(Self {
|
||||
name: path.to_path_buf(),
|
||||
data,
|
||||
given_fullpath: true,
|
||||
@@ -152,7 +152,7 @@ impl MappedFile {
|
||||
}
|
||||
|
||||
/// Opens a file, returning `None` if it doesn't exist.
|
||||
pub fn open(path: impl AsRef<Path>) -> Option<&'static MappedFile> {
|
||||
pub fn open(path: impl AsRef<Path>) -> Option<&'static Self> {
|
||||
let path = path.as_ref();
|
||||
match Self::open_impl(path) {
|
||||
Ok(mf) => Some(mf),
|
||||
@@ -162,17 +162,17 @@ impl MappedFile {
|
||||
}
|
||||
|
||||
/// Opens a file that must exist.
|
||||
pub fn must_open(path: impl AsRef<Path>) -> &'static MappedFile {
|
||||
pub fn must_open(path: impl AsRef<Path>) -> &'static Self {
|
||||
let path = path.as_ref();
|
||||
Self::open_impl(path).unwrap_or_else(|e| fatal!("cannot open {}: {e}", path.display()))
|
||||
}
|
||||
|
||||
/// Returns a view of a member of this archive.
|
||||
pub fn slice(&'static self, name: PathBuf, start: usize, size: usize) -> &'static MappedFile {
|
||||
pub fn slice(&'static self, name: PathBuf, start: usize, size: usize) -> &'static Self {
|
||||
assert!(start <= self.size() && size <= self.size() - start);
|
||||
// SAFETY: the checked range lies in the same allocation.
|
||||
let data = unsafe { self.data.cast::<u8>().add(start) };
|
||||
let mf = util::leak(MappedFile {
|
||||
let mf = util::leak(Self {
|
||||
name,
|
||||
data: NonNull::slice_from_raw_parts(data, size),
|
||||
given_fullpath: true,
|
||||
@@ -185,9 +185,9 @@ impl MappedFile {
|
||||
}
|
||||
|
||||
/// Opens a member whose bytes are stored outside this thin archive.
|
||||
pub fn open_thin_member(&'static self, chroot: &Path, path: &Path) -> &'static MappedFile {
|
||||
pub fn open_thin_member(&'static self, chroot: &Path, path: &Path) -> &'static Self {
|
||||
let member = must_open_file(chroot, path);
|
||||
util::leak(MappedFile {
|
||||
util::leak(Self {
|
||||
name: member.name.clone(),
|
||||
data: member.data,
|
||||
given_fullpath: true,
|
||||
|
||||
+6
-6
@@ -205,7 +205,7 @@ impl OutputFile {
|
||||
size: u64,
|
||||
perm: u32,
|
||||
overwrite_in_place: bool,
|
||||
) -> OutputFile {
|
||||
) -> Self {
|
||||
let path = crate::mapped_file::apply_chroot(&args.chroot, &args.output);
|
||||
let mut output = Self::open_impl(&path, size, perm, overwrite_in_place);
|
||||
if let Some(filler) = args.filler {
|
||||
@@ -214,11 +214,11 @@ impl OutputFile {
|
||||
output
|
||||
}
|
||||
|
||||
fn open_impl(path: &Path, size: u64, perm: u32, overwrite_in_place: bool) -> OutputFile {
|
||||
fn open_impl(path: &Path, size: u64, perm: u32, overwrite_in_place: bool) -> Self {
|
||||
let is_special =
|
||||
path == Path::new("-") || std::fs::metadata(path).is_ok_and(|m| !m.is_file());
|
||||
if is_special {
|
||||
return OutputFile {
|
||||
return Self {
|
||||
path: path.to_path_buf(),
|
||||
tmp_path: None,
|
||||
storage: Storage::Memory(vec![0; size as usize]),
|
||||
@@ -268,7 +268,7 @@ impl OutputFile {
|
||||
|
||||
let map = map_file(&file, size)
|
||||
.unwrap_or_else(|e| fatal!("{}: mmap failed: {e}", path.display()));
|
||||
let output = OutputFile {
|
||||
let output = Self {
|
||||
path: path.to_path_buf(),
|
||||
tmp_path: Some(tmp),
|
||||
storage: Storage::File { file, map, len: size as usize },
|
||||
@@ -285,7 +285,7 @@ impl OutputFile {
|
||||
/// stale one is not picked up by accident; [`Self::resize`] gives it its
|
||||
/// size.
|
||||
#[cfg(not(windows))]
|
||||
pub fn open_locked(path: &Path, perm: u32) -> OutputFile {
|
||||
pub fn open_locked(path: &Path, perm: u32) -> Self {
|
||||
let mut file = open_options(perm)
|
||||
.read(true)
|
||||
.write(true)
|
||||
@@ -301,7 +301,7 @@ impl OutputFile {
|
||||
// it's ready.
|
||||
file.write_all(&[0; 256])
|
||||
.unwrap_or_else(|e| fatal!("{}: write failed: {e}", path.display()));
|
||||
OutputFile {
|
||||
Self {
|
||||
path: path.to_path_buf(),
|
||||
tmp_path: None,
|
||||
storage: Storage::File { file, map: None, len: 0 },
|
||||
|
||||
+2
-2
@@ -483,8 +483,8 @@ unsafe impl Send for ComdatSymbolSlot {}
|
||||
unsafe impl Sync for ComdatSymbolSlot {}
|
||||
|
||||
impl ComdatSymbolSlot {
|
||||
fn new(group: &mut ComdatGroupRef) -> ComdatSymbolSlot {
|
||||
ComdatSymbolSlot(NonNull::from(group.signature_word_mut()))
|
||||
fn new(group: &mut ComdatGroupRef) -> Self {
|
||||
Self(NonNull::from(group.signature_word_mut()))
|
||||
}
|
||||
|
||||
fn assign(self, id: SymbolId) {
|
||||
|
||||
+26
-26
@@ -32,10 +32,10 @@ pub struct SymbolId(pub u32);
|
||||
|
||||
impl SymbolId {
|
||||
// Local symbols in discarded COMDAT sections all use one zero-valued symbol.
|
||||
pub const DISCARDED_COMDAT: SymbolId = SymbolId(0);
|
||||
pub const DISCARDED_COMDAT: Self = Self(0);
|
||||
|
||||
/// No symbol. Used where an optional id must remain four bytes.
|
||||
pub const NONE: SymbolId = SymbolId(u32::MAX);
|
||||
pub const NONE: Self = Self(u32::MAX);
|
||||
|
||||
#[inline]
|
||||
pub fn index(self) -> usize {
|
||||
@@ -70,23 +70,23 @@ pub(crate) enum OriginValue {
|
||||
}
|
||||
|
||||
impl Origin {
|
||||
const NONE: Origin = Origin(0);
|
||||
const NONE: Self = Self(0);
|
||||
|
||||
fn new(value: OriginValue) -> Origin {
|
||||
fn new(value: OriginValue) -> Self {
|
||||
match value {
|
||||
OriginValue::None => Origin::NONE,
|
||||
OriginValue::None => Self::NONE,
|
||||
OriginValue::InputSection(section) => {
|
||||
debug_assert_ne!(section, InputSectionId::NONE);
|
||||
Origin(section.raw() << 2 | SECTION_TAG)
|
||||
Self(section.raw() << 2 | SECTION_TAG)
|
||||
}
|
||||
OriginValue::OutputChunk(chunk) => Origin(u64::from(chunk.0) << 2 | CHUNK_TAG),
|
||||
OriginValue::OutputChunk(chunk) => Self(u64::from(chunk.0) << 2 | CHUNK_TAG),
|
||||
OriginValue::Fragment(fragment) => {
|
||||
// FragmentRef contains two u32 indices. One billion merged sections
|
||||
// are enough to leave the low two bits available for the tag.
|
||||
assert!(fragment.section.0 < 1 << 30, "too many merged sections");
|
||||
Origin(fragment.raw() << 2 | FRAGMENT_TAG)
|
||||
Self(fragment.raw() << 2 | FRAGMENT_TAG)
|
||||
}
|
||||
OriginValue::Symbol(symbol) => Origin(u64::from(symbol.0) << 2 | SYMBOL_TAG),
|
||||
OriginValue::Symbol(symbol) => Self(u64::from(symbol.0) << 2 | SYMBOL_TAG),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,8 +134,8 @@ pub struct AddrFlags {
|
||||
}
|
||||
|
||||
impl AddrFlags {
|
||||
pub const NO_PLT: AddrFlags = AddrFlags { no_plt: true, no_opd: false };
|
||||
pub const NO_OPD: AddrFlags = AddrFlags { no_plt: false, no_opd: true };
|
||||
pub const NO_PLT: Self = Self { no_plt: true, no_opd: false };
|
||||
pub const NO_OPD: Self = Self { no_plt: false, no_opd: true };
|
||||
}
|
||||
|
||||
// Rarely used fields for dynamic symbols. Because mold allocates tens of
|
||||
@@ -187,12 +187,12 @@ impl SymbolFile {
|
||||
const NONE: u32 = u32::MAX;
|
||||
|
||||
#[inline]
|
||||
fn none() -> SymbolFile {
|
||||
SymbolFile(Self::NONE)
|
||||
fn none() -> Self {
|
||||
Self(Self::NONE)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn some(file: FileId) -> SymbolFile {
|
||||
fn some(file: FileId) -> Self {
|
||||
let raw = match file {
|
||||
FileId::Obj(id) => {
|
||||
debug_assert!(id.0 < Self::DSO);
|
||||
@@ -203,7 +203,7 @@ impl SymbolFile {
|
||||
id.0 | Self::DSO
|
||||
}
|
||||
};
|
||||
SymbolFile(raw)
|
||||
Self(raw)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -462,9 +462,9 @@ symbol_bits! {
|
||||
|
||||
impl Symbol {
|
||||
#[inline]
|
||||
pub fn new(name: &'static BStr) -> Symbol {
|
||||
pub fn new(name: &'static BStr) -> Self {
|
||||
let name_len = u32::try_from(name.len()).expect("symbol name is larger than 4 GiB");
|
||||
Symbol {
|
||||
Self {
|
||||
name_ptr: name.as_ptr() as usize,
|
||||
name_len,
|
||||
mu: AtomicU8::new(0),
|
||||
@@ -550,7 +550,7 @@ impl Symbol {
|
||||
///
|
||||
/// `ptr` must point to a live Symbol.
|
||||
#[inline]
|
||||
pub(crate) unsafe fn skip_dso_at(ptr: *const Symbol) -> bool {
|
||||
pub(crate) unsafe fn skip_dso_at(ptr: *const Self) -> bool {
|
||||
let mu = unsafe { std::ptr::addr_of!((*ptr).mu) };
|
||||
unsafe { &*mu }.load(Ordering::Relaxed) & SYMBOL_SKIP_DSO != 0
|
||||
}
|
||||
@@ -564,8 +564,8 @@ impl Symbol {
|
||||
/// must use this function.
|
||||
#[inline]
|
||||
pub(crate) unsafe fn with_resolution_lock<R>(
|
||||
ptr: *mut Symbol,
|
||||
f: impl FnOnce(&mut Symbol) -> R,
|
||||
ptr: *mut Self,
|
||||
f: impl FnOnce(&mut Self) -> R,
|
||||
) -> R {
|
||||
let mu = unsafe { std::ptr::addr_of!((*ptr).mu) };
|
||||
let mut unlocked = 0;
|
||||
@@ -1332,8 +1332,8 @@ impl<S> Default for Bins<S> {
|
||||
}
|
||||
|
||||
impl<S> Bins<S> {
|
||||
pub fn new() -> Bins<S> {
|
||||
Bins((0..NUM_SHARDS).map(|_| Vec::new()).collect())
|
||||
pub fn new() -> Self {
|
||||
Self((0..NUM_SHARDS).map(|_| Vec::new()).collect())
|
||||
}
|
||||
|
||||
/// Records `key` and the slot that receives its symbol id.
|
||||
@@ -1371,8 +1371,8 @@ unsafe impl Sync for SymbolSlot {}
|
||||
|
||||
impl SymbolSlot {
|
||||
#[inline]
|
||||
pub(crate) fn new(slot: &mut SymbolId) -> SymbolSlot {
|
||||
SymbolSlot(NonNull::from(slot))
|
||||
pub(crate) fn new(slot: &mut SymbolId) -> Self {
|
||||
Self(NonNull::from(slot))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -1514,8 +1514,8 @@ impl Default for SymbolTable {
|
||||
}
|
||||
|
||||
impl SymbolTable {
|
||||
pub fn new() -> SymbolTable {
|
||||
let mut table = SymbolTable {
|
||||
pub fn new() -> Self {
|
||||
let mut table = Self {
|
||||
symbols: Vec::new(),
|
||||
aux: Vec::new(),
|
||||
shards: (0..NUM_SHARDS).map(|_| ShardMap::default()).collect(),
|
||||
|
||||
@@ -141,7 +141,7 @@ fn zlib_compress(input: &[u8], level: u32) -> Vec<u8> {
|
||||
}
|
||||
|
||||
impl Compressor {
|
||||
pub fn zlib(input: &[u8], level: u32) -> Compressor {
|
||||
pub fn zlib(input: &[u8], level: u32) -> Self {
|
||||
// Compress each shard
|
||||
let (shards, adlers): (Vec<Vec<u8>>, Vec<u32>) = input
|
||||
.par_chunks(SHARD_SIZE)
|
||||
@@ -153,30 +153,30 @@ impl Compressor {
|
||||
for (adler, shard) in adlers.iter().zip(input.chunks(SHARD_SIZE)).skip(1) {
|
||||
checksum = adler32_combine(checksum, *adler, shard.len() as u64);
|
||||
}
|
||||
Compressor::Zlib { shards, checksum }
|
||||
Self::Zlib { shards, checksum }
|
||||
}
|
||||
|
||||
pub fn zstd(input: &[u8], level: i32) -> Compressor {
|
||||
pub fn zstd(input: &[u8], level: i32) -> Self {
|
||||
// Compress each shard
|
||||
let shards = input
|
||||
.par_chunks(SHARD_SIZE)
|
||||
.map(|shard| zstd::bulk::compress(shard, level).expect("zstd compression failed"))
|
||||
.collect();
|
||||
Compressor::Zstd { shards }
|
||||
Self::Zstd { shards }
|
||||
}
|
||||
|
||||
pub fn compressed_size(&self) -> usize {
|
||||
// Comput the total size
|
||||
match self {
|
||||
// the header and the trailer
|
||||
Compressor::Zlib { shards, .. } => 8 + shards.iter().map(Vec::len).sum::<usize>(),
|
||||
Compressor::Zstd { shards } => shards.iter().map(Vec::len).sum(),
|
||||
Self::Zlib { shards, .. } => 8 + shards.iter().map(Vec::len).sum::<usize>(),
|
||||
Self::Zstd { shards } => shards.iter().map(Vec::len).sum(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_to(&self, buf: &mut [u8]) {
|
||||
match self {
|
||||
Compressor::Zlib { shards, checksum } => {
|
||||
Self::Zlib { shards, checksum } => {
|
||||
// Write a zlib-format header
|
||||
buf[0] = 0x78;
|
||||
buf[1] = 0x9c;
|
||||
@@ -194,7 +194,7 @@ impl Compressor {
|
||||
buf[pos + 1] = 0;
|
||||
buf[pos + 2..pos + 6].copy_from_slice(&checksum.to_be_bytes());
|
||||
}
|
||||
Compressor::Zstd { shards } => {
|
||||
Self::Zstd { shards } => {
|
||||
// Copy compressed data
|
||||
let mut pos = 0;
|
||||
for shard in shards {
|
||||
|
||||
@@ -123,8 +123,8 @@ impl EntryId {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn from_raw(raw: u32) -> EntryId {
|
||||
EntryId(raw)
|
||||
pub(crate) fn from_raw(raw: u32) -> Self {
|
||||
Self(raw)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ unsafe impl<T: Send + Sync> Sync for ConcurrentMap<T> {}
|
||||
impl<T> Default for ConcurrentMap<T> {
|
||||
/// A map without buckets, to be replaced before use.
|
||||
fn default() -> Self {
|
||||
ConcurrentMap { entries: ptr::null_mut(), nbuckets: 0 }
|
||||
Self { entries: ptr::null_mut(), nbuckets: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ impl<T> ConcurrentMap<T> {
|
||||
// SAFETY: the range is the fresh allocation; the advice is only a
|
||||
// hint on targets that support it.
|
||||
unsafe { crate::util::madvise_hugepage(entries.cast(), bufsize) };
|
||||
ConcurrentMap { entries, nbuckets }
|
||||
Self { entries, nbuckets }
|
||||
}
|
||||
|
||||
fn bufsize(nbuckets: usize) -> usize {
|
||||
@@ -352,7 +352,7 @@ pub struct FrozenMap<T>(ConcurrentMap<T>);
|
||||
|
||||
impl<T> Default for FrozenMap<T> {
|
||||
fn default() -> Self {
|
||||
FrozenMap(ConcurrentMap::default())
|
||||
Self(ConcurrentMap::default())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -39,7 +39,7 @@ struct Pattern {
|
||||
}
|
||||
|
||||
impl Pattern {
|
||||
fn compile(mut pat: &[u8], value: i64) -> Option<Pattern> {
|
||||
fn compile(mut pat: &[u8], value: i64) -> Option<Self> {
|
||||
let mut tokens: Vec<Token> = Vec::new();
|
||||
|
||||
while let Some((&c, rest)) = pat.split_first() {
|
||||
@@ -123,7 +123,7 @@ impl Pattern {
|
||||
_ => push_char(&mut tokens, c),
|
||||
}
|
||||
}
|
||||
Some(Pattern { tokens, value })
|
||||
Some(Self { tokens, value })
|
||||
}
|
||||
|
||||
fn matches(&self, s: &[u8]) -> bool {
|
||||
@@ -213,7 +213,7 @@ struct Nfa {
|
||||
}
|
||||
|
||||
impl Nfa {
|
||||
fn compile(patterns: &[Pattern]) -> Nfa {
|
||||
fn compile(patterns: &[Pattern]) -> Self {
|
||||
let mut num_states = 0;
|
||||
for pattern in patterns {
|
||||
num_states += 1;
|
||||
@@ -227,7 +227,7 @@ impl Nfa {
|
||||
}
|
||||
|
||||
let num_words = num_states.div_ceil(64);
|
||||
let mut nfa = Nfa {
|
||||
let mut nfa = Self {
|
||||
initial_states: vec![0; num_words],
|
||||
star_states: vec![0; num_words],
|
||||
accept_states: vec![0; num_words],
|
||||
@@ -328,7 +328,7 @@ struct TrieNode {
|
||||
|
||||
impl Default for TrieNode {
|
||||
fn default() -> Self {
|
||||
TrieNode { value: -1, suffix_link: -1, first_child: -1, next_sibling: -1, ch: 0 }
|
||||
Self { value: -1, suffix_link: -1, first_child: -1, next_sibling: -1, ch: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ impl HyperLogLog {
|
||||
/// Combines two estimators, as if every value had been inserted into
|
||||
/// one of them.
|
||||
#[inline]
|
||||
pub fn merged(mut self, other: &HyperLogLog) -> HyperLogLog {
|
||||
pub fn merged(mut self, other: &Self) -> Self {
|
||||
for (a, b) in self.registers.iter_mut().zip(&other.registers) {
|
||||
*a = (*a).max(*b);
|
||||
}
|
||||
@@ -43,7 +43,7 @@ impl HyperLogLog {
|
||||
|
||||
impl Default for HyperLogLog {
|
||||
fn default() -> Self {
|
||||
HyperLogLog { registers: [0; Self::NUM_REGISTERS] }
|
||||
Self { registers: [0; Self::NUM_REGISTERS] }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -18,8 +18,8 @@ pub struct Counter {
|
||||
}
|
||||
|
||||
impl Counter {
|
||||
pub const fn new(name: &'static str) -> Counter {
|
||||
Counter { name, value: AtomicI64::new(0), registered: Once::new() }
|
||||
pub const fn new(name: &'static str) -> Self {
|
||||
Self { name, value: AtomicI64::new(0), registered: Once::new() }
|
||||
}
|
||||
|
||||
pub fn enable() {
|
||||
@@ -165,12 +165,12 @@ impl Default for Timers {
|
||||
|
||||
impl Timers {
|
||||
pub fn new() -> Self {
|
||||
Timers { records: Some(Arc::new(Mutex::new(Vec::new()))) }
|
||||
Self { records: Some(Arc::new(Mutex::new(Vec::new()))) }
|
||||
}
|
||||
|
||||
/// Skips clock reads, system calls and shared recording when --perf is off.
|
||||
pub fn disabled() -> Self {
|
||||
Timers { records: None }
|
||||
Self { records: None }
|
||||
}
|
||||
|
||||
fn inactive(&self) -> Timer {
|
||||
@@ -257,7 +257,7 @@ impl Timer {
|
||||
/// Starts a timer nested in this one. Timers started from parallel
|
||||
/// tasks name their parent this way, since which timer started last
|
||||
/// says nothing about nesting then.
|
||||
pub fn child(&self, name: impl std::fmt::Display) -> Timer {
|
||||
pub fn child(&self, name: impl std::fmt::Display) -> Self {
|
||||
self.timers.start_child(name, Some(self.index))
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -77,8 +77,8 @@ fn encode_path(basedir: &OsStr, path: &Path) -> Vec<u8> {
|
||||
}
|
||||
|
||||
impl TarWriter {
|
||||
pub fn open(output_path: &Path, basedir: &OsStr) -> io::Result<TarWriter> {
|
||||
Ok(TarWriter { out: File::create(output_path)?, basedir: basedir.to_os_string() })
|
||||
pub fn open(output_path: &Path, basedir: &OsStr) -> io::Result<Self> {
|
||||
Ok(Self { out: File::create(output_path)?, basedir: basedir.to_os_string() })
|
||||
}
|
||||
|
||||
pub fn append(&mut self, path: &Path, data: &[u8]) -> io::Result<()> {
|
||||
|
||||
+8
-8
@@ -62,12 +62,12 @@ struct Target {
|
||||
}
|
||||
|
||||
impl Target {
|
||||
fn native(machine: String) -> Target {
|
||||
Target { label: machine.clone(), machine, triple: None, cpu: None }
|
||||
fn native(machine: String) -> Self {
|
||||
Self { label: machine.clone(), machine, triple: None, cpu: None }
|
||||
}
|
||||
|
||||
fn cross(machine: String, triple: String) -> Target {
|
||||
Target { label: machine.clone(), machine, triple: Some(triple), cpu: None }
|
||||
fn cross(machine: String, triple: String) -> Self {
|
||||
Self { label: machine.clone(), machine, triple: Some(triple), cpu: None }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,9 +107,9 @@ enum Outcome {
|
||||
impl Outcome {
|
||||
fn status(self) -> &'static str {
|
||||
match self {
|
||||
Outcome::Pass => "pass",
|
||||
Outcome::Skip => "skip",
|
||||
Outcome::Fail | Outcome::Timeout => "fail",
|
||||
Self::Pass => "pass",
|
||||
Self::Skip => "skip",
|
||||
Self::Fail | Self::Timeout => "fail",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,7 @@ impl Counts {
|
||||
}
|
||||
}
|
||||
|
||||
fn merge(&mut self, other: &Counts) {
|
||||
fn merge(&mut self, other: &Self) {
|
||||
self.pass += other.pass;
|
||||
self.skip += other.skip;
|
||||
self.fail += other.fail;
|
||||
|
||||
Reference in new issue
Block a user