From 1f89d2178c06b31091ebcd47f891de57211b08be Mon Sep 17 00:00:00 2001 From: Sadra Bayat Tork Date: Mon, 25 Nov 2024 11:54:44 +1000 Subject: [PATCH] fix globalMapping func inconsistencies --- .../data_structure_analysis/Graph.scala | 9 ++++--- .../SymbolicAddressAnalysis.scala | 2 ++ .../data_structure_analysis/Utility.scala | 2 ++ .../scala/DataStructureAnalysisTest.scala | 26 +++++++++---------- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/main/scala/analysis/data_structure_analysis/Graph.scala b/src/main/scala/analysis/data_structure_analysis/Graph.scala index a1463068d..41d480150 100644 --- a/src/main/scala/analysis/data_structure_analysis/Graph.scala +++ b/src/main/scala/analysis/data_structure_analysis/Graph.scala @@ -196,17 +196,18 @@ class Graph(val proc: Procedure, global match case FuncEntry(name, size, address) => val func = Node(Some(this), size) - func.allocationRegions.add(DataLocation(name, address, size / 8)) + func.allocationRegions.add(Function(name)) func.flags.global = true func.flags.incomplete = true + func.flags.function = true // globalMapping.update(AddressRange(address, address + (size / 8)), Field(func, 0)) - val pointer = Node(Some(this), 0) - pointer.allocationRegions.add(DataLocation(s"$name's pointer@$address", address, 0)) // todo check that size 0 is correct + val pointer = Node(Some(this), size) + pointer.allocationRegions.add(DataLocation(name, address, size / 8)) // todo check that size 0 is correct pointer.flags.global = true pointer.flags.incomplete = true pointer.cells(0).pointee = Some(Slice(func.cells(0), 0)) - globalMapping.update(AddressRange(address, address), Field(pointer, 0)) + globalMapping.update(AddressRange(address, address + (size / 8)), Field(pointer, 0)) case SpecGlobal(name, size, arraySize, address) => val node = Node(Some(this), size) node.allocationRegions.add(DataLocation(name, address, size / 8)) diff --git a/src/main/scala/analysis/data_structure_analysis/SymbolicAddressAnalysis.scala b/src/main/scala/analysis/data_structure_analysis/SymbolicAddressAnalysis.scala index a66b7f616..7323d5566 100644 --- a/src/main/scala/analysis/data_structure_analysis/SymbolicAddressAnalysis.scala +++ b/src/main/scala/analysis/data_structure_analysis/SymbolicAddressAnalysis.scala @@ -29,6 +29,8 @@ case class DataLocation(override val regionIdentifier: String, start: BigInt, si override def toString: String = s"Data($regionIdentifier, $start, $size)" } +case class Function(override val regionIdentifier: String) extends MemoryLocation + case class UnknownLocation(override val regionIdentifier: String, proc: Procedure) extends MemoryLocation { override def toString: String = s"Unknown($regionIdentifier)" } diff --git a/src/main/scala/analysis/data_structure_analysis/Utility.scala b/src/main/scala/analysis/data_structure_analysis/Utility.scala index 15ffc657b..38bb08860 100644 --- a/src/main/scala/analysis/data_structure_analysis/Utility.scala +++ b/src/main/scala/analysis/data_structure_analysis/Utility.scala @@ -21,6 +21,7 @@ object NodeCounter { class Flags() { var collapsed = false + var function = false var stack = false var heap = false var global = false @@ -40,6 +41,7 @@ class Flags() { modified = other.modified || modified incomplete = other.incomplete || incomplete foreign = other.foreign && foreign + function = function || other.function } /** diff --git a/src/test/scala/DataStructureAnalysisTest.scala b/src/test/scala/DataStructureAnalysisTest.scala index 45c18c272..6c31ee700 100644 --- a/src/test/scala/DataStructureAnalysisTest.scala +++ b/src/test/scala/DataStructureAnalysisTest.scala @@ -80,21 +80,21 @@ class DataStructureAnalysisTest extends AnyFunSuite { assert(dsg.adjust(stack72.getPointee).equals(dsg.adjust(dsg.formals(R30)))) // R31 + 8 points to the link register // overlapping access - assert(dsg.adjust(stack16.getPointee).equals(dsg.find(dsg.globalMapping(AddressRange(1876, 1876)).node.cells(0)))) - assert(dsg.adjust(stack24.getPointee).equals(dsg.find(dsg.globalMapping(AddressRange(1896, 1896)).node.cells(0)))) + assert(dsg.adjust(stack16.getPointee).equals(dsg.find(dsg.globalMapping(AddressRange(1876, 1876 + 20)).node.cells(0)))) + assert(dsg.adjust(stack24.getPointee).equals(dsg.find(dsg.globalMapping(AddressRange(1896, 1896 + 20)).node.cells(0)))) - assert(!dsg.find(dsg.globalMapping(AddressRange(1876, 1876)).node.cells(0)).equals(dsg.find(dsg.globalMapping(AddressRange(1896, 1896)).node.cells(0)))) - assert(dsg.find(dsg.globalMapping(AddressRange(1876, 1876)).node.cells(0)).node.get.equals(dsg.find(dsg.globalMapping(AddressRange(1896, 1896)).node.cells(0)).node.get)) + assert(!dsg.find(dsg.globalMapping(AddressRange(1876, 1876 + 20)).node.cells(0)).equals(dsg.find(dsg.globalMapping(AddressRange(1896, 1896 + 20)).node.cells(0)))) + assert(dsg.find(dsg.globalMapping(AddressRange(1876, 1876 + 20)).node.cells(0)).node.get.equals(dsg.find(dsg.globalMapping(AddressRange(1896, 1896 + 20)).node.cells(0)).node.get)) - assert(dsg.find(dsg.globalMapping(AddressRange(1876, 1876)).node.cells(0)).offset.equals(0)) - assert(dsg.find(dsg.globalMapping(AddressRange(1896, 1896)).node.cells(0)).offset.equals(8)) + assert(dsg.find(dsg.globalMapping(AddressRange(1876, 1876 + 20)).node.cells(0)).offset.equals(0)) + assert(dsg.find(dsg.globalMapping(AddressRange(1896, 1896 + 20)).node.cells(0)).offset.equals(8)) - assert(dsg.adjust(dsg.SSAVar("%00000429$1", "R8")).equals(dsg.find(dsg.globalMapping(AddressRange(1876, 1876)).node.cells(0)))) - assert(dsg.adjust(dsg.SSAVar("%00000438$1", "R8")).equals(dsg.find(dsg.globalMapping(AddressRange(1896, 1896)).node.cells(0)))) + assert(dsg.adjust(dsg.SSAVar("%00000429$1", "R8")).equals(dsg.find(dsg.globalMapping(AddressRange(1876, 1876 + 20)).node.cells(0)))) + assert(dsg.adjust(dsg.SSAVar("%00000438$1", "R8")).equals(dsg.find(dsg.globalMapping(AddressRange(1896, 1896 + 20)).node.cells(0)))) - assert(dsg.adjust(stack32.getPointee).equals(dsg.find(dsg.globalMapping(AddressRange(1916, 1916)).node.cells(0)))) + assert(dsg.adjust(stack32.getPointee).equals(dsg.find(dsg.globalMapping(AddressRange(1916, 1916 + 20)).node.cells(0)))) } @@ -287,13 +287,13 @@ class DataStructureAnalysisTest extends AnyFunSuite { // jump_table relocation assert(dsg.adjust(dsg.globalMapping(AddressRange(69624, 69624 + 8)).node.cells(0).getPointee).equals(dsg.find(dsg.globalMapping(AddressRange(69656, 69656 + 24)).node.cells(0)))) // add_two relocation - assert(dsg.adjust(dsg.globalMapping(AddressRange(69656, 69656 + 24)).node.cells(0).getPointee).equals(dsg.find(dsg.globalMapping(AddressRange(1940, 1940)).node.cells(0)))) + assert(dsg.adjust(dsg.globalMapping(AddressRange(69656, 69656 + 24)).node.cells(0).getPointee).equals(dsg.find(dsg.globalMapping(AddressRange(1940, 1940 + 36)).node.cells(0)))) // add_six relocation - assert(dsg.adjust(dsg.globalMapping(AddressRange(69656, 69656 + 24)).node.cells(8).getPointee).equals(dsg.find(dsg.globalMapping(AddressRange(1976, 1976)).node.cells(0)))) + assert(dsg.adjust(dsg.globalMapping(AddressRange(69656, 69656 + 24)).node.cells(8).getPointee).equals(dsg.find(dsg.globalMapping(AddressRange(1976, 1976 + 36)).node.cells(0)))) // sub_seven relocation - assert(dsg.adjust(dsg.globalMapping(AddressRange(69656, 69656 + 24)).node.cells(16).getPointee).equals(dsg.find(dsg.globalMapping(AddressRange(2012, 2012)).node.cells(0)))) + assert(dsg.adjust(dsg.globalMapping(AddressRange(69656, 69656 + 24)).node.cells(16).getPointee).equals(dsg.find(dsg.globalMapping(AddressRange(2012, 2012 + 36)).node.cells(0)))) // main relocation - assert(dsg.adjust(dsg.globalMapping(AddressRange(69608, 69608 + 8)).node.cells(0).getPointee).equals(dsg.find(dsg.globalMapping(AddressRange(2048, 2048)).node.cells(0)))) + assert(dsg.adjust(dsg.globalMapping(AddressRange(69608, 69608 + 8)).node.cells(0).getPointee).equals(dsg.find(dsg.globalMapping(AddressRange(2048, 2048 + 76)).node.cells(0)))) // x relocation assert(dsg.adjust(dsg.globalMapping(AddressRange(69592, 69592 + 8)).node.cells(0).getPointee).equals(dsg.find(dsg.globalMapping(AddressRange(69648, 69648 + 4)).node.cells(0)))) }