diff --git a/macaw-riscv-symbolic/tests/Main.hs b/macaw-riscv-symbolic/tests/Main.hs index f6b9ad54..cb62f6cc 100644 --- a/macaw-riscv-symbolic/tests/Main.hs +++ b/macaw-riscv-symbolic/tests/Main.hs @@ -32,7 +32,6 @@ import qualified Test.Tasty.Runners as TTR import qualified Data.Macaw.Architecture.Info as MAI import qualified Data.Macaw.CFG as MC import qualified Data.Macaw.Discovery as M -import qualified Data.Macaw.Memory.ElfLoader.PLTStubs as MMELP import qualified Data.Macaw.Symbolic as MS import qualified Data.Macaw.Symbolic.Testing as MST import qualified Data.Macaw.RISCV as MR @@ -133,8 +132,8 @@ symExTestSized :: forall rv w arch , 16 <= w , MC.ArchConstraints arch , arch ~ MR.RISCV rv + , Elf.ElfWidthConstraints w , KnownNat w - , Show (Elf.ElfWordType w) , MS.ArchInfo arch ) => MST.SimulationResult @@ -147,12 +146,7 @@ symExTestSized :: forall rv w arch -> MAI.ArchitectureInfo arch -> TTH.Assertion symExTestSized expected mmPreset exePath saveSMT saveMacaw step ehi archInfo = do - binfo <- MST.runDiscovery ehi exePath MST.toAddrSymMap archInfo - -- Test cases involving shared libraries are not - -- yet supported on the RISC-V backend. At a - -- minimum, this is blocked on - -- https://github.com/GaloisInc/elf-edit/issues/36. - (MMELP.noPLTStubInfo "RISC-V") + binfo <- MST.runDiscovery ehi exePath MST.toAddrSymMap archInfo MR.riscvPLTStubInfo let funInfos = Map.elems (MST.binaryDiscState (MST.mainBinaryInfo binfo) ^. M.funInfo) let testEntryPoints = mapMaybe hasTestPrefix funInfos F.forM_ testEntryPoints $ \(name, Some dfi) -> do diff --git a/macaw-riscv-symbolic/tests/pass/Makefile b/macaw-riscv-symbolic/tests/pass/Makefile index c6ec3a4d..27b942fb 100644 --- a/macaw-riscv-symbolic/tests/pass/Makefile +++ b/macaw-riscv-symbolic/tests/pass/Makefile @@ -2,6 +2,7 @@ CC64=riscv64-linux-musl-gcc CC32=riscv32-linux-musl-gcc CFLAGS=-nostdlib -no-pie -static -fno-stack-protector +SO_CFLAGS=-nostdlib -fno-stack-protector -fcf-protection=none unopt32 = $(patsubst %.c,%.unopt32.exe,$(wildcard *.c)) unopt64 = $(patsubst %.c,%.unopt64.exe,$(wildcard *.c)) @@ -21,3 +22,33 @@ all: $(unopt32) $(opt32) $(unopt64) $(opt64) %.opt64.exe : %.c $(CC64) $(CFLAGS) -O2 $< -o $@ + +so/libfib.unopt32.so: so/fib.c so/libgetone.unopt32.so + $(CC32) $(SO_CFLAGS) -O0 -Lso/ -Iso/ -shared $< -lgetone.unopt32 -o $@ +so/libfib.opt32.so: so/fib.c so/libgetone.opt32.so + $(CC32) $(SO_CFLAGS) -O2 -Lso/ -Iso/ -shared $< -lgetone.opt32 -o $@ + +so/libgetone.unopt32.so : so/getone.c + $(CC32) $(SO_CFLAGS) -O0 -Iso/ -shared $< -o $@ +so/libgetone.opt32.so : so/getone.c + $(CC32) $(SO_CFLAGS) -O2 -Iso/ -shared $< -o $@ + +so/so.unopt32.exe : so/so.c so/libfib.unopt32.so + $(CC32) $(SO_CFLAGS) -O0 -Lso/ -Iso/ $< -lfib.unopt32 -lgetone.unopt32 -o $@ +so/so.opt32.exe : so/so.c so/libfib.opt32.so + $(CC32) $(SO_CFLAGS) -O2 -Lso/ -Iso/ $< -lfib.opt32 -lgetone.opt32 -o $@ + +so/libfib.unopt64.so: so/fib.c so/libgetone.unopt64.so + $(CC64) $(SO_CFLAGS) -O0 -Lso/ -Iso/ -shared $< -lgetone.unopt64 -o $@ +so/libfib.opt64.so: so/fib.c so/libgetone.opt64.so + $(CC64) $(SO_CFLAGS) -O2 -Lso/ -Iso/ -shared $< -lgetone.opt64 -o $@ + +so/libgetone.unopt64.so : so/getone.c + $(CC64) $(SO_CFLAGS) -O0 -Iso/ -shared $< -o $@ +so/libgetone.opt64.so : so/getone.c + $(CC64) $(SO_CFLAGS) -O2 -Iso/ -shared $< -o $@ + +so/so.unopt64.exe : so/so.c so/libfib.unopt64.so + $(CC64) $(SO_CFLAGS) -O0 -Lso/ -Iso/ $< -lfib.unopt64 -lgetone.unopt64 -o $@ +so/so.opt64.exe : so/so.c so/libfib.opt64.so + $(CC64) $(SO_CFLAGS) -O2 -Lso/ -Iso/ $< -lfib.opt64 -lgetone.opt64 -o $@ diff --git a/macaw-riscv-symbolic/tests/pass/so/fib.c b/macaw-riscv-symbolic/tests/pass/so/fib.c new file mode 100644 index 00000000..60f439fd --- /dev/null +++ b/macaw-riscv-symbolic/tests/pass/so/fib.c @@ -0,0 +1,8 @@ +#include "fib.h" +#include "getone.h" + +int fib(int n) { + if (n <= 0) return 0; + if (n == 1) return getone(); + return fib(n - 1) + fib(n - 2); +} diff --git a/macaw-riscv-symbolic/tests/pass/so/fib.h b/macaw-riscv-symbolic/tests/pass/so/fib.h new file mode 100644 index 00000000..a55848d7 --- /dev/null +++ b/macaw-riscv-symbolic/tests/pass/so/fib.h @@ -0,0 +1 @@ +int fib(int x); diff --git a/macaw-riscv-symbolic/tests/pass/so/getone.c b/macaw-riscv-symbolic/tests/pass/so/getone.c new file mode 100644 index 00000000..6cef4ed8 --- /dev/null +++ b/macaw-riscv-symbolic/tests/pass/so/getone.c @@ -0,0 +1,5 @@ +#include "getone.h" + +int getone(void) { + return 1; +} diff --git a/macaw-riscv-symbolic/tests/pass/so/getone.h b/macaw-riscv-symbolic/tests/pass/so/getone.h new file mode 100644 index 00000000..a528347d --- /dev/null +++ b/macaw-riscv-symbolic/tests/pass/so/getone.h @@ -0,0 +1 @@ +int getone(void); diff --git a/macaw-riscv-symbolic/tests/pass/so/libfib.opt32.so b/macaw-riscv-symbolic/tests/pass/so/libfib.opt32.so new file mode 100755 index 00000000..ec72edb6 Binary files /dev/null and b/macaw-riscv-symbolic/tests/pass/so/libfib.opt32.so differ diff --git a/macaw-riscv-symbolic/tests/pass/so/libfib.opt64.so b/macaw-riscv-symbolic/tests/pass/so/libfib.opt64.so new file mode 100755 index 00000000..a600fbf1 Binary files /dev/null and b/macaw-riscv-symbolic/tests/pass/so/libfib.opt64.so differ diff --git a/macaw-riscv-symbolic/tests/pass/so/libfib.unopt32.so b/macaw-riscv-symbolic/tests/pass/so/libfib.unopt32.so new file mode 100755 index 00000000..04fa164d Binary files /dev/null and b/macaw-riscv-symbolic/tests/pass/so/libfib.unopt32.so differ diff --git a/macaw-riscv-symbolic/tests/pass/so/libfib.unopt64.so b/macaw-riscv-symbolic/tests/pass/so/libfib.unopt64.so new file mode 100755 index 00000000..5231b232 Binary files /dev/null and b/macaw-riscv-symbolic/tests/pass/so/libfib.unopt64.so differ diff --git a/macaw-riscv-symbolic/tests/pass/so/libgetone.opt32.so b/macaw-riscv-symbolic/tests/pass/so/libgetone.opt32.so new file mode 100755 index 00000000..5076d040 Binary files /dev/null and b/macaw-riscv-symbolic/tests/pass/so/libgetone.opt32.so differ diff --git a/macaw-riscv-symbolic/tests/pass/so/libgetone.opt64.so b/macaw-riscv-symbolic/tests/pass/so/libgetone.opt64.so new file mode 100755 index 00000000..0c151921 Binary files /dev/null and b/macaw-riscv-symbolic/tests/pass/so/libgetone.opt64.so differ diff --git a/macaw-riscv-symbolic/tests/pass/so/libgetone.unopt32.so b/macaw-riscv-symbolic/tests/pass/so/libgetone.unopt32.so new file mode 100755 index 00000000..266904d5 Binary files /dev/null and b/macaw-riscv-symbolic/tests/pass/so/libgetone.unopt32.so differ diff --git a/macaw-riscv-symbolic/tests/pass/so/libgetone.unopt64.so b/macaw-riscv-symbolic/tests/pass/so/libgetone.unopt64.so new file mode 100755 index 00000000..a69d687e Binary files /dev/null and b/macaw-riscv-symbolic/tests/pass/so/libgetone.unopt64.so differ diff --git a/macaw-riscv-symbolic/tests/pass/so/so.c b/macaw-riscv-symbolic/tests/pass/so/so.c new file mode 100644 index 00000000..b8583a9d --- /dev/null +++ b/macaw-riscv-symbolic/tests/pass/so/so.c @@ -0,0 +1,9 @@ +#include "fib.h" + +int __attribute__((noinline)) test_fib(void) { + return fib(6) == 8; +} + +void _start(void) { + test_fib(); +} diff --git a/macaw-riscv-symbolic/tests/pass/so/so.opt32.exe b/macaw-riscv-symbolic/tests/pass/so/so.opt32.exe new file mode 100755 index 00000000..d06d5e36 Binary files /dev/null and b/macaw-riscv-symbolic/tests/pass/so/so.opt32.exe differ diff --git a/macaw-riscv-symbolic/tests/pass/so/so.opt64.exe b/macaw-riscv-symbolic/tests/pass/so/so.opt64.exe new file mode 100755 index 00000000..2c1c0959 Binary files /dev/null and b/macaw-riscv-symbolic/tests/pass/so/so.opt64.exe differ diff --git a/macaw-riscv-symbolic/tests/pass/so/so.unopt32.exe b/macaw-riscv-symbolic/tests/pass/so/so.unopt32.exe new file mode 100755 index 00000000..d588d15a Binary files /dev/null and b/macaw-riscv-symbolic/tests/pass/so/so.unopt32.exe differ diff --git a/macaw-riscv-symbolic/tests/pass/so/so.unopt64.exe b/macaw-riscv-symbolic/tests/pass/so/so.unopt64.exe new file mode 100755 index 00000000..805d29d1 Binary files /dev/null and b/macaw-riscv-symbolic/tests/pass/so/so.unopt64.exe differ diff --git a/macaw-riscv/macaw-riscv.cabal b/macaw-riscv/macaw-riscv.cabal index abc79976..088f9701 100644 --- a/macaw-riscv/macaw-riscv.cabal +++ b/macaw-riscv/macaw-riscv.cabal @@ -25,6 +25,7 @@ library bv-sized, bytestring, containers, + elf-edit, grift, lens, macaw-base, diff --git a/macaw-riscv/src/Data/Macaw/RISCV.hs b/macaw-riscv/src/Data/Macaw/RISCV.hs index acac5628..c7a79ea3 100644 --- a/macaw-riscv/src/Data/Macaw/RISCV.hs +++ b/macaw-riscv/src/Data/Macaw/RISCV.hs @@ -12,6 +12,7 @@ module Data.Macaw.RISCV ( module Data.Macaw.RISCV.RISCVReg, -- * Macaw configurations riscv_info, + riscvPLTStubInfo, -- * Type-level tags G.RV(..), G.RVRepr(..), @@ -25,10 +26,12 @@ module Data.Macaw.RISCV ( import GHC.Stack (HasCallStack) +import qualified Data.ElfEdit as EE import qualified Data.Macaw.CFG as MC import qualified Data.Macaw.CFG.DemandSet as MD import Data.Macaw.Discovery ( defaultClassifier ) import qualified Data.Macaw.Architecture.Info as MI +import qualified Data.Macaw.Memory.ElfLoader.PLTStubs as MMEP import Data.Parameterized ( type(<=) ) import qualified GRIFT.Types as G @@ -79,3 +82,11 @@ riscv_info rvRepr = , MI.postArchTermStmtAbsState = \_ _ _ _ _ -> error $ "postArchTermStmtAbsState unimplemented in riscv_info" , MI.archClassifier = defaultClassifier } + +-- | PLT stub information for ARM32 relocation types. +riscvPLTStubInfo :: MMEP.PLTStubInfo (EE.RISCV_RelocationType w) +riscvPLTStubInfo = MMEP.PLTStubInfo + { MMEP.pltFunSize = 32 + , MMEP.pltStubSize = 16 + , MMEP.pltGotStubSize = error "Unexpected .plt.got section in RISC-V binary" + }