Support address in config symbol references

Example: `symbol_name!.data:0x1234`
Allows disambiguating local symbols
with the same name.

Supported in `extract` and
`add_relocations` in config.yml

Resolves #58
This commit is contained in:
2024-06-03 18:08:06 -06:00
parent 4701de32f6
commit 61cd72cd11
2 changed files with 40 additions and 7 deletions

View File

@@ -947,11 +947,10 @@ fn split_write_obj(
let (_, symbol) = module
.obj
.symbols
.by_name(&extract.symbol)?
.by_ref(&module.obj.sections, &extract.symbol)?
.with_context(|| format!("Failed to locate symbol '{}'", extract.symbol))?;
let section_index = symbol
.section
.with_context(|| format!("Symbol '{}' has no section", extract.symbol))?;
let section_index =
symbol.section.with_context(|| format!("Symbol '{}' has no section", symbol.name))?;
let section = &module.obj.sections[section_index];
let data = section.symbol_data(symbol)?;
@@ -1893,7 +1892,7 @@ fn apply_block_relocations(
fn apply_add_relocations(obj: &mut ObjInfo, relocations: &[AddRelocationConfig]) -> Result<()> {
for reloc in relocations {
let SectionAddress { section, address } = reloc.source.resolve(obj)?;
let (target_symbol, _) = match obj.symbols.by_name(&reloc.target)? {
let (target_symbol, _) = match obj.symbols.by_ref(&obj.sections, &reloc.target)? {
Some(v) => v,
None => {
// Assume external symbol