Working rel make & more

- Added `elf info`
- Improved `rel info`
- Colored output for `shasum`
- Fix section `rename` in RELs
- Added padding symbols to avoid linker issues
- Automatically set symbols to "active" in .comment output
This commit is contained in:
2023-09-03 10:42:52 -04:00
parent a2374e4fa0
commit f9f7fb2e1e
27 changed files with 1443 additions and 258 deletions

View File

@@ -18,7 +18,10 @@ pub use symbols::{
ObjSymbolScope, ObjSymbols, SymbolIndex,
};
use crate::util::{comment::MWComment, rel::RelReloc};
use crate::{
analysis::cfa::SectionAddress,
util::{comment::MWComment, rel::RelReloc},
};
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum ObjKind {
@@ -63,12 +66,11 @@ pub struct ObjInfo {
pub arena_hi: Option<u32>,
// Extracted
pub named_sections: BTreeMap<u32, String>,
pub link_order: Vec<ObjUnit>,
pub blocked_ranges: BTreeMap<u32, u32>, // start -> end
pub blocked_ranges: BTreeMap<SectionAddress, u32>, // start -> end
// From extab
pub known_functions: BTreeMap<u32, u32>,
pub known_functions: BTreeMap<SectionAddress, u32>,
// REL
/// Module ID (0 for main)
@@ -99,8 +101,6 @@ impl ObjInfo {
db_stack_addr: None,
arena_lo: None,
arena_hi: None,
// splits: Default::default(),
named_sections: Default::default(),
link_order: vec![],
blocked_ranges: Default::default(),
known_functions: Default::default(),
@@ -276,6 +276,8 @@ impl ObjInfo {
align: new_align,
common: split.common,
autogenerated: new_autogenerated,
skip: false, // ?
rename: None, // ?
})?;
return Ok(());
}

View File

@@ -15,6 +15,10 @@ pub struct ObjSplit {
pub common: bool,
/// Generated, replaceable by user.
pub autogenerated: bool,
/// Skip when emitting the split object.
pub skip: bool,
/// Override the section name in the split object. (e.g. `.ctors$10`)
pub rename: Option<String>,
}
/// Splits within a section.

View File

@@ -37,6 +37,8 @@ flags! {
ForceActive,
/// Symbol isn't referenced by any relocations
RelocationIgnore,
/// Symbol won't be written to symbols file
NoWrite,
}
}
@@ -78,6 +80,9 @@ impl ObjSymbolFlagSet {
#[inline]
pub fn is_relocation_ignore(&self) -> bool { self.0.contains(ObjSymbolFlags::RelocationIgnore) }
#[inline]
pub fn is_no_write(&self) -> bool { self.0.contains(ObjSymbolFlags::NoWrite) }
#[inline]
pub fn set_scope(&mut self, scope: ObjSymbolScope) {
match scope {
@@ -196,7 +201,7 @@ impl ObjSymbols {
self.at_section_address(section_index, in_symbol.address as u32).find(|(_, symbol)| {
symbol.kind == in_symbol.kind ||
// Replace auto symbols with real symbols
(symbol.kind == ObjSymbolKind::Unknown && is_auto_symbol(&symbol.name))
(symbol.kind == ObjSymbolKind::Unknown && is_auto_symbol(symbol))
})
} else if self.obj_kind == ObjKind::Executable {
// TODO hmmm
@@ -205,6 +210,7 @@ impl ObjSymbols {
bail!("ABS symbol in relocatable object: {:?}", in_symbol);
};
let target_symbol_idx = if let Some((symbol_idx, existing)) = opt {
let replace = replace || (is_auto_symbol(existing) && !is_auto_symbol(&in_symbol));
let size =
if existing.size_known && in_symbol.size_known && existing.size != in_symbol.size {
// TODO fix and promote back to warning