diff --git a/src/main/java/cafeloader/Cafe_ElfExtension.java b/src/main/java/cafeloader/Cafe_ElfExtension.java index 880bbb8..60ea0bc 100644 --- a/src/main/java/cafeloader/Cafe_ElfExtension.java +++ b/src/main/java/cafeloader/Cafe_ElfExtension.java @@ -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; } diff --git a/src/main/java/cafeloader/Cafe_ElfRelocationHandler.java b/src/main/java/cafeloader/Cafe_ElfRelocationHandler.java index 58f5d55..9fb2d29 100644 --- a/src/main/java/cafeloader/Cafe_ElfRelocationHandler.java +++ b/src/main/java/cafeloader/Cafe_ElfRelocationHandler.java @@ -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 { - program.getReferenceManager().addExternalReference(relocationAddress, 1, - location, SourceType.IMPORTED, RefType.UNCONDITIONAL_CALL); + 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); }