Rename output_chunks to chunks

Rename the module directory and update its declaration, imports, and
call sites to use crate::chunks.

Validation:
- cargo check --locked --workspace
- cargo test --locked --workspace: 5,487 integration tests passed,
  637 skipped, no failures; all library tests passed. Four cross targets
  were unavailable because their compiler or QEMU was missing.
This commit is contained in:
Rui Ueyama committed 2026-09-05 16:21:19 +09:00
1 parent 2eef5735f0
commit c8f06bb1a5
67 files changed
+228 -234

No files matched your search

+2 -2
View File
@@ -49,13 +49,13 @@ use std::marker::PhantomData;
use rayon::prelude::*;
use crate::arch::{Arch, Family, ThunkLayout};
use crate::chunks::eh_frame;
use crate::chunks::output_section::OutputBuffer;
use crate::context::Context;
use crate::elf::*;
use crate::input_sections::{
check_tlsle, scan_absrel, scan_pcrel, scan_tlsdesc, InputSection, InputSectionId,
};
use crate::output_chunks::eh_frame;
use crate::output_chunks::output_section::OutputBuffer;
use crate::symbol::{Symbol, NEEDS_GOT, NEEDS_GOTTP, NEEDS_PLT, NEEDS_TLSGD};
use crate::thunks::Thunk;
use crate::util::{align_to, bit, bits, is_int, sign_extend};
+1 -1
View File
@@ -23,10 +23,10 @@
use std::marker::PhantomData;
use crate::arch::{Arch, Family, ThunkLayout};
use crate::chunks::eh_frame;
use crate::context::Context;
use crate::elf::*;
use crate::input_sections::{check_tlsle, scan_absrel, scan_pcrel, scan_tlsdesc, InputSection};
use crate::output_chunks::eh_frame;
use crate::symbol::{Symbol, NEEDS_GOT, NEEDS_GOTTP, NEEDS_PLT, NEEDS_TLSGD};
use crate::thunks::Thunk;
use crate::util::{bits, is_int};
+1 -1
View File
@@ -37,10 +37,10 @@
//! locations rather than in the relocation entries.
use crate::arch::{Arch, Family};
use crate::chunks::eh_frame;
use crate::context::Context;
use crate::elf::*;
use crate::input_sections::{check_tlsle, scan_absrel, scan_pcrel, scan_tlsdesc, InputSection};
use crate::output_chunks::eh_frame;
use crate::symbol::{Symbol, NEEDS_GOT, NEEDS_GOTTP, NEEDS_PLT, NEEDS_TLSGD};
use crate::{error, fatal};
+1 -1
View File
@@ -27,13 +27,13 @@
use std::marker::PhantomData;
use crate::arch::{Arch, Family};
use crate::chunks::eh_frame;
use crate::context::Context;
use crate::elf::*;
use crate::input_files::FileId;
use crate::input_sections::{
check_tlsle, scan_absrel, scan_pcrel, scan_tlsdesc, InputSection, RelocDelta,
};
use crate::output_chunks::eh_frame;
use crate::shrink_sections::compute_distance;
use crate::symbol::{Symbol, NEEDS_GOT, NEEDS_GOTTP, NEEDS_PLT, NEEDS_TLSGD};
use crate::util::{align_to, bits, is_int, overwrite_uleb, read_uleb, sign_extend};
+1 -1
View File
@@ -17,10 +17,10 @@
use std::sync::atomic::Ordering;
use crate::arch::{Arch, Family};
use crate::chunks::eh_frame;
use crate::context::Context;
use crate::elf::*;
use crate::input_sections::{check_tlsle, scan_absrel, scan_pcrel, InputSection};
use crate::output_chunks::eh_frame;
use crate::symbol::{Symbol, NEEDS_GOT, NEEDS_GOTTP, NEEDS_PLT, NEEDS_TLSGD};
use crate::{error, fatal};
+1 -1
View File
@@ -43,10 +43,10 @@
use std::sync::atomic::Ordering;
use crate::arch::{Arch, Family, ThunkLayout};
use crate::chunks::eh_frame;
use crate::context::Context;
use crate::elf::*;
use crate::input_sections::{check_tlsle, scan_absrel, scan_pcrel, InputSection};
use crate::output_chunks::eh_frame;
use crate::symbol::{Symbol, NEEDS_GOT, NEEDS_GOTTP, NEEDS_PLT, NEEDS_TLSGD};
use crate::thunks::Thunk;
use crate::util::{bits, is_int};
+1 -1
View File
@@ -51,11 +51,11 @@ use std::sync::atomic::Ordering;
use rayon::prelude::*;
use crate::arch::{Arch, Family, ThunkLayout};
use crate::chunks::eh_frame;
use crate::context::Context;
use crate::elf::*;
use crate::input_files::{FileId, SymbolEditor};
use crate::input_sections::{check_tlsle, InputSection, SectionRef};
use crate::output_chunks::eh_frame;
use crate::symbol::{
AddrFlags, Symbol, NEEDS_GOT, NEEDS_GOTTP, NEEDS_PLT, NEEDS_PPC_OPD, NEEDS_TLSGD,
};
+1 -1
View File
@@ -86,10 +86,10 @@
use std::sync::atomic::Ordering;
use crate::arch::{Arch, Family, ThunkLayout};
use crate::chunks::eh_frame;
use crate::context::Context;
use crate::elf::*;
use crate::input_sections::{check_tlsle, InputSection};
use crate::output_chunks::eh_frame;
use crate::symbol::{Symbol, NEEDS_GOT, NEEDS_GOTTP, NEEDS_PLT, NEEDS_TLSGD};
use crate::thunks::Thunk;
use crate::util::{bits, is_int};
+1 -1
View File
@@ -23,13 +23,13 @@
use std::marker::PhantomData;
use crate::arch::{Arch, Family};
use crate::chunks::eh_frame;
use crate::context::Context;
use crate::elf::*;
use crate::input_files::FileId;
use crate::input_sections::{
check_tlsle, r_delta, scan_absrel, scan_pcrel, scan_tlsdesc, InputSection, RelocDelta,
};
use crate::output_chunks::eh_frame;
use crate::shrink_sections::compute_distance;
use crate::symbol::{Symbol, NEEDS_GOT, NEEDS_GOTTP, NEEDS_PLT, NEEDS_TLSGD};
use crate::util::{align_to, bit, bits, encode_uleb, is_int, overwrite_uleb, read_uleb};
+1 -1
View File
@@ -36,10 +36,10 @@
//! https://github.com/IBM/s390x-abi/releases/download/v1.6.1/lzsabi_s390x.pdf
use crate::arch::{Arch, Family};
use crate::chunks::eh_frame;
use crate::context::Context;
use crate::elf::*;
use crate::input_sections::{check_tlsle, scan_absrel, scan_pcrel, InputSection};
use crate::output_chunks::eh_frame;
use crate::symbol::{Symbol, NEEDS_GOT, NEEDS_GOTTP, NEEDS_PLT, NEEDS_TLSGD};
use crate::util::{bits, is_int};
use crate::{error, fatal};
+1 -1
View File
@@ -63,10 +63,10 @@ use std::marker::PhantomData;
use std::sync::atomic::Ordering;
use crate::arch::{Arch, Family};
use crate::chunks::eh_frame;
use crate::context::Context;
use crate::elf::*;
use crate::input_sections::{check_tlsle, scan_pcrel, InputSection};
use crate::output_chunks::eh_frame;
use crate::symbol::{Symbol, NEEDS_GOT, NEEDS_GOTTP, NEEDS_PLT, NEEDS_TLSGD};
use crate::{error, fatal};
+2 -2
View File
@@ -59,11 +59,11 @@
use std::sync::atomic::Ordering;
use crate::arch::{Arch, Family};
use crate::chunks::eh_frame;
use crate::chunks::plt::SPARC_NUM_SMALL_PLT;
use crate::context::Context;
use crate::elf::*;
use crate::input_sections::{check_tlsle, scan_absrel, scan_pcrel, InputSection};
use crate::output_chunks::eh_frame;
use crate::output_chunks::plt::SPARC_NUM_SMALL_PLT;
use crate::symbol::{Symbol, NEEDS_GOT, NEEDS_GOTTP, NEEDS_PLT, NEEDS_TLSGD};
use crate::util::{bit, bits};
use crate::{error, fatal};
+1 -1
View File
@@ -26,10 +26,10 @@
//! https://gitlab.com/x86-psABIs/x86-64-ABI
use crate::arch::{Arch, Family};
use crate::chunks::eh_frame;
use crate::context::Context;
use crate::elf::*;
use crate::input_sections::{check_tlsle, scan_absrel, scan_pcrel, scan_tlsdesc, InputSection};
use crate::output_chunks::eh_frame;
use crate::symbol::{Symbol, NEEDS_GOT, NEEDS_GOTTP, NEEDS_PLT, NEEDS_TLSGD};
use crate::util::is_int;
use crate::{error, fatal};
@@ -15,9 +15,9 @@
use rayon::prelude::*;
use crate::arch::Arch;
use crate::chunks::{output_section, ChunkHeader, ChunkId, OutputSectionId};
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::{output_section, ChunkHeader, ChunkId, OutputSectionId};
use crate::util::sign_extend;
const CANTUNWIND: u32 = 1;
@@ -1,9 +1,9 @@
//! `.note.gnu.build-id`, the output file's build identifier.
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
// .note.gnu.build-id contains an identifier for an output ELF file. The
// contents of the section is usually a cryptogrpahic hash of the output
@@ -1,9 +1,9 @@
//! COMDAT groups in relocatable outputs.
use crate::arch::Arch;
use crate::chunks::{ChunkHeader, ChunkId};
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::{ChunkHeader, ChunkId};
use crate::symbol::SymbolId;
// ComdatGroupSection represents a comdat group for an output file.
@@ -1,9 +1,9 @@
//! Compressed output sections.
use crate::arch::Arch;
use crate::chunks::{self, ChunkHeader, ChunkId};
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::{self, ChunkHeader, ChunkId};
use crate::util::compress::Compressor;
// Debug sections can be compressed with zlib or zstd to reduce the
@@ -34,7 +34,7 @@ pub fn new<E: Arch>(ctx: &Context<E>, original: ChunkId) -> CompressedSection<E>
let mut buf = vec![0u8; hdr.shdr.sh_size.get() as usize];
// Write uncompressed contents and then compress them
output_chunks::write_to(ctx, original, &mut buf);
chunks::write_to(ctx, original, &mut buf);
let level = ctx.args.compress_debug_sections_level;
let compressor = if ctx.args.compress_debug_sections == ELFCOMPRESS_ZLIB {
@@ -1,11 +1,11 @@
//! `.copyrel` and `.copyrel.rel.ro`, storage for copy relocations.
use crate::arch::Arch;
use crate::chunks::{self, ChunkHeader};
use crate::context::Context;
use crate::elf::*;
use crate::error;
use crate::input_files::FileId;
use crate::output_chunks::{self, ChunkHeader};
use crate::symbol::SymbolId;
use crate::util::align_to;
@@ -88,7 +88,7 @@ pub fn add_symbol<E: Arch>(ctx: &mut Context<E>, relro: bool, id: SymbolId) {
s.set_copyrel(true);
s.set_copyrel_readonly(relro);
s.value = offset;
output_chunks::dynsym::add_symbol(ctx, alias);
chunks::dynsym::add_symbol(ctx, alias);
}
}
@@ -1,10 +1,10 @@
//! `.dynamic`, information consumed by the dynamic linker.
use crate::arch::{Arch, Family};
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::input_files::FileId;
use crate::output_chunks::ChunkHeader;
use crate::symbol::SymbolId;
// .dynamic contains various information for dynamically-linked ELF files.
@@ -155,8 +155,7 @@ fn create_contents<E: Arch>(ctx: &Context<E>) -> Vec<(u64, u64)> {
if ctx.gotplt.hdr.shdr.sh_size.get() != 0 {
define(
DT_PLTGOT,
ctx.gotplt.hdr.shdr.sh_addr.get()
+ crate::output_chunks::gotplt::header_size::<E>(),
ctx.gotplt.hdr.shdr.sh_addr.get() + crate::chunks::gotplt::header_size::<E>(),
);
}
} else if ctx.gotplt.hdr.shdr.sh_size.get() != 0 {
@@ -288,7 +287,7 @@ fn create_contents<E: Arch>(ctx: &Context<E>) -> Vec<(u64, u64)> {
// it's what it is.
define(
DT_PPC64_GLINK,
ctx.plt.hdr.shdr.sh_addr.get() + crate::output_chunks::plt::entry_offset::<E>(0) - 32,
ctx.plt.hdr.shdr.sh_addr.get() + crate::chunks::plt::entry_offset::<E>(0) - 32,
);
}
@@ -3,9 +3,9 @@
use std::collections::HashMap;
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
use crate::util::write_cstr;
// .dynstr contains strings that the runtime uses.
@@ -1,11 +1,11 @@
//! `.dynsym`, the dynamic symbol table.
use crate::arch::Arch;
use crate::chunks::symtab::to_output_esym;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::error;
use crate::output_chunks::symtab::to_output_esym;
use crate::output_chunks::ChunkHeader;
use crate::symbol::SymbolId;
// .dynsym contains symbols for dynamic linking. This is similar to
@@ -10,12 +10,12 @@ use std::ptr::NonNull;
use rayon::prelude::*;
use crate::arch::Arch;
use crate::chunks::eh_frame_hdr::EhFrameHdrSection;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::input_files::ObjectFile;
use crate::input_sections::CieRecord;
use crate::output_chunks::eh_frame_hdr::EhFrameHdrSection;
use crate::output_chunks::ChunkHeader;
use crate::output_file::split_at_offsets;
use crate::symbol::Symbol;
use crate::util::is_int;
@@ -1,9 +1,9 @@
//! `.eh_frame_hdr`, the lookup table for exception-handling records.
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
// .eh_frame_hdr is a lookup table for .eh_frame. Entries in .eh_frame_hdr
// are sorted by their dcorresponding function addresses, so tha the
@@ -3,10 +3,10 @@
use rayon::prelude::*;
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::input_files::ObjectFile;
use crate::output_chunks::ChunkHeader;
// EhFrameRelocSection contains relocation records for .eh_frame. It is used
// only for relocatable outputs (an .o file rather than an executable or .so).
@@ -1,9 +1,9 @@
//! `.gnu_debuglink`, the pathname and checksum of separate debug information.
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
use crate::util::align_to;
use crate::util::{path_filename, write_cstr};
@@ -1,9 +1,9 @@
//! `.gnu.hash`, the GNU hash table for dynamic symbol lookup.
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
use crate::symbol::SymbolId;
/// The hash function for `.gnu.hash`.
@@ -1,10 +1,10 @@
//! `.got`, addresses and thread-local offsets used at runtime.
use crate::arch::{Arch, Family};
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::input_files::SymtabBlock;
use crate::output_chunks::ChunkHeader;
use crate::symbol::{AddrFlags, SymbolId};
// .got is a linker-synthesized constant pool whose entry size is the same
@@ -1,9 +1,9 @@
//! `.got.plt`, function pointers used by the PLT.
use crate::arch::{Arch, Family};
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
// .got.plt is similar to .got in the sense that it is a table containing
// pointers. The contents in .got.plt are function pointers used by .plt.
@@ -1,9 +1,9 @@
//! `.hash`, the ELF hash table for dynamic symbol lookup.
use crate::arch::{Arch, Family};
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
// The hash function for .hash.
pub fn elf_hash(name: &[u8]) -> u32 {
@@ -1,9 +1,9 @@
//! `.interp`, the dynamic linker's pathname.
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
use crate::util::write_cstr;
// .interp contains the pathname of a dynamic linker. Dynamically-linked
@@ -14,12 +14,12 @@ use bstr::BStr;
use rayon::prelude::*;
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::cmdline::Args;
use crate::context::Context;
use crate::elf::*;
use crate::input_sections::{InputSection, MergeInfo, SectionFragment, SectionRef};
use crate::out;
use crate::output_chunks::ChunkHeader;
use crate::output_file::split_at_offsets;
use crate::util::align_to;
use crate::util::concurrent_map::{ConcurrentMap, EntryId, FrozenMap, NUM_SHARDS};
File renamed without changes.
@@ -1,9 +1,9 @@
//! `.note.package`, package metadata.
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
use crate::util::align_to;
use crate::util::write_cstr;
@@ -3,9 +3,9 @@
use std::collections::{BTreeMap, BTreeSet};
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
// .note.gnu.property section contains an additional runtime information
// about ISA variant.
@@ -9,9 +9,9 @@
//! same way it synthesizes GOT and PLT entries.
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
use crate::symbol::{AddrFlags, SymbolId};
pub const ENTRY_SIZE: u64 = 24;
@@ -6,11 +6,11 @@ use bstr::BStr;
use rayon::prelude::*;
use crate::arch::{Arch, Family};
use crate::chunks::{ChunkHeader, OutputSectionId};
use crate::context::Context;
use crate::elf::*;
use crate::input_files::SymtabBlock;
use crate::input_sections::{r_delta, InputSectionId};
use crate::output_chunks::{ChunkHeader, OutputSectionId};
use crate::symbol::{AddrFlags, SymbolId, NEEDS_CANONICAL};
use crate::thunks::Thunk;
use crate::util::align_to;
@@ -601,9 +601,9 @@ pub fn populate_symtab<E: Arch>(
block.push_synthetic::<E>(name, suffix.as_bytes(), func(addr));
if E::FAMILY == Family::Arm32 {
// Emit "$t", "$a" and "$d" if ARM32.
block.push_mapping_symbol::<E>(crate::output_chunks::strtab::THUMB, func(addr));
block.push_mapping_symbol::<E>(crate::output_chunks::strtab::ARM, func(addr + 4));
block.push_mapping_symbol::<E>(crate::output_chunks::strtab::DATA, func(addr + 12));
block.push_mapping_symbol::<E>(crate::chunks::strtab::THUMB, func(addr));
block.push_mapping_symbol::<E>(crate::chunks::strtab::ARM, func(addr + 4));
block.push_mapping_symbol::<E>(crate::chunks::strtab::DATA, func(addr + 12));
}
}
}
@@ -1,10 +1,10 @@
//! `.plt`, stubs for runtime lazy symbol resolution.
use crate::arch::{Arch, Family};
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::input_files::SymtabBlock;
use crate::output_chunks::ChunkHeader;
use crate::symbol::SymbolId;
// .plt contains linker-synthesized stub code that acts as if they are
@@ -82,7 +82,7 @@ pub fn add_symbol<E: Arch>(ctx: &mut Context<E>, sym: SymbolId) {
let idx = ctx.plt.symbols.len() as u32;
ctx.symbols.aux_mut(sym).plt_idx = Some(idx);
ctx.plt.symbols.push(sym);
crate::output_chunks::dynsym::add_symbol(ctx, sym);
crate::chunks::dynsym::add_symbol(ctx, sym);
}
pub fn update_shdr<E: Arch>(ctx: &mut Context<E>) {
@@ -132,7 +132,7 @@ pub fn populate_symtab<E: Arch>(ctx: &Context<E>, block: &mut SymtabBlock<'_>) {
sym.set_type(STT_FUNC);
sym
};
use crate::output_chunks::strtab::{ARM, DATA};
use crate::chunks::strtab::{ARM, DATA};
if E::FAMILY == Family::Arm32 {
block.push_mapping_symbol::<E>(ARM, func(plt.hdr.shdr.sh_addr.get()));
block.push_mapping_symbol::<E>(DATA, func(plt.hdr.shdr.sh_addr.get() + 16));
@@ -1,10 +1,10 @@
//! `.plt.got`, PLT stubs for symbols already resolved through the GOT.
use crate::arch::{Arch, Family};
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::input_files::SymtabBlock;
use crate::output_chunks::ChunkHeader;
use crate::symbol::SymbolId;
// .plt.got is similar to .plt but doesn't support lazy symbol resolution.
@@ -79,7 +79,7 @@ pub fn populate_symtab<E: Arch>(ctx: &Context<E>, block: &mut SymtabBlock<'_>) {
sym.set_type(STT_FUNC);
sym
};
use crate::output_chunks::strtab::{ARM, DATA};
use crate::chunks::strtab::{ARM, DATA};
for &id in &pltgot.symbols {
let sym = &ctx.symbols[id];
let addr = sym.plt_addr(ctx);
@@ -1,9 +1,9 @@
//! PowerPC64 register save and restore functions.
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
/// `.save_restore_regs`, the register save and restore routines that GCC
/// expects the linker to provide on PowerPC64 ELFv2.
@@ -3,10 +3,10 @@
use rayon::prelude::*;
use crate::arch::Arch;
use crate::chunks::relrdyn::encode_relr;
use crate::chunks::{self, ChunkHeader};
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::relrdyn::encode_relr;
use crate::output_chunks::{self, ChunkHeader};
use crate::util::encode_sleb;
// .rel.dyn contains relocation infromation for other sections.
@@ -63,7 +63,7 @@ pub fn collect_relocs<E: Arch>(ctx: &Context<E>) -> Vec<ElfRel<E>> {
let count = (hdr.num_dynrels - hdr.num_relrs) as usize;
if count != 0 {
let (slots, tail) = std::mem::take(&mut rest).split_at_mut(count);
output_chunks::write_dynrels(ctx, id, slots);
chunks::write_dynrels(ctx, id, slots);
rest = tail;
}
}
@@ -79,7 +79,7 @@ pub fn construct_relr<E: Arch>(ctx: &mut Context<E>) {
let ids = ctx.chunks.clone();
for &id in &ids {
let n = output_chunks::num_dynrels(ctx, id);
let n = chunks::num_dynrels(ctx, id);
let hdr = ctx.chunk_header_mut(id);
hdr.num_dynrels = n;
hdr.num_relrs = 0;
@@ -102,7 +102,7 @@ pub fn construct_relr<E: Arch>(ctx: &mut Context<E>) {
continue;
}
if n != 0 {
let offsets = output_chunks::relr_offsets(ctx, id);
let offsets = chunks::relr_offsets(ctx, id);
let hdr = ctx.chunk_header_mut(id);
hdr.num_relrs = offsets.len() as u64;
debug_assert!(hdr.num_relrs <= hdr.num_dynrels);
@@ -123,7 +123,7 @@ pub fn update_shdr<E: Arch>(ctx: &mut Context<E>) {
let ids = ctx.chunks.clone();
if !ctx.args.pack_dyn_relocs_relr {
for &id in &ids {
let n = output_chunks::num_dynrels(ctx, id);
let n = chunks::num_dynrels(ctx, id);
let hdr = ctx.chunk_header_mut(id);
hdr.num_dynrels = n;
hdr.num_relrs = 0;
@@ -179,7 +179,7 @@ pub fn copy_buf<E: Arch>(ctx: &Context<E>, buf: &mut [u8]) {
let count = (hdr.num_dynrels - hdr.num_relrs) as usize;
if count != 0 {
let (slots, tail) = std::mem::take(&mut rest).split_at_mut(count * size);
output_chunks::write_dynrels(ctx, id, rels_from_bytes_mut::<E>(slots));
chunks::write_dynrels(ctx, id, rels_from_bytes_mut::<E>(slots));
rest = tail;
}
}
@@ -3,10 +3,10 @@
use bstr::BStr;
use crate::arch::Arch;
use crate::chunks::{ChunkHeader, OutputSectionId};
use crate::context::Context;
use crate::elf::*;
use crate::input_sections::{r_delta, InputSection};
use crate::output_chunks::{ChunkHeader, OutputSectionId};
use crate::symbol::OriginValue;
// RelocSection represents a relocation table for an output file.
@@ -1,9 +1,9 @@
//! `.rel.plt` and `.rela.plt`, relocations for PLT entries.
use crate::arch::Arch;
use crate::chunks::{plt, ChunkHeader};
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::{plt, ChunkHeader};
// .rel.plt contains relocation information for .plt.
#[derive(Debug)]
@@ -1,9 +1,9 @@
//! `.relr.dyn`, packed base relocations.
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
// .relr.dyn is a relatively new section to contain base relocation
// information.
@@ -1,7 +1,7 @@
//! Padding at the end of a RELRO segment.
use crate::chunks::ChunkHeader;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
// PT_GNU_RELRO works on page granularity. We want to align its end to
// a page boundary. We append this section at end of a segment so that
@@ -1,9 +1,9 @@
//! `.riscv.attributes`, merged RISC-V target attributes.
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
/// `.riscv.attributes` describes the ISA the output requires, merged
/// from the input files' attributes.
@@ -3,10 +3,10 @@
//! FDE index sorted by address.
use crate::arch::{Arch, Family};
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::input_files::ObjId;
use crate::output_chunks::ChunkHeader;
// .sframe is a compact stack-unwinding format. Like .eh_frame, the linker
// has to parse and reconstruct it: the output section is a single sorted
@@ -1,9 +1,9 @@
//! `.rela.sframe`, SFrame relocations for relocatable outputs.
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
// SFrameRelocSection holds the relocations for .sframe. We use it only for
// relocatable outputs, where function addresses aren't known yet and each
@@ -5,9 +5,9 @@ use std::collections::HashMap;
use bstr::BStr;
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
use crate::util::write_cstr;
// .shstrtab contains section names, such as ".text" or ".data". Just like
@@ -1,9 +1,9 @@
//! `.strtab`, names of non-dynamic symbols.
use crate::arch::{Arch, Family};
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
// .strtab is referenced by .strtab and contains symbol names. Note that
// .strtab is not needed at runtime; one can remove the section from an
@@ -3,11 +3,11 @@
use rayon::prelude::*;
use crate::arch::{Arch, Family};
use crate::chunks::{self, strtab, ChunkHeader, ChunkId};
use crate::context::Context;
use crate::elf::*;
use crate::input_files::{SymtabBlock, SymtabEntries};
use crate::input_sections::{r_delta, InputSection};
use crate::output_chunks::{self, strtab, ChunkHeader, ChunkId};
use crate::symbol::{AddrFlags, OriginValue, Symbol};
// .symtab contains non-dynamic symbols. The section is not needed at
@@ -212,7 +212,7 @@ pub fn copy_buf<E: Arch>(
part.strtab.0,
);
match part.writer {
Writer::Chunk(id) => output_chunks::populate_symtab(ctx, id, &mut block),
Writer::Chunk(id) => chunks::populate_symtab(ctx, id, &mut block),
Writer::Obj(id) => ctx.objs[id.index()].populate_symtab(ctx, id, &mut block),
Writer::Dso(id) => ctx.dsos[id.index()].populate_symtab(ctx, id, &mut block),
}
@@ -1,7 +1,7 @@
//! `.symtab_shndx`, extended section indices for the symbol table.
use crate::chunks::ChunkHeader;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
// .symtab_shndx is a parallel table for .symtab to contain section
// indices for symbols.
@@ -1,12 +1,12 @@
//! `.gnu.version_d`, defined symbol versions.
use crate::arch::Arch;
use crate::chunks::dynstr::DynstrSection;
use crate::chunks::hash::elf_hash;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::input_files::FileId;
use crate::output_chunks::dynstr::DynstrSection;
use crate::output_chunks::hash::elf_hash;
use crate::output_chunks::ChunkHeader;
use crate::util::path_filename;
// .gnu.version contains a parallel table for .dynsym to specify symbol
@@ -1,12 +1,12 @@
//! `.gnu.version_r`, required symbol versions.
use crate::arch::Arch;
use crate::chunks::dynstr::DynstrSection;
use crate::chunks::hash::elf_hash;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::input_files::{DsoId, FileId};
use crate::output_chunks::dynstr::DynstrSection;
use crate::output_chunks::hash::elf_hash;
use crate::output_chunks::ChunkHeader;
use crate::symbol::SymbolId;
// .gnu.version_r contains information to refer to shared libraries and
@@ -1,9 +1,9 @@
//! `.gnu.version`, symbol version indices.
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::output_chunks::ChunkHeader;
// .gnu.version section contains version indices as a parallel array for
// .dynsym. If a dynamic symbol is a defined one, its version information
+44 -45
View File
@@ -8,6 +8,46 @@ use std::sync::atomic::{AtomicBool, AtomicU32};
use std::sync::{Mutex, MutexGuard, OnceLock};
use crate::arch::Arch;
use crate::chunks::build_id::BuildIdSection;
use crate::chunks::comdat_group::ComdatGroupSection;
use crate::chunks::compressed::CompressedSection;
use crate::chunks::copyrel::CopyrelSection;
use crate::chunks::dynamic::DynamicSection;
use crate::chunks::dynstr::DynstrSection;
use crate::chunks::dynsym::DynsymSection;
use crate::chunks::eh_frame::EhFrameSection;
use crate::chunks::eh_frame_hdr::EhFrameHdrSection;
use crate::chunks::eh_frame_reloc::EhFrameRelocSection;
use crate::chunks::gnu_debuglink::GnuDebuglinkSection;
use crate::chunks::gnu_hash::GnuHashSection;
use crate::chunks::got::GotSection;
use crate::chunks::gotplt::GotPltSection;
use crate::chunks::hash::HashSection;
use crate::chunks::interp::InterpSection;
use crate::chunks::merged::{MergedSection, MergedSectionId};
use crate::chunks::note_package::NotePackageSection;
use crate::chunks::note_property::NotePropertySection;
use crate::chunks::output_section::OutputSection;
use crate::chunks::plt::PltSection;
use crate::chunks::pltgot::PltGotSection;
use crate::chunks::reldyn::RelDynSection;
use crate::chunks::reloc::RelocSection;
use crate::chunks::relplt::RelPltSection;
use crate::chunks::relrdyn::RelrDynSection;
use crate::chunks::relro_padding::RelroPaddingSection;
use crate::chunks::riscv_attributes::RiscvAttributesSection;
use crate::chunks::sframe::SFrameSection;
use crate::chunks::sframe_reloc::SFrameRelocSection;
use crate::chunks::shstrtab::ShstrtabSection;
use crate::chunks::strtab::StrtabSection;
use crate::chunks::symtab::SymtabSection;
use crate::chunks::symtab_shndx::SymtabShndxSection;
use crate::chunks::verdef::VerdefSection;
use crate::chunks::verneed::VerneedSection;
use crate::chunks::versym::VersymSection;
use crate::chunks::{
ChunkHeader, ChunkId, GdbIndexSection, OutputEhdr, OutputPhdr, OutputSectionId, OutputShdr,
};
use crate::cmdline::Args;
use crate::elf::{ElfSym, ElfWord};
use crate::input_files::{FileId, FileList, InputFile, ObjId, ObjectFile, SharedFile};
@@ -15,46 +55,6 @@ use crate::input_sections::{
FragmentRef, InputSection, InputSectionId, SectionFragment, SectionRef,
};
use crate::linker_script::{DynamicPattern, VersionPattern};
use crate::output_chunks::build_id::BuildIdSection;
use crate::output_chunks::comdat_group::ComdatGroupSection;
use crate::output_chunks::compressed::CompressedSection;
use crate::output_chunks::copyrel::CopyrelSection;
use crate::output_chunks::dynamic::DynamicSection;
use crate::output_chunks::dynstr::DynstrSection;
use crate::output_chunks::dynsym::DynsymSection;
use crate::output_chunks::eh_frame::EhFrameSection;
use crate::output_chunks::eh_frame_hdr::EhFrameHdrSection;
use crate::output_chunks::eh_frame_reloc::EhFrameRelocSection;
use crate::output_chunks::gnu_debuglink::GnuDebuglinkSection;
use crate::output_chunks::gnu_hash::GnuHashSection;
use crate::output_chunks::got::GotSection;
use crate::output_chunks::gotplt::GotPltSection;
use crate::output_chunks::hash::HashSection;
use crate::output_chunks::interp::InterpSection;
use crate::output_chunks::merged::{MergedSection, MergedSectionId};
use crate::output_chunks::note_package::NotePackageSection;
use crate::output_chunks::note_property::NotePropertySection;
use crate::output_chunks::output_section::OutputSection;
use crate::output_chunks::plt::PltSection;
use crate::output_chunks::pltgot::PltGotSection;
use crate::output_chunks::reldyn::RelDynSection;
use crate::output_chunks::reloc::RelocSection;
use crate::output_chunks::relplt::RelPltSection;
use crate::output_chunks::relrdyn::RelrDynSection;
use crate::output_chunks::relro_padding::RelroPaddingSection;
use crate::output_chunks::riscv_attributes::RiscvAttributesSection;
use crate::output_chunks::sframe::SFrameSection;
use crate::output_chunks::sframe_reloc::SFrameRelocSection;
use crate::output_chunks::shstrtab::ShstrtabSection;
use crate::output_chunks::strtab::StrtabSection;
use crate::output_chunks::symtab::SymtabSection;
use crate::output_chunks::symtab_shndx::SymtabShndxSection;
use crate::output_chunks::verdef::VerdefSection;
use crate::output_chunks::verneed::VerneedSection;
use crate::output_chunks::versym::VersymSection;
use crate::output_chunks::{
ChunkHeader, ChunkId, GdbIndexSection, OutputEhdr, OutputPhdr, OutputSectionId, OutputShdr,
};
use crate::symbol::{Bins, SymbolId, SymbolSlot, SymbolTable};
use crate::util::perf::Timers;
@@ -192,10 +192,9 @@ pub struct Context<E: Arch> {
// Target-specific context members
pub note_property: Option<NotePropertySection<E>>,
pub riscv_attributes: Option<RiscvAttributesSection<E>>,
pub arm_exidx: Option<crate::output_chunks::arm_exidx::ArmExidxSection<E>>,
pub ppc64_save_restore:
Option<crate::output_chunks::ppc64_save_restore::Ppc64SaveRestoreSection<E>>,
pub ppc64_opd: Option<crate::output_chunks::opd::Ppc64OpdSection<E>>,
pub arm_exidx: Option<crate::chunks::arm_exidx::ArmExidxSection<E>>,
pub ppc64_save_restore: Option<crate::chunks::ppc64_save_restore::Ppc64SaveRestoreSection<E>>,
pub ppc64_opd: Option<crate::chunks::opd::Ppc64OpdSection<E>>,
/// Whether any input uses Power10 PC-relative calls, which decides
/// how thunks address their targets.
pub is_power10: AtomicBool,
@@ -421,7 +420,7 @@ impl<E: Arch> Context<E> {
.ppc64_opd
.as_ref()
.expect("PPC64 ELFv1 has an .opd section");
opd.hdr.shdr.sh_addr.get() + idx as u64 * crate::output_chunks::opd::ENTRY_SIZE
opd.hdr.shdr.sh_addr.get() + idx as u64 * crate::chunks::opd::ENTRY_SIZE
}
/// Whether the file is the internal object holding synthesized symbols.
+17 -17
View File
@@ -6,11 +6,11 @@ use std::sync::mpsc;
use rayon::prelude::*;
use crate::arch::{self, Arch};
use crate::chunks::{self, ChunkId};
use crate::cmdline::{self, Args, TargetTraits};
use crate::context::Context;
use crate::elf::*;
use crate::input_files::FileId;
use crate::output_chunks::{self, ChunkId};
use crate::output_file::{split_ranges, OutputFile, Range};
use crate::{error, fatal, passes};
@@ -331,7 +331,7 @@ pub fn link<E: Arch>(cmdline: &[String]) -> Result<i32, String> {
// Convert an .ARM.exidx to a synthetic section.
if E::FAMILY == arch::Family::Arm32 {
output_chunks::arm_exidx::create(&mut ctx);
chunks::arm_exidx::create(&mut ctx);
}
// Handle --section-align options.
@@ -428,7 +428,7 @@ pub fn link<E: Arch>(cmdline: &[String]) -> Result<i32, String> {
// RELR is encoded independently for each output chunk using offsets
// relative to that chunk.
if ctx.args.pack_dyn_relocs_relr {
output_chunks::reldyn::construct_relr(&mut ctx);
chunks::reldyn::construct_relr(&mut ctx);
}
// Reserve a space for dynamic symbol strings in .dynstr and sort
// .dynsym contents if necessary. Beyond this point, no symbol will
@@ -475,20 +475,20 @@ pub fn link<E: Arch>(cmdline: &[String]) -> Result<i32, String> {
// Fill .gnu.version_d section contents.
if ctx.verdef.is_some() {
output_chunks::verdef::construct(&mut ctx);
chunks::verdef::construct(&mut ctx);
}
// Fill .gnu.version_r section contents.
output_chunks::verneed::construct(&mut ctx);
chunks::verneed::construct(&mut ctx);
// .eh_frame is a special section from the linker's point of view,
// as its contents are parsed and reconstructed by the linker,
// unlike other sections that are regarded as opaque bytes.
// Here, we construct output .eh_frame contents.
output_chunks::eh_frame::construct(&mut ctx);
chunks::eh_frame::construct(&mut ctx);
// .sframe is likewise parsed and reconstructed by the linker. Build
// the merged, PC-sorted output .sframe.
output_chunks::sframe::construct(&mut ctx);
chunks::sframe::construct(&mut ctx);
// If --emit-relocs is given, we'll copy relocation sections from input
// files to an output file.
@@ -524,7 +524,7 @@ pub fn link<E: Arch>(cmdline: &[String]) -> Result<i32, String> {
filesize = passes::set_osec_offsets(&mut ctx);
}
if ctx.arm_exidx.is_some() {
output_chunks::arm_exidx::remove_duplicate_entries(&mut ctx);
chunks::arm_exidx::remove_duplicate_entries(&mut ctx);
filesize = passes::set_osec_offsets(&mut ctx);
}
@@ -534,7 +534,7 @@ pub fn link<E: Arch>(cmdline: &[String]) -> Result<i32, String> {
let t = ctx.timer("fix_synthetic_symbols");
passes::fix_synthetic_symbols(&mut ctx);
drop(t);
output_chunks::sframe::sort(&mut ctx);
chunks::sframe::sort(&mut ctx);
// Beyond this, you can assume that symbol addresses including their
// GOT or PLT addresses have a correct final value.
@@ -562,7 +562,7 @@ pub fn link<E: Arch>(cmdline: &[String]) -> Result<i32, String> {
// At this point, both memory and file layouts are fixed.
let t = ctx.timer("update_reldyn");
output_chunks::reldyn::update_shdr(&mut ctx);
chunks::reldyn::update_shdr(&mut ctx);
drop(t);
ctx.filesize = filesize;
t_before_copy.stop();
@@ -596,7 +596,7 @@ pub fn link<E: Arch>(cmdline: &[String]) -> Result<i32, String> {
if ctx.chunks.contains(&ChunkId::RelDyn) && reldyn.sh_size.get() != 0 {
let start = reldyn.sh_offset.get() as usize;
let end = (reldyn.sh_offset.get() + reldyn.sh_size.get()) as usize;
output_chunks::reldyn::sort(&ctx, &mut buf[start..end]);
chunks::reldyn::sort(&ctx, &mut buf[start..end]);
}
// The final stage reads address ranges, which requires relocated debug
@@ -822,21 +822,21 @@ fn run_tasks<E: Arch>(
let mut bufs = bufs.drain(..);
let own = bufs.next().unwrap();
match task.chunk {
ChunkId::EhFrame => output_chunks::eh_frame::copy_buf(ctx, own, bufs.next()),
ChunkId::EhFrame => chunks::eh_frame::copy_buf(ctx, own, bufs.next()),
ChunkId::Symtab => {
let strtab = bufs.next().unwrap();
output_chunks::symtab::copy_buf(ctx, own, strtab, bufs.next());
chunks::symtab::copy_buf(ctx, own, strtab, bufs.next());
}
ChunkId::Reloc(i) => output_chunks::reloc::copy_buf(ctx, i, own, bufs.next()),
ChunkId::EhFrameReloc => output_chunks::eh_frame_reloc::copy_buf(ctx, own, bufs.next()),
id => output_chunks::copy_buf(ctx, id, own),
ChunkId::Reloc(i) => chunks::reloc::copy_buf(ctx, i, own, bufs.next()),
ChunkId::EhFrameReloc => chunks::eh_frame_reloc::copy_buf(ctx, own, bufs.next()),
id => chunks::copy_buf(ctx, id, own),
}
});
// .eh_frame_hdr's header, whose table .eh_frame wrote.
if tasks.iter().any(|t| t.chunk == ChunkId::EhFrame) && ctx.eh_frame_hdr.is_some() {
let r = file_range(ctx, ChunkId::EhFrameHdr);
output_chunks::eh_frame_hdr::write_header(
chunks::eh_frame_hdr::write_header(
ctx,
&mut buf[r.offset as usize..(r.offset + r.size) as usize],
);
+2 -2
View File
@@ -83,10 +83,10 @@
use rayon::prelude::*;
use crate::arch::Arch;
use crate::chunks::ChunkId;
use crate::context::Context;
use crate::elf::*;
use crate::fatal;
use crate::output_chunks::ChunkId;
use crate::output_file::{split_at_offsets, OutputFile};
use std::ptr::NonNull;
use std::sync::atomic::{AtomicU32, AtomicUsize, Ordering};
@@ -1472,6 +1472,6 @@ pub fn write<E: Arch>(ctx: &mut Context<E>, output: &mut OutputFile) {
let buf = output.buf();
let start = shdr.sh_offset.get() as usize;
let end = (shdr.sh_offset.get() + shdr.sh_size.get()) as usize;
crate::output_chunks::copy_buf(ctx, ChunkId::Shdr, &mut buf[start..end]);
crate::chunks::copy_buf(ctx, ChunkId::Shdr, &mut buf[start..end]);
}
}
+2 -3
View File
@@ -284,15 +284,14 @@ impl DigestMap {
fn uniquify_cies<E: Arch>(ctx: &mut Context<E>) {
let _t = ctx.timer("uniquify_cies");
let mut leaders: Vec<crate::output_chunks::eh_frame::CieHandle<E>> = Vec::new();
let mut leaders: Vec<crate::chunks::eh_frame::CieHandle<E>> = Vec::new();
for file in &mut ctx.objs {
let file_ptr = file as *mut ObjectFile<E>;
let cies = file.cies.as_mut_ptr();
for ci in 0..file.cies.len() {
// SAFETY: object files are boxed and ICF does not resize their CIE
// vectors, so leaders remain stable through this serial pass.
let cie =
unsafe { crate::output_chunks::eh_frame::CieHandle::new(file_ptr, cies.add(ci)) };
let cie = unsafe { crate::chunks::eh_frame::CieHandle::new(file_ptr, cies.add(ci)) };
let found = leaders.iter().position(|&leader| leader.equals(cie));
match found {
Some(idx) => cie.icf_idx(idx as u32),
+3 -3
View File
@@ -17,6 +17,7 @@ use std::sync::{OnceLock, RwLock};
use rayon::prelude::*;
use crate::arch::{Arch, Family};
use crate::chunks::merged::MergedSection;
use crate::cmdline::Args;
use crate::context::Context;
use crate::elf::*;
@@ -25,7 +26,6 @@ use crate::input_sections::{
SFrameFde, SectionList,
};
use crate::mapped_file::MappedFile;
use crate::output_chunks::merged::MergedSection;
use crate::symbol::{
hash_key, Bins, OriginValue, ParallelSymbolAllocator, Symbol, SymbolId, SymbolSlot,
SymbolTable, NEEDS_PLT,
@@ -2900,13 +2900,13 @@ impl<'a> SymtabBlock<'a> {
pub fn push_local<E: Arch>(&mut self, ctx: &Context<E>, sym: &Symbol) {
let st_name = self.add_string(&[sym.name().as_ref()]);
let (esym, xindex) = crate::output_chunks::symtab::to_output_esym(ctx, sym, st_name);
let (esym, xindex) = crate::chunks::symtab::to_output_esym(ctx, sym, st_name);
self.locals.push::<E>(esym, xindex);
}
pub fn push_global<E: Arch>(&mut self, ctx: &Context<E>, sym: &Symbol) {
let st_name = self.add_string(&[sym.name().as_ref()]);
let (esym, xindex) = crate::output_chunks::symtab::to_output_esym(ctx, sym, st_name);
let (esym, xindex) = crate::chunks::symtab::to_output_esym(ctx, sym, st_name);
self.globals.push::<E>(esym, xindex);
}
+3 -3
View File
@@ -6,12 +6,12 @@ use std::sync::atomic::{AtomicBool, AtomicU64, AtomicU8, Ordering};
use bstr::BStr;
use crate::arch::{Arch, Family};
use crate::chunks::merged::{MergedSection, MergedSectionId};
use crate::chunks::OutputSectionId;
use crate::cmdline::UnresolvedKind;
use crate::context::Context;
use crate::elf::*;
use crate::input_files::{ObjId, ObjectFile, RelocationIter};
use crate::output_chunks::merged::{MergedSection, MergedSectionId};
use crate::output_chunks::OutputSectionId;
use crate::symbol::{Symbol, SymbolId, NEEDS_CANONICAL, NEEDS_GOTTP, NEEDS_PLT, NEEDS_TLSDESC};
use crate::util::compress::{zlib_decompress, zstd_decompress};
use crate::util::concurrent_map::EntryId;
@@ -1570,7 +1570,7 @@ impl MergeInfo {
pub fn resolve_contents<E: Arch>(
&mut self,
section: &InputSection<E>,
parent: &crate::output_chunks::merged::MergedSection<E>,
parent: &crate::chunks::merged::MergedSection<E>,
gc_sections: bool,
) {
let n = self.frag_offsets.len();
+1 -1
View File
@@ -2,6 +2,7 @@
pub mod arch;
pub mod archive_file;
pub mod chunks;
pub mod cmdline;
pub mod context;
pub mod driver;
@@ -22,7 +23,6 @@ pub mod lto;
pub mod lto;
pub mod mapfile;
pub mod mapped_file;
pub mod output_chunks;
pub mod output_file;
pub mod passes;
pub mod reader;
+1 -1
View File
@@ -7,12 +7,12 @@ use std::io::Write;
use rayon::prelude::*;
use crate::arch::Arch;
use crate::chunks::ChunkId;
use crate::context::Context;
use crate::elf::*;
use crate::fatal;
use crate::input_files::FileId;
use crate::input_sections::InputSectionId;
use crate::output_chunks::ChunkId;
use crate::symbol::SymbolId;
// Construct a section-to-symbol map.
+60 -61
View File
@@ -12,6 +12,25 @@ use bstr::BStr;
use rayon::prelude::*;
use crate::arch::{Arch, Family};
use crate::chunks::build_id::{self, BuildIdSection};
use crate::chunks::dynamic::DynamicSection;
use crate::chunks::eh_frame_hdr::EhFrameHdrSection;
use crate::chunks::eh_frame_reloc::EhFrameRelocSection;
use crate::chunks::gnu_debuglink::{self, GnuDebuglinkSection};
use crate::chunks::gnu_hash::{self, GnuHashSection};
use crate::chunks::hash::HashSection;
use crate::chunks::interp::InterpSection;
use crate::chunks::note_property::NotePropertySection;
use crate::chunks::output_section::OutputSection;
use crate::chunks::relrdyn::RelrDynSection;
use crate::chunks::relro_padding::RelroPaddingSection;
use crate::chunks::shstrtab::ShstrtabSection;
use crate::chunks::symtab_shndx::SymtabShndxSection;
use crate::chunks::verdef::VerdefSection;
use crate::chunks::{
self, compressed, copyrel, dynsym, reloc, ChunkHeader, ChunkId, GdbIndexSection, OutputEhdr,
OutputPhdr, OutputSectionId, OutputShdr,
};
use crate::cmdline::{
BsymbolicKind, BuildIdKind, CetReportKind, DefsymValue, SectionOrderKind, SeparateCodeKind,
ShuffleSectionsKind, UnresolvedKind,
@@ -24,25 +43,6 @@ use crate::input_files::{
};
use crate::input_sections::{InputSection, InputSectionId, SectionRef};
use crate::linker_script::VersionPattern;
use crate::output_chunks::build_id::{self, BuildIdSection};
use crate::output_chunks::dynamic::DynamicSection;
use crate::output_chunks::eh_frame_hdr::EhFrameHdrSection;
use crate::output_chunks::eh_frame_reloc::EhFrameRelocSection;
use crate::output_chunks::gnu_debuglink::{self, GnuDebuglinkSection};
use crate::output_chunks::gnu_hash::{self, GnuHashSection};
use crate::output_chunks::hash::HashSection;
use crate::output_chunks::interp::InterpSection;
use crate::output_chunks::note_property::NotePropertySection;
use crate::output_chunks::output_section::OutputSection;
use crate::output_chunks::relrdyn::RelrDynSection;
use crate::output_chunks::relro_padding::RelroPaddingSection;
use crate::output_chunks::shstrtab::ShstrtabSection;
use crate::output_chunks::symtab_shndx::SymtabShndxSection;
use crate::output_chunks::verdef::VerdefSection;
use crate::output_chunks::{
self, compressed, copyrel, dynsym, reloc, ChunkHeader, ChunkId, GdbIndexSection, OutputEhdr,
OutputPhdr, OutputSectionId, OutputShdr,
};
use crate::output_file::OutputFile;
use crate::symbol::{
is_c_identifier, Bins, Symbol, SymbolId, NEEDS_CANONICAL, NEEDS_GOT, NEEDS_GOTTP, NEEDS_PLT,
@@ -188,7 +188,7 @@ pub fn create_synthetic_sections<E: Arch>(ctx: &mut Context<E>) {
shdr.sh_type.set(SHT_PROGBITS);
shdr.sh_flags.set((SHF_MERGE | SHF_STRINGS) as u64);
let merged = RwLock::new(std::mem::take(&mut ctx.merged_sections));
ctx.comment = crate::output_chunks::merged::MergedSection::get_instance(
ctx.comment = crate::chunks::merged::MergedSection::get_instance(
&ctx.args,
&merged,
BStr::new(b".comment"),
@@ -202,17 +202,16 @@ pub fn create_synthetic_sections<E: Arch>(ctx: &mut Context<E>) {
chunks.push(ChunkId::NoteProperty);
}
if E::IS_RISCV {
ctx.riscv_attributes =
Some(crate::output_chunks::riscv_attributes::RiscvAttributesSection::new());
ctx.riscv_attributes = Some(crate::chunks::riscv_attributes::RiscvAttributesSection::new());
chunks.push(ChunkId::RiscvAttributes);
}
if E::FAMILY == Family::Ppc64V2 {
ctx.ppc64_save_restore =
Some(crate::output_chunks::ppc64_save_restore::Ppc64SaveRestoreSection::new());
Some(crate::chunks::ppc64_save_restore::Ppc64SaveRestoreSection::new());
chunks.push(ChunkId::Ppc64SaveRestore);
}
if E::FAMILY == Family::Ppc64V1 {
ctx.ppc64_opd = Some(crate::output_chunks::opd::Ppc64OpdSection::new());
ctx.ppc64_opd = Some(crate::chunks::opd::Ppc64OpdSection::new());
chunks.push(ChunkId::Ppc64Opd);
}
@@ -984,8 +983,8 @@ pub fn parse_sframe_sections<E: Arch>(ctx: &mut Context<E>) {
fn merged_resolve_members<E: Arch>(
objs: &mut FileList<ObjectFile<E>>,
count: usize,
) -> Vec<Vec<crate::output_chunks::merged::ResolveMember<'_, E>>> {
let mut members: Vec<Vec<crate::output_chunks::merged::ResolveMember<'_, E>>> =
) -> Vec<Vec<crate::chunks::merged::ResolveMember<'_, E>>> {
let mut members: Vec<Vec<crate::chunks::merged::ResolveMember<'_, E>>> =
(0..count).map(|_| Vec::new()).collect();
for file in objs {
let filename = file.base.filename.as_str();
@@ -994,7 +993,7 @@ fn merged_resolve_members<E: Arch>(
let num_elf_sections = file.num_elf_sections;
for (merge_info, input) in file.sections.merge_infos_with_inputs_mut() {
let parent = merge_info.parent.index();
members[parent].push(crate::output_chunks::merged::ResolveMember {
members[parent].push(crate::chunks::merged::ResolveMember {
merge_info,
section: input,
filename,
@@ -1044,10 +1043,10 @@ pub fn create_merged_sections<E: Arch>(ctx: &mut Context<E>) {
let t = ctx.timer("resolve");
let mut members = merged_resolve_members(&mut ctx.objs, ctx.merged_sections.len());
crate::output_chunks::merged::resolve_sections::<E>(
crate::chunks::merged::resolve_sections::<E>(
&mut ctx.merged_sections,
&mut members,
crate::output_chunks::merged::ResolveOptions {
crate::chunks::merged::ResolveOptions {
allocated_only: true,
gc_sections: ctx.args.gc_sections,
comment: ctx.comment,
@@ -1493,7 +1492,7 @@ pub fn create_output_sections<E: Arch>(ctx: &mut Context<E>) {
.map(|i| ChunkId::Output(OutputSectionId::new(i as u32)))
.chain(
(0..ctx.merged_sections.len())
.map(|i| ChunkId::Merged(crate::output_chunks::merged::MergedSectionId(i as u32))),
.map(|i| ChunkId::Merged(crate::chunks::merged::MergedSectionId(i as u32))),
)
.collect();
// Sections are added to the section lists in an arbitrary order
@@ -2312,8 +2311,8 @@ pub fn sort_debug_info_sections<E: Arch>(ctx: &mut Context<E>) {
&& (osec.hdr.shdr.sh_size.get() >= u32::MAX as u64 || is_in_test)
})
.collect();
let vec2: Vec<crate::output_chunks::merged::MergedSectionId> = (0..ctx.merged_sections.len())
.map(|i| crate::output_chunks::merged::MergedSectionId(i as u32))
let vec2: Vec<crate::chunks::merged::MergedSectionId> = (0..ctx.merged_sections.len())
.map(|i| crate::chunks::merged::MergedSectionId(i as u32))
.filter(|&id| {
let msec = &ctx.merged_sections[id.index()];
!msec.is_alloc()
@@ -2355,7 +2354,7 @@ pub fn sort_debug_info_sections<E: Arch>(ctx: &mut Context<E>) {
.iter()
.partition(|&&m| objs[m.file().index()].is_dwarf32);
osec.members = a.into_iter().chain(b).collect();
output_chunks::compute_section_size(ctx, ChunkId::Output(id));
chunks::compute_section_size(ctx, ChunkId::Output(id));
}
// Reorder strings in .debug_str and the like
@@ -2370,7 +2369,7 @@ pub fn sort_debug_info_sections<E: Arch>(ctx: &mut Context<E>) {
}
}
for id in vec2 {
output_chunks::compute_section_size(ctx, ChunkId::Merged(id));
chunks::compute_section_size(ctx, ChunkId::Merged(id));
}
}
@@ -2543,10 +2542,10 @@ pub fn compute_section_sizes<E: Arch>(ctx: &mut Context<E>) {
// parent sections concurrently too.
{
let mut members = merged_resolve_members(&mut ctx.objs, ctx.merged_sections.len());
crate::output_chunks::merged::resolve_sections::<E>(
crate::chunks::merged::resolve_sections::<E>(
&mut ctx.merged_sections,
&mut members,
crate::output_chunks::merged::ResolveOptions {
crate::chunks::merged::ResolveOptions {
allocated_only: false,
gc_sections: ctx.args.gc_sections,
comment: ctx.comment,
@@ -2564,7 +2563,7 @@ pub fn compute_section_sizes<E: Arch>(ctx: &mut Context<E>) {
.par_iter()
.filter_map(|&id| match id {
ChunkId::Output(osec) if !needs_thunks(ctx, id) => {
Some((osec, output_chunks::output_section::layout(ctx, osec)))
Some((osec, chunks::output_section::layout(ctx, osec)))
}
_ => None,
})
@@ -2578,13 +2577,13 @@ pub fn compute_section_sizes<E: Arch>(ctx: &mut Context<E>) {
// layout, just as each C++ Chunk does in the parallel chunk loop.
ctx.merged_sections
.par_iter_mut()
.for_each(crate::output_chunks::merged::layout);
.for_each(crate::chunks::merged::layout);
for id in ctx.chunks.clone() {
match id {
ChunkId::Output(_) => {}
ChunkId::Merged(_) => {}
_ => output_chunks::compute_section_size(ctx, id),
_ => chunks::compute_section_size(ctx, id),
}
}
}
@@ -2729,7 +2728,7 @@ pub fn scan_relocations<E: Arch>(ctx: &mut Context<E>) {
// separately because they can be promoted to dynamic relocations.
let results: Vec<(
OutputSectionId,
Vec<crate::output_chunks::output_section::AbsRel>,
Vec<crate::chunks::output_section::AbsRel>,
Vec<u64>,
)> = {
let ctx_ref: &Context<E> = ctx;
@@ -2739,7 +2738,7 @@ pub fn scan_relocations<E: Arch>(ctx: &mut Context<E>) {
.filter(|&id| ctx_ref.output_sections[id.index()].hdr.is_alloc())
.map(|id| {
let (abs_rels, offsets) =
crate::output_chunks::output_section::scan_abs_relocations(ctx_ref, id);
crate::chunks::output_section::scan_abs_relocations(ctx_ref, id);
(id, abs_rels, offsets)
})
.collect()
@@ -2795,7 +2794,7 @@ pub fn scan_relocations<E: Arch>(ctx: &mut Context<E>) {
};
if ctx.needs_tlsld.load(Ordering::Relaxed) {
crate::output_chunks::got::add_tlsld(ctx);
crate::chunks::got::add_tlsld(ctx);
}
// Every dynamic symbol gets its auxiliary record. The loop below
@@ -2820,7 +2819,7 @@ pub fn scan_relocations<E: Arch>(ctx: &mut Context<E>) {
dynsym::add_symbol(ctx, id);
}
if flags & NEEDS_GOT != 0 {
crate::output_chunks::got::add_got_symbol(ctx, id);
crate::chunks::got::add_got_symbol(ctx, id);
}
if flags & NEEDS_CANONICAL != 0 && ty == STT_FUNC {
let sym = &mut ctx.symbols[id];
@@ -2832,22 +2831,22 @@ pub fn scan_relocations<E: Arch>(ctx: &mut Context<E>) {
// We can't use .plt.got for a canonical PLT because otherwise
// .plt.got and .got would refer to each other, resulting in an
// infinite loop at runtime.
crate::output_chunks::plt::add_symbol(ctx, id);
crate::chunks::plt::add_symbol(ctx, id);
} else if flags & NEEDS_PLT != 0 {
if flags & NEEDS_GOT != 0 {
crate::output_chunks::pltgot::add_symbol(ctx, id);
crate::chunks::pltgot::add_symbol(ctx, id);
} else {
crate::output_chunks::plt::add_symbol(ctx, id);
crate::chunks::plt::add_symbol(ctx, id);
}
}
if flags & NEEDS_GOTTP != 0 {
crate::output_chunks::got::add_gottp_symbol(ctx, id);
crate::chunks::got::add_gottp_symbol(ctx, id);
}
if flags & NEEDS_TLSGD != 0 {
crate::output_chunks::got::add_tlsgd_symbol(ctx, id);
crate::chunks::got::add_tlsgd_symbol(ctx, id);
}
if flags & NEEDS_TLSDESC != 0 {
crate::output_chunks::got::add_tlsdesc_symbol(ctx, id);
crate::chunks::got::add_tlsdesc_symbol(ctx, id);
}
if flags & NEEDS_CANONICAL != 0 && ty != STT_FUNC {
let relro = ctx.args.z_relro
@@ -2858,7 +2857,7 @@ pub fn scan_relocations<E: Arch>(ctx: &mut Context<E>) {
copyrel::add_symbol(ctx, relro, id);
}
if E::FAMILY == Family::Ppc64V1 && flags & NEEDS_PPC_OPD != 0 {
crate::output_chunks::opd::add_symbol(ctx, id);
crate::chunks::opd::add_symbol(ctx, id);
}
ctx.symbols[id].clear_flags();
}
@@ -3029,7 +3028,7 @@ pub fn create_output_symtab<E: Arch>(ctx: &mut Context<E>) {
}
}
for id in ctx.chunks.clone() {
output_chunks::compute_symtab_size(ctx, id);
chunks::compute_symtab_size(ctx, id);
}
let obj_plans: Vec<crate::input_files::SymtabPlan> = {
@@ -3731,7 +3730,7 @@ fn tls_segment_alignment<E: Arch>(ctx: &Context<E>) -> u64 {
fn set_virtual_addresses_regular<E: Arch>(ctx: &mut Context<E>) {
const RELRO: u64 = 1 << 32;
let flags_of = |ctx: &Context<E>, id: ChunkId| -> u64 {
let flags = output_chunks::to_phdr_flags(ctx, id) as u64;
let flags = chunks::to_phdr_flags(ctx, id) as u64;
if ctx.args.z_relro && ctx.chunk_header(id).is_relro {
flags | RELRO
} else {
@@ -3867,8 +3866,8 @@ fn set_virtual_addresses_by_order<E: Arch>(ctx: &mut Context<E>) {
// put sections with different memory attributes into different
// pages. We do it by inserting a padding.
if i != 0 {
let flags1 = output_chunks::to_phdr_flags(ctx, vec[i - 1]);
let flags2 = output_chunks::to_phdr_flags(ctx, vec[i]);
let flags1 = chunks::to_phdr_flags(ctx, vec[i - 1]);
let flags2 = chunks::to_phdr_flags(ctx, vec[i]);
if flags1 != flags2 {
match ctx.args.z_separate_code {
SeparateCodeKind::SeparateLoadableSegments => {
@@ -4016,7 +4015,7 @@ pub fn separate_debug_sections<E: Arch>(ctx: &mut Context<E>) {
pub fn compute_section_headers<E: Arch>(ctx: &mut Context<E>) {
// Update sh_size for each chunk.
for id in ctx.chunks.clone() {
output_chunks::update_shdr(ctx, id);
chunks::update_shdr(ctx, id);
}
// Remove empty chunks.
@@ -4060,7 +4059,7 @@ pub fn compute_section_headers<E: Arch>(ctx: &mut Context<E>) {
// Some types of section header refer to other section by index.
// Recompute all section headers to fill such fields with correct values.
for id in ctx.chunks.clone() {
output_chunks::update_shdr(ctx, id);
chunks::update_shdr(ctx, id);
}
if let Some(symtab_shndx) = &mut ctx.symtab_shndx {
@@ -4081,7 +4080,7 @@ pub fn set_osec_offsets<E: Arch>(ctx: &mut Context<E>) -> u64 {
if ctx.args.pack_dyn_relocs_android {
let before = ctx.reldyn.hdr.shdr.sh_size.get();
crate::output_chunks::reldyn::update_shdr(ctx);
crate::chunks::reldyn::update_shdr(ctx);
if before != ctx.reldyn.hdr.shdr.sh_size.get() {
continue;
}
@@ -4093,7 +4092,7 @@ pub fn set_osec_offsets<E: Arch>(ctx: &mut Context<E>) -> u64 {
let fileoff = set_file_offsets(ctx);
if ctx.phdr.is_some() {
let before = ctx.phdr.as_ref().unwrap().hdr.shdr.sh_size.get();
output_chunks::update_phdr(ctx);
chunks::update_phdr(ctx);
if before < ctx.phdr.as_ref().unwrap().hdr.shdr.sh_size.get() {
continue;
}
@@ -4563,7 +4562,7 @@ pub fn write_separate_debug_file<E: Arch>(ctx: &mut Context<E>) {
let new_chunks = ctx.chunks[num_chunks..].to_vec();
for id in new_chunks {
output_chunks::compute_section_size(ctx, id);
chunks::compute_section_size(ctx, id);
}
sort_debug_info_sections(ctx);
@@ -4596,7 +4595,7 @@ pub fn write_separate_debug_file<E: Arch>(ctx: &mut Context<E>) {
// The program header keeps its size, since the placeholders' addresses
// were laid out around it.
if let Some(n) = ctx.phdr.as_ref().map(|p| p.phdrs.len()) {
output_chunks::update_phdr(ctx);
chunks::update_phdr(ctx);
let phdr = ctx.phdr.as_mut().unwrap();
phdr.phdrs.resize(n, ElfPhdr::<E>::default());
phdr.hdr
@@ -4772,7 +4771,7 @@ pub fn show_stats<E: Arch>(ctx: &Context<E>) {
Counter::print();
for section in &ctx.merged_sections {
crate::output_chunks::merged::print_stats(section);
crate::chunks::merged::print_stats(section);
}
}
+9 -9
View File
@@ -33,16 +33,16 @@
use rayon::prelude::*;
use crate::arch::Arch;
use crate::chunks::comdat_group::ComdatGroupSection;
use crate::chunks::eh_frame_reloc::EhFrameRelocSection;
use crate::chunks::note_property::NotePropertySection;
use crate::chunks::riscv_attributes::RiscvAttributesSection;
use crate::chunks::sframe_reloc::SFrameRelocSection;
use crate::chunks::shstrtab::ShstrtabSection;
use crate::chunks::{self, ChunkId, OutputEhdr, OutputShdr};
use crate::context::Context;
use crate::elf::*;
use crate::input_files::FileId;
use crate::output_chunks::comdat_group::ComdatGroupSection;
use crate::output_chunks::eh_frame_reloc::EhFrameRelocSection;
use crate::output_chunks::note_property::NotePropertySection;
use crate::output_chunks::riscv_attributes::RiscvAttributesSection;
use crate::output_chunks::sframe_reloc::SFrameRelocSection;
use crate::output_chunks::shstrtab::ShstrtabSection;
use crate::output_chunks::{self, ChunkId, OutputEhdr, OutputShdr};
use crate::output_file::OutputFile;
use crate::passes;
use crate::util::align_to;
@@ -175,8 +175,8 @@ pub fn combine_objects<E: Arch>(ctx: &mut Context<E>) {
passes::compute_section_sizes(ctx);
passes::sort_output_sections(ctx);
passes::create_output_symtab(ctx);
output_chunks::eh_frame::construct(ctx);
output_chunks::sframe::construct(ctx);
chunks::eh_frame::construct(ctx);
chunks::sframe::construct(ctx);
passes::create_reloc_sections(ctx);
create_comdat_group_sections(ctx);
passes::compute_section_headers(ctx);
+2 -2
View File
@@ -78,11 +78,11 @@
use rayon::prelude::*;
use crate::arch::Arch;
use crate::chunks::{self, ChunkId};
use crate::context::Context;
use crate::elf::*;
use crate::input_files::{FileId, SymbolEditor};
use crate::input_sections::{r_delta, InputSection, RelocDelta};
use crate::output_chunks::{self, ChunkId};
use crate::symbol::Symbol;
/// Returns the distance between a relocated place and a symbol.
@@ -184,7 +184,7 @@ pub fn shrink_sections<E: Arch>(ctx: &mut Context<E>) {
& SHF_EXECINSTR as u64
!= 0 =>
{
Some((osec, output_chunks::output_section::layout(ctx, osec)))
Some((osec, chunks::output_section::layout(ctx, osec)))
}
_ => None,
})
+4 -6
View File
@@ -20,12 +20,12 @@ use hashbrown::{Equivalent, HashMap};
use rayon::prelude::*;
use crate::arch::Arch;
use crate::chunks::ChunkHeader;
use crate::context::Context;
use crate::elf::*;
use crate::error::demangle_enabled;
use crate::input_files::FileId;
use crate::input_sections::{FragmentRef, InputSection, InputSectionId};
use crate::output_chunks::ChunkHeader;
use crate::util::demangle::{demangle_cpp, demangle_rust};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
@@ -1079,9 +1079,8 @@ impl Symbol {
pub fn gotplt_addr<E: Arch>(&self, ctx: &Context<E>) -> u64 {
ctx.gotplt.hdr.shdr.sh_addr.get()
+ crate::output_chunks::gotplt::header_size::<E>()
+ self.plt_idx(&ctx.symbols).unwrap() as u64
* crate::output_chunks::gotplt::entry_size::<E>()
+ crate::chunks::gotplt::header_size::<E>()
+ self.plt_idx(&ctx.symbols).unwrap() as u64 * crate::chunks::gotplt::entry_size::<E>()
}
pub fn gottp_addr<E: Arch>(&self, ctx: &Context<E>) -> u64 {
@@ -1102,8 +1101,7 @@ impl Symbol {
#[inline]
pub fn plt_addr<E: Arch>(&self, ctx: &Context<E>) -> u64 {
if let Some(idx) = self.plt_idx(&ctx.symbols) {
return ctx.plt.hdr.shdr.sh_addr.get()
+ crate::output_chunks::plt::entry_offset::<E>(idx);
return ctx.plt.hdr.shdr.sh_addr.get() + crate::chunks::plt::entry_offset::<E>(idx);
}
ctx.pltgot.hdr.shdr.sh_addr.get()
+ self.pltgot_idx(&ctx.symbols).unwrap() as u64 * E::PLTGOT_SIZE
+2 -2
View File
@@ -34,11 +34,11 @@ use std::cell::UnsafeCell;
use rayon::prelude::*;
use crate::arch::{Arch, Family};
use crate::chunks::output_section::OutputSection;
use crate::chunks::{ChunkId, OutputSectionId};
use crate::context::Context;
use crate::elf::*;
use crate::input_sections::InputSection;
use crate::output_chunks::output_section::OutputSection;
use crate::output_chunks::{ChunkId, OutputSectionId};
use crate::symbol::{AddrFlags, Symbol, SymbolId};
use crate::util::align_to;