Skip to content

Commit

Permalink
fixes to Global Function sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
sadrabt committed Nov 27, 2024
1 parent 7ef566f commit 09c5b18
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
29 changes: 12 additions & 17 deletions src/main/scala/analysis/data_structure_analysis/Graph.scala
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,17 @@ class Graph(val proc: Procedure,
val globalMapping = mutable.Map[AddressRange, Field]()
globals.foreach {
case FuncEntry(name, size, address) =>
val func = Node(Some(this), size)
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), size)
pointer.allocationRegions.add(DataPointer(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 + (size / 8)), Field(pointer, 0))

val function = Node(Some(this), size/8)
function.cells(0).growSize(size/8)
function.allocationRegions.add(Function(name, address, size / 8)) // todo check that size 0 is correct
function.flags.global = true
function.flags.incomplete = true
globalMapping.update(AddressRange(address, address + (size / 8)), Field(function, 0))
case SpecGlobal(name, size, arraySize, address) =>
val node = Node(Some(this), size)
node.allocationRegions.add(DataPointer(name, address, size / 8))

val node = Node(Some(this), size/8)
node.allocationRegions.add(DataLocation(name, address, size / 8))
node.flags.global = true
node.flags.incomplete = true
globalMapping.update(AddressRange(address, address + size / 8), Field(node, 0))
Expand All @@ -235,7 +230,7 @@ class Graph(val proc: Procedure,

case None =>
val node = Node(Some(this))
node.allocationRegions.add(DataPointer(s"Relocated_$relocatedAddress", relocatedAddress, 8))
node.allocationRegions.add(DataLocation(s"Relocated_$relocatedAddress", relocatedAddress, 8))
node.flags.global = true
node.flags.incomplete = true
globalMapping.update(AddressRange(relocatedAddress, relocatedAddress + 8), Field(node, 0))
Expand All @@ -249,7 +244,7 @@ class Graph(val proc: Procedure,

externalFunctions.foreach { external =>
val node = Node(Some(this))
node.allocationRegions.add(DataPointer(external.name, external.offset, 0))
node.allocationRegions.add(DataLocation(external.name, external.offset, 0))
node.flags.global = true
node.flags.incomplete = true
globalMapping.update(AddressRange(external.offset, external.offset), Field(node, 0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ case class SymbolicAddress(accessor: Variable, symbolicBase: MemoryLocation, off

trait MemoryLocation {
val regionIdentifier: String
}


override def toString: String = s"MemoryRegion($regionIdentifier)"
trait GlobalLocation {
val start: BigInt
val size: BigInt
}

case class StackLocation(override val regionIdentifier: String, proc: Procedure, size: BigInt) extends MemoryLocation {
Expand All @@ -25,11 +29,15 @@ case class HeapLocation(override val regionIdentifier: String, proc: Procedure,
override def toString: String = s"Heap($regionIdentifier, $size)"
}

case class DataPointer(override val regionIdentifier: String, start: BigInt, size: BigInt) extends MemoryLocation {
case class DataLocation(override val regionIdentifier: String, override val start: BigInt, override val size: BigInt)
extends MemoryLocation, GlobalLocation {
override def toString: String = s"Data($regionIdentifier, $start, $size)"
}

case class Function(override val regionIdentifier: String) extends MemoryLocation
case class Function(regionIdentifier: String, start: BigInt, size: BigInt) extends MemoryLocation, GlobalLocation{
override def toString: String = s"Func($regionIdentifier, $start, $size)"
}


case class UnknownLocation(override val regionIdentifier: String, proc: Procedure) extends MemoryLocation {
override def toString: String = s"Unknown($regionIdentifier)"
Expand Down
6 changes: 4 additions & 2 deletions src/test/scala/DataStructureAnalysisTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ class DataStructureAnalysisTest extends AnyFunSuite {
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 + 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)).equals(dsg.find(dsg.globalMapping(AddressRange(1896, 1896 + 20)).node.cells(0))))
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 + 20)).node.cells(0)).offset.equals(0))
assert(dsg.find(dsg.globalMapping(AddressRange(1896, 1896 + 20)).node.cells(0)).offset.equals(8))
assert(dsg.find(dsg.globalMapping(AddressRange(1896, 1896 + 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 + 20)).node.cells(0))))
assert(dsg.adjust(dsg.SSAVar("%00000438$1", "R8")).equals(dsg.find(dsg.globalMapping(AddressRange(1896, 1896 + 20)).node.cells(0))))
Expand Down

0 comments on commit 09c5b18

Please sign in to comment.