Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
595756a
case class readelf, toscala readelf, --dump-relf
katrinafyi Jun 20, 2025
ba5dec4
we can get external function symbols. TODO: dig into auxdata
katrinafyi Jun 20, 2025
167325f
new AuxDecoder for compositional decoding of AuxData
katrinafyi Jun 20, 2025
7397b88
use auxdecoder in gtirb loader
katrinafyi Jun 20, 2025
efdf667
scalafmt
katrinafyi Jun 20, 2025
19df41e
i cant tell if this is shorter
katrinafyi Jun 20, 2025
191730d
foldLeft1 is just reduce - allie
katrinafyi Jun 20, 2025
fe91ff6
Merge remote-tracking branch 'origin/mapdecoder2' into gtirb-relf
katrinafyi Jun 20, 2025
b94a1a4
what the fkkkkkkkkkkkkkkkkkk
katrinafyi Jun 20, 2025
cebe023
kaitai https://formats.kaitai.io/elf/java.html
katrinafyi Jun 20, 2025
31e0cfe
kaitai integration. ASS BECAUSE SCALA [no ci]
katrinafyi Jun 20, 2025
f67df70
Revert "kaitai integration. ASS BECAUSE SCALA [no ci]"
katrinafyi Jun 21, 2025
6adf92d
Revert "kaitai https://formats.kaitai.io/elf/java.html"
katrinafyi Jun 21, 2025
677bea2
groupMapReduce
katrinafyi Jun 21, 2025
1f80736
change r_type to long, add docs. BTW, ...
katrinafyi Jun 21, 2025
856616c
unfold
katrinafyi Jun 21, 2025
1d280c8
a lot more work. all parts from readelfloader work now
katrinafyi Jun 21, 2025
805342f
ToScala: deriving creates multi-line output sometimes
katrinafyi Jun 21, 2025
8f9911f
scalafmt
katrinafyi Jun 21, 2025
3c45043
tehe revert me
katrinafyi Jun 21, 2025
91d84c0
macros lol
katrinafyi Jun 21, 2025
5f86644
auto tupling??
katrinafyi Jun 21, 2025
e6e38a5
ReadTuple
katrinafyi Jun 22, 2025
1446863
move
katrinafyi Jun 22, 2025
018da5f
resolver
katrinafyi Jun 22, 2025
0e38d1b
Revert "tehe revert me"
katrinafyi Jun 23, 2025
a2e49bd
Merge remote-tracking branch 'origin/main' into gtirb-relf
katrinafyi Jun 23, 2025
c7e98f6
scalafmt
katrinafyi Jun 23, 2025
615f9bb
Merge remote-tracking branch 'origin/main' into gtirb-relf
katrinafyi Jun 23, 2025
07fc539
allow string in Uuid inputs
katrinafyi Jun 23, 2025
c23d19f
docs
katrinafyi Jun 23, 2025
b058f74
construct ReadELFData struct
katrinafyi Jun 23, 2025
96fcd87
diffing. WHY IS IT OFF BY 8 RAHHH
katrinafyi Jun 23, 2025
6e75244
--dump-relf writes files now
katrinafyi Jun 23, 2025
4d44074
fix size bug in global variables
katrinafyi Jun 23, 2025
1c88565
scalfmt
katrinafyi Jun 23, 2025
20a77b5
fix atEnd bug! yay. it all matches now except crtstuff.c ??
katrinafyi Jun 23, 2025
742a84a
scalafmt
katrinafyi Jun 23, 2025
dad7b02
touch up docs and fix references
katrinafyi Jun 23, 2025
56be8ae
rename to ref
katrinafyi Jun 23, 2025
5eb9db6
make it not crash. TODO: global library variables are borked
katrinafyi Jun 23, 2025
10f68c2
no println
katrinafyi Jun 23, 2025
bedc54d
scalafmt
katrinafyi Jun 25, 2025
28cb1a8
.sorted method for ReadELFData
katrinafyi Jun 25, 2025
f0de62e
working on R_AARCH64_COPY. add SECTION entries too
katrinafyi Jun 26, 2025
bb019a1
fix relocated global objects
katrinafyi Jun 26, 2025
9aa41b4
checkset, remove -100 symbols
katrinafyi Jun 26, 2025
1052400
scalafmt
katrinafyi Jun 26, 2025
53275d3
urls in doc comments
katrinafyi Jun 26, 2025
62cb830
type annotations
katrinafyi Jun 26, 2025
d6b688a
Merge remote-tracking branch 'origin/main' into gtirb-relf
katrinafyi Jun 26, 2025
3b99169
format
katrinafyi Jun 26, 2025
698d42d
Merge remote-tracking branch 'origin/main' into gtirb-relf
katrinafyi Jun 27, 2025
e4afa50
reformat
katrinafyi Jun 27, 2025
fd8500b
Merge remote-tracking branch 'origin/main' into gtirb-relf
katrinafyi Jul 8, 2025
b7a5165
touch scaladoc mappings
katrinafyi Jul 8, 2025
71e1cf5
--gts-relf argument to use inputFile as relfFile
katrinafyi Jul 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions basilmill/basildocs.mill
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ trait BasilDocs extends ScalaModule {

def scalaDocExternalMappingOptions = Task {
val defaultExternals = Seq(
".*scala/.*::scaladoc3::https://scala-lang.org/api/3.3_LTS/",
"java/.*::javadoc::https://docs.oracle.com/en/java/javase/17/docs/api/java.base/",
".*com/google/protobuf.*::javadoc::https://protobuf.dev/reference/java/api-docs/",
".*/scala/.*::scaladoc3::https://scala-lang.org/api/3.3_LTS/",
".*/java/.*::javadoc::https://docs.oracle.com/en/java/javase/17/docs/api/java.base/",
".*/com/google/protobuf.*::javadoc::https://protobuf.dev/reference/java/api-docs/",
)
val externals = defaultExternals ++ docsRegexes().map {
case (path, regex) => s"$regex::$baseUrl/$path"
Expand Down
65 changes: 63 additions & 2 deletions src/main/scala/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ import util.{
BoogieMemoryAccessMode,
DSAConfig,
DebugDumpIRLogger,
FrontendMode,
ILLoadingConfig,
IRLoading,
LogLevel,
Logger,
MemoryRegionsMode,
PCTrackingOption,
ProcRelyVersion,
RunUtils,
StaticAnalysisConfig
StaticAnalysisConfig,
writeToFile
}

import scala.language.postfixOps
Expand Down Expand Up @@ -144,6 +147,12 @@ object Main {
doc = "Switch version of procedure rely/guarantee checks to emit. (function|ifblock)"
)
procedureRG: Option[String],
@arg(
name = "gts-relf",
doc =
"Use .gts file for obtaining ELF symbol information (overrides --relf) (defaults to true if using GTIRB input and no --relf)"
)
useGTIRBReadELF: Flag,
@arg(name = "verbose", short = 'v', doc = "Show extra debugging logs (the same as -vl log)")
verbose: Flag,
@arg(
Expand All @@ -157,6 +166,8 @@ object Main {
interpret: Flag,
@arg(name = "dump-il", doc = "Dump the Intermediate Language to text.")
dumpIL: Option[String],
@arg(name = "dump-relf", doc = "Dump Basil's representation of the readelf information to the given file and exit.")
dumpRelf: Option[String],
@arg(name = "main-procedure-name", short = 'm', doc = "Name of the main procedure to begin analysis at.")
mainProcedureName: String = "main",
@arg(
Expand Down Expand Up @@ -335,7 +346,7 @@ object Main {
val boogieGeneratorConfig =
BoogieGeneratorConfig(boogieMemoryAccessMode, true, rely, conf.threadSplit.value, conf.noif.value)

val loadingInputs = if (conf.bapInputDirName.isDefined) then {
var loadingInputs = if (conf.bapInputDirName.isDefined) then {
loadDirectory(ChooseInput.Bap, conf.bapInputDirName.get)

} else if (conf.gtirbInputDirName.isDefined) then {
Expand All @@ -350,6 +361,56 @@ object Main {
)
}

val isGTIRB = loadingInputs.frontendMode == FrontendMode.Gtirb

// NOTE: --dump-relf ignores --gts-relf, to ensure that the output ELF files are correctly named
conf.dumpRelf match {
case None => ()
case Some(relfOut) =>

val gtirbRelfFile = Some(loadingInputs.inputFile).filter(_ => isGTIRB)
val realRelfFile = loadingInputs.relfFile

Logger.setLevel(LogLevel.DEBUG)
val (relf, gtirb) = (realRelfFile, gtirbRelfFile) match {
case (Some(relfFile), _) =>
val (a, b) = IRLoading.loadReadELFWithGTIRB(relfFile, loadingInputs)
(Some(a), b)
case (None, Some(_)) => (None, Some(IRLoading.loadGTIRBReadELF(loadingInputs)))
case _ => throw IllegalArgumentException("--dump-relf requires either --relf or a GTIRB input")
}

// skip writing files if the given path is an empty string. this checks compatibility and exits.
if (relfOut.trim.isEmpty)
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Significant indentation 👎


relf match {
case Some(relf) =>
writeToFile(
relf.sorted.toScala
.replace("@GLIBC_2.17", "")
.replace("@GLIBC_2.38", "")
.replace("@GLIBC_2.34", ""),
relfOut + "-readelf.scala"
)
case None => Logger.warn(s"Failed to load .relf information, $relfOut-readelf.scala not written")
}
gtirb match {
case Some(relf) => writeToFile(relf.sorted.toScala, relfOut + "-gtsrelf.scala")
case None => Logger.warn(s"Failed to load GTIRB information, $relfOut-gtsrelf.scala not written")
}
return
}

// patch in gtirb-as-relf if directed or if relf is omitted but we are using gtirb.
// NOTE: this must be done early, because lots of later places make checks about loadingInputs.relfFile.
if (conf.useGTIRBReadELF.value || (isGTIRB && loadingInputs.relfFile.isEmpty)) {
if (!isGTIRB) {
throw IllegalArgumentException("--gts-relf requires a GTIRB input")
}
loadingInputs = loadingInputs.copy(relfFile = Some(loadingInputs.inputFile))
}

if (loadingInputs.specFile.isDefined && loadingInputs.relfFile.isEmpty) {
throw IllegalArgumentException("--spec requires --relf")
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/boogie/BExpr.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package boogie
import ir.*
import ir.dsl.given
import specification.*
import util.assertion.*

Expand Down Expand Up @@ -788,7 +789,7 @@ case class SpecGlobal(
arraySize: Option[Int],
override val address: BigInt
) extends SymbolTableEntry,
SpecGlobalOrAccess {
SpecGlobalOrAccess derives ir.dsl.ToScala {
override def specGlobals: Set[SpecGlobalOrAccess] = Set(this)

def sanitisedName = util.StringEscape.escape(name)
Expand Down
21 changes: 18 additions & 3 deletions src/main/scala/gtirb/AuxDecoder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ object AuxDecoder {

/**
* [[AuxKind]] provides pre-defined decoders for some official AuxData fields. An [[AuxKind]] can be
* passed to [[decodeAux]] to automatically extract and decode the given AuxData from a GTIRB
* [[com.grammatech.gtirb.proto.Module.Module]].
* passed to [[decodeAux]] to automatically extract and decode the given AuxData from a GTIRB [[com.grammatech.gtirb.proto.Module.Module]].
* See the [Standard AuxData Schemata](https://grammatech.github.io/gtirb/md__aux_data.html) for a list of official AuxData fields
* and their types.
*/
enum AuxKind[T](val name: String, val decoder: Decoder[T]) {
case ElfSymbolTabIdxInfo
Expand All @@ -40,13 +41,16 @@ object AuxDecoder {
"elfSymbolInfo",
readMap(readUuid, readTuple(readUint(64), readString, readString, readString, readUint(64)))
)
case SectionProperties
extends AuxKind("sectionProperties", readMap(readUuid, readTuple(readUint(64), readUint(64))))
case FunctionEntries extends AuxKind("functionEntries", readMap(readUuid, readSet(readUuid)))
case FunctionBlocks extends AuxKind("functionBlocks", readMap(readUuid, readSet(readUuid)))
case FunctionNames extends AuxKind("functionNames", readMap(readUuid, readUuid))
case SymbolForwarding extends AuxKind("symbolForwarding", readMap(readUuid, readUuid))
}

type Input = ByteArrayInputStream
type Decoder[T] = Input => T
type Decoder[T] = ByteArrayInputStream => T

def decodeAux[T](known: AuxKind[T])(mod: Module) =
decode(known.decoder)(mod.auxData(known.name))
Expand Down Expand Up @@ -145,6 +149,17 @@ object AuxDecoder {
val x6 = r6(bs)
(x1, x2, x3, x4, x5, x6)

// type ReadTuple[T <: Tuple] <: Tuple = T match
// case Reader[out] *: rest => out *: ReadTuple[rest]
// case EmptyTuple => EmptyTuple
//
// inline def readTuple[T <: Tuple](xs: T)(bs: Input): ReadTuple[T] =
// inline xs match
// case xs: (Reader[o] *: rest) =>
// xs match
// case h *: t => h(bs) *: readTuple[rest](t)(bs)
// case _: EmptyTuple => EmptyTuple

def readUuid(bs: Input) =
// ByteString.copyFrom(readBytes(16)(bs))
Base64.getEncoder().encodeToString(readBytes(16)(bs))
Expand Down
Loading