mirror of
https://github.com/rui314/mold.git
synced 2026-11-07 09:16:04 -10:00
Append a table's little-endian fields with util's push16, push32 and push64
chained_fixups.rs had push16, push32 and push64, unwind_info.rs the same as closures, and dtrace.rs appended its u16 fields by hand and its u32 and u64 lists in helpers of its own. They are util's push16, push32 and push64 now, beside its read and write helpers, and dtrace's list helpers append with them. code_signature's push_be32 and push_be64, the only big-endian ones, stay its own. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
50074775e4
commit
6a1eabb9b3
4 files changed
+24
-23
No files matched your search
@@ -12,6 +12,7 @@ use crate::fatal;
|
||||
use crate::input_files::{FileId, data_blob_binds, data_blob_pointers};
|
||||
use crate::macho::*;
|
||||
use crate::symbol::{Symbol, SymbolId};
|
||||
use crate::util::{push16, push32, push64};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ChainedFixupsSection {
|
||||
@@ -97,18 +98,6 @@ pub(crate) fn pointer_format<E: Target>(ctx: &Context<E>) -> u16 {
|
||||
}
|
||||
}
|
||||
|
||||
fn push16(buf: &mut Vec<u8>, val: u16) {
|
||||
buf.extend_from_slice(&val.to_le_bytes());
|
||||
}
|
||||
|
||||
fn push32(buf: &mut Vec<u8>, val: u32) {
|
||||
buf.extend_from_slice(&val.to_le_bytes());
|
||||
}
|
||||
|
||||
fn push64(buf: &mut Vec<u8>, val: u64) {
|
||||
buf.extend_from_slice(&val.to_le_bytes());
|
||||
}
|
||||
|
||||
fn pad(buf: &mut Vec<u8>, align: usize) {
|
||||
buf.resize(buf.len().next_multiple_of(align), 0);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use crate::context::Context;
|
||||
use crate::input_sections::{InputSection, UnwindRecord};
|
||||
use crate::macho::*;
|
||||
use crate::symbol::SymbolId;
|
||||
use crate::util::{push16, push32};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct UnwindInfoSection {
|
||||
@@ -266,8 +267,6 @@ fn write_table<E: Target>(
|
||||
let lsda_off = page1_off + (pages.len() + 1) * 12;
|
||||
let page2_off = lsda_off + num_lsda * 8;
|
||||
|
||||
let push32 = |buf: &mut Vec<u8>, val: u32| buf.extend_from_slice(&val.to_le_bytes());
|
||||
|
||||
let mut buf = Vec::new();
|
||||
push32(&mut buf, UNWIND_SECTION_VERSION);
|
||||
push32(&mut buf, personality_off as u32);
|
||||
@@ -325,8 +324,6 @@ fn encode_page<E: Target>(ctx: &Context<E>, records: &[UnwindRecord], page: &Pag
|
||||
let base = ctx.mach_header.hdr.addr;
|
||||
let span = &records[page.records.clone()];
|
||||
let encs = &page.encodings;
|
||||
let push32 = |buf: &mut Vec<u8>, val: u32| buf.extend_from_slice(&val.to_le_bytes());
|
||||
let push16 = |buf: &mut Vec<u8>, val: u16| buf.extend_from_slice(&val.to_le_bytes());
|
||||
|
||||
let mut lsda = Vec::new();
|
||||
for rec in span {
|
||||
|
||||
+7
-7
@@ -34,7 +34,7 @@ use crate::input_files::add_synthetic_section;
|
||||
use crate::input_sections::{InputSection, Reloc, RelocTarget};
|
||||
use crate::macho::*;
|
||||
use crate::symbol::SymbolId;
|
||||
use crate::util::split_once;
|
||||
use crate::util::{push16, push32, push64, split_once};
|
||||
|
||||
/// The prefix of the names of the symbols a `dtrace -h` header makes
|
||||
/// code refer to. ld-prime takes every undefined symbol whose name
|
||||
@@ -525,9 +525,9 @@ impl ProbeTables {
|
||||
let offidx = t.sites.len() as u32;
|
||||
put_u32s(&mut t.records, &[func, name, nargv, xargv, argidx, offidx]);
|
||||
t.records.extend_from_slice(&[nargc, nargc]);
|
||||
t.records.extend_from_slice(&(inst.sites.len() as u16).to_le_bytes());
|
||||
push16(&mut t.records, inst.sites.len() as u16);
|
||||
put_u32s(&mut t.records, &[t.tests.len() as u32]);
|
||||
t.records.extend_from_slice(&(inst.tests.len() as u16).to_le_bytes());
|
||||
push16(&mut t.records, inst.tests.len() as u16);
|
||||
t.records.extend_from_slice(&[0; 6]);
|
||||
t.sites.extend(&inst.sites);
|
||||
t.tests.extend(&inst.tests);
|
||||
@@ -599,14 +599,14 @@ fn lay_out_dof(
|
||||
}
|
||||
|
||||
fn put_u32s(out: &mut Vec<u8>, vals: &[u32]) {
|
||||
for v in vals {
|
||||
out.extend_from_slice(&v.to_le_bytes());
|
||||
for &v in vals {
|
||||
push32(out, v);
|
||||
}
|
||||
}
|
||||
|
||||
fn put_u64s(out: &mut Vec<u8>, vals: &[u64]) {
|
||||
for v in vals {
|
||||
out.extend_from_slice(&v.to_le_bytes());
|
||||
for &v in vals {
|
||||
push64(out, v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,21 @@ pub fn write64(loc: &mut [u8], val: u64) {
|
||||
loc[..8].copy_from_slice(&val.to_le_bytes());
|
||||
}
|
||||
|
||||
// Little-endian appends of an integer to a buffer: the fields of the
|
||||
// tables the linker builds in full before writing them out (the chained
|
||||
// fixups, the unwind info, a DOF section).
|
||||
pub fn push16(buf: &mut Vec<u8>, val: u16) {
|
||||
buf.extend_from_slice(&val.to_le_bytes());
|
||||
}
|
||||
|
||||
pub fn push32(buf: &mut Vec<u8>, val: u32) {
|
||||
buf.extend_from_slice(&val.to_le_bytes());
|
||||
}
|
||||
|
||||
pub fn push64(buf: &mut Vec<u8>, val: u64) {
|
||||
buf.extend_from_slice(&val.to_le_bytes());
|
||||
}
|
||||
|
||||
/// A sort key that orders byte strings like the strings themselves but
|
||||
/// settles most comparisons on one integer: the first eight bytes,
|
||||
/// big-endian, zero-padded. Symbol names cannot contain NULs, so
|
||||
|
||||
Reference in new issue
Block a user