From df0b8cd76873c4c07eccb370dae851946a7c2fd7 Mon Sep 17 00:00:00 2001 From: James Benton Date: Wed, 2 Oct 2019 18:31:40 +0100 Subject: [PATCH] Optimise relocations by using getUniqueExternalLocation --- .../cafeloader/Cafe_ElfRelocationHandler.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/cafeloader/Cafe_ElfRelocationHandler.java b/src/main/java/cafeloader/Cafe_ElfRelocationHandler.java index a7c4917..737bc92 100644 --- a/src/main/java/cafeloader/Cafe_ElfRelocationHandler.java +++ b/src/main/java/cafeloader/Cafe_ElfRelocationHandler.java @@ -55,19 +55,23 @@ public class Cafe_ElfRelocationHandler extends ElfRelocationHandler { program.getReferenceManager().addMemoryReference(relocationAddress, elfRelocationContext.getSymbolAddress(sym), RefType.UNCONDITIONAL_CALL, SourceType.IMPORTED, 0); } - - ExternalLocationIterator locations = program.getExternalManager() - .getExternalLocations(elfRelocationContext.getSymbolAddress(sym)); - while (locations.hasNext()) { + + String rplName = symbolSectionName.split("import_")[1]; + if (!rplName.endsWith(".rpl")) { + rplName += ".rpl"; + } + + ExternalLocation location = program.getExternalManager().getUniqueExternalLocation(rplName, sym.getNameAsString()); + if (location != null) { try { - ExternalLocation location = locations.next(); program.getReferenceManager().addExternalReference(relocationAddress, 1, - location, SourceType.IMPORTED, RefType.UNCONDITIONAL_CALL); + location, SourceType.IMPORTED, RefType.UNCONDITIONAL_CALL); } catch (InvalidInputException e) { Msg.warn(this, "addExternalReference failed with " + e); } + } else { + Msg.warn(this, "Failed to find location for " + sym.getNameAsString()); } - } switch (type) {