Compare commits
3 Commits
7b7c8ce251
...
4a84975648
Author | SHA1 | Date |
---|---|---|
Luke Street | 4a84975648 | |
Luke Street | 26cc6a13b4 | |
Luke Street | f71931838c |
|
@ -1654,6 +1654,9 @@ fn apply(args: ApplyArgs) -> Result<()> {
|
|||
if linked_scope != ObjSymbolScope::Unknown
|
||||
&& !is_globalized
|
||||
&& linked_scope != orig_sym.flags.scope()
|
||||
// Don't overwrite unknown scope with global
|
||||
&& (linked_scope != ObjSymbolScope::Global
|
||||
|| orig_sym.flags.scope() != ObjSymbolScope::Unknown)
|
||||
{
|
||||
log::info!(
|
||||
"Changing scope of {} (type {:?}) from {:?} to {:?}",
|
||||
|
@ -1683,6 +1686,7 @@ fn apply(args: ApplyArgs) -> Result<()> {
|
|||
// Add symbols from the linked object that aren't in the original
|
||||
for linked_sym in linked_obj.symbols.iter() {
|
||||
if matches!(linked_sym.kind, ObjSymbolKind::Section)
|
||||
|| is_auto_symbol(linked_sym)
|
||||
|| is_linker_generated_object(&linked_sym.name)
|
||||
// skip ABS for now
|
||||
|| linked_sym.section.is_none()
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
use std::{
|
||||
fs::File,
|
||||
io::{BufRead, BufReader, Read},
|
||||
io::{stdout, BufRead, BufReader, Read, Write},
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use anyhow::{anyhow, bail, Context, Result};
|
||||
use argp::FromArgs;
|
||||
use owo_colors::{OwoColorize, Stream};
|
||||
use path_slash::PathExt;
|
||||
use sha1::{Digest, Sha1};
|
||||
|
||||
use crate::util::file::{open_file, process_rsp, touch};
|
||||
use crate::util::file::{buf_writer, open_file, process_rsp, touch};
|
||||
|
||||
#[derive(FromArgs, PartialEq, Eq, Debug)]
|
||||
/// Print or check SHA1 (160-bit) checksums.
|
||||
|
@ -22,7 +23,8 @@ pub struct Args {
|
|||
/// path to input file(s)
|
||||
files: Vec<PathBuf>,
|
||||
#[argp(option, short = 'o')]
|
||||
/// touch output file on successful check
|
||||
/// (check) touch output file on successful check
|
||||
/// (hash) write hash(es) to output file
|
||||
output: Option<PathBuf>,
|
||||
#[argp(switch, short = 'q')]
|
||||
/// only print failures and a summary
|
||||
|
@ -32,17 +34,28 @@ pub struct Args {
|
|||
const DEFAULT_BUF_SIZE: usize = 8192;
|
||||
|
||||
pub fn run(args: Args) -> Result<()> {
|
||||
for path in process_rsp(&args.files)? {
|
||||
let mut file = open_file(&path)?;
|
||||
if args.check {
|
||||
check(&args, &mut BufReader::new(file))?
|
||||
} else {
|
||||
hash(&mut file, &path)?
|
||||
if args.check {
|
||||
for path in process_rsp(&args.files)? {
|
||||
let file = open_file(&path)?;
|
||||
check(&args, &mut BufReader::new(file))?;
|
||||
}
|
||||
if let Some(out_path) = &args.output {
|
||||
touch(out_path)
|
||||
.with_context(|| format!("Failed to touch output file '{}'", out_path.display()))?;
|
||||
}
|
||||
} else {
|
||||
let mut w: Box<dyn Write> =
|
||||
if let Some(out_path) = &args.output {
|
||||
Box::new(buf_writer(out_path).with_context(|| {
|
||||
format!("Failed to open output file '{}'", out_path.display())
|
||||
})?)
|
||||
} else {
|
||||
Box::new(stdout())
|
||||
};
|
||||
for path in process_rsp(&args.files)? {
|
||||
let mut file = open_file(&path)?;
|
||||
hash(w.as_mut(), &mut file, &path)?
|
||||
}
|
||||
}
|
||||
if let Some(out_path) = args.output {
|
||||
touch(&out_path)
|
||||
.with_context(|| format!("Failed to touch output file '{}'", out_path.display()))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -98,13 +111,16 @@ where R: BufRead + ?Sized {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn hash<R>(reader: &mut R, path: &Path) -> Result<()>
|
||||
where R: Read + ?Sized {
|
||||
fn hash<R, W>(w: &mut W, reader: &mut R, path: &Path) -> Result<()>
|
||||
where
|
||||
R: Read + ?Sized,
|
||||
W: Write + ?Sized,
|
||||
{
|
||||
let hash = file_sha1(reader)?;
|
||||
let mut hash_buf = [0u8; 40];
|
||||
let hash_str = base16ct::lower::encode_str(&hash, &mut hash_buf)
|
||||
.map_err(|e| anyhow!("Failed to encode hash: {e}"))?;
|
||||
println!("{} {}", hash_str, path.display());
|
||||
writeln!(w, "{} {}", hash_str, path.to_slash_lossy())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -178,6 +178,8 @@ pub fn is_auto_symbol(symbol: &ObjSymbol) -> bool {
|
|||
symbol.name.starts_with("lbl_")
|
||||
|| symbol.name.starts_with("fn_")
|
||||
|| symbol.name.starts_with("jumptable_")
|
||||
|| symbol.name.starts_with("gap_")
|
||||
|| symbol.name.starts_with("pad_")
|
||||
}
|
||||
|
||||
fn write_if_unchanged<P, Cb>(path: P, cb: Cb, cached_file: Option<FileReadInfo>) -> Result<()>
|
||||
|
|
|
@ -1353,7 +1353,9 @@ fn auto_unit_name(
|
|||
let name = sanitize_with_options(&symbol.name, &sanitise_file_name::Options {
|
||||
length_limit: 20,
|
||||
..Default::default()
|
||||
});
|
||||
})
|
||||
// Also replace $ to avoid issues with build.ninja
|
||||
.replace('$', "_");
|
||||
let mut unit_name = format!("auto_{}_{}", name, section_name.trim_start_matches('.'));
|
||||
// Ensure the name is unique
|
||||
if unit_exists(&unit_name, obj, new_splits) {
|
||||
|
|
Loading…
Reference in New Issue