Improve data references.

This commit is contained in:
James Benton 2019-10-03 11:13:54 +01:00
parent 3eda80f7c5
commit 3275fe9c7f
2 changed files with 18 additions and 2 deletions

View File

@ -113,6 +113,15 @@ public class Cafe_ElfExtension extends ElfExtension {
return false;
}
// Force .dimport section to writeable so compiler does not inline
// the value... even though its external...
// TODO: Maybe there is a better way to define .dimport/.fimport
// sections as not real loaded in memory sections so that the
// compiler does not inline it's values?
if (name != null && name.startsWith(".dimport")) {
return true;
}
return (section.getFlags() & ElfSectionHeaderConstants.SHF_WRITE) != 0;
}

View File

@ -47,9 +47,11 @@ public class Cafe_ElfRelocationHandler extends ElfRelocationHandler {
ElfSectionHeader symbolSection = elf.getSections()[sym.getSectionHeaderIndex()];
if (symbolSection.getType() == Cafe_ElfExtension.SHT_RPL_IMPORTS.value) {
String symbolSectionName = symbolSection.getNameAsString();
boolean isDataImport = false;
if (symbolSectionName.startsWith(".dimport_")) {
program.getReferenceManager().addMemoryReference(relocationAddress,
elfRelocationContext.getSymbolAddress(sym), RefType.DATA, SourceType.IMPORTED, 0);
isDataImport = true;
} else if (symbolSectionName.startsWith(".fimport_")) {
program.getReferenceManager().addMemoryReference(relocationAddress,
elfRelocationContext.getSymbolAddress(sym), RefType.UNCONDITIONAL_CALL, SourceType.IMPORTED, 0);
@ -63,8 +65,13 @@ public class Cafe_ElfRelocationHandler extends ElfRelocationHandler {
ExternalLocation location = program.getExternalManager().getUniqueExternalLocation(rplName, sym.getNameAsString());
if (location != null) {
try {
if (isDataImport) {
program.getReferenceManager().addExternalReference(relocationAddress, 1,
location, SourceType.IMPORTED, RefType.DATA);
} else {
program.getReferenceManager().addExternalReference(relocationAddress, 1,
location, SourceType.IMPORTED, RefType.UNCONDITIONAL_CALL);
}
} catch (InvalidInputException e) {
Msg.warn(this, "addExternalReference failed with " + e);
}