Skip to content

Commit

Permalink
fix globalMapping func inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sadrabt committed Nov 25, 2024
1 parent 1a9e118 commit 1f89d21
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
9 changes: 5 additions & 4 deletions src/main/scala/analysis/data_structure_analysis/Graph.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/analysis/data_structure_analysis/Utility.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ object NodeCounter {

class Flags() {
var collapsed = false
var function = false
var stack = false
var heap = false
var global = false
Expand All @@ -40,6 +41,7 @@ class Flags() {
modified = other.modified || modified
incomplete = other.incomplete || incomplete
foreign = other.foreign && foreign
function = function || other.function
}

/**
Expand Down
26 changes: 13 additions & 13 deletions src/test/scala/DataStructureAnalysisTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))))

}

Expand Down Expand Up @@ -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))))
}
Expand Down

0 comments on commit 1f89d21

Please sign in to comment.