Skip to content

Commit ea6011a

Browse files
feat(TDA): add TypeDeductionAnalysis library and bump to c++20
1 parent 401278a commit ea6011a

6 files changed

Lines changed: 38 additions & 8 deletions

File tree

.github/workflows/main.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ jobs:
1616
- name: Checking out ASPIS
1717
uses: actions/checkout@v4
1818
with:
19-
path: ASPIS
19+
submodules: recursive
20+
fetch-depth: 0
2021

22+
- name: Init submodules
23+
run: |
24+
git submodule sync --recursive
25+
git submodule update --init --recursive
26+
2127
- name: Install system dependencies
2228
run: |
2329
sudo apt update
@@ -40,7 +46,7 @@ jobs:
4046
4147
- name: Compiling ASPIS
4248
shell: bash
43-
working-directory: ${{ github.workspace }}/ASPIS
49+
working-directory: ${{ github.workspace }}
4450
run: |
4551
ccache --set-config=max_size=${CCACHE_MAXSIZE}
4652
ccache --zero-stats
@@ -63,18 +69,18 @@ jobs:
6369
id: pip-cache
6470
with:
6571
path: ~/.cache/pip
66-
key: pip-${{ hashFiles('${{ github.workspace }}/ASPIS/testing/requirements.txt') }}
72+
key: pip-${{ hashFiles('${{ github.workspace }}/testing/requirements.txt') }}
6773
restore-keys: |
6874
pip-
6975
- name: Install Python requirements
7076
shell: bash
7177
if: steps.restore-ccache.outputs.cache-hit != 'true'
72-
working-directory: ${{ github.workspace }}/ASPIS/testing
78+
working-directory: ${{ github.workspace }}/testing
7379
run: |
7480
pip install -r requirements.txt
7581
- name: Testing ASPIS
7682
shell: bash
77-
working-directory: ${{ github.workspace }}/ASPIS/testing
83+
working-directory: ${{ github.workspace }}/testing
7884
run: |
7985
pytest test.py --no-header -v
8086

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "libs/TypeDeductionAnalysis"]
2+
path = libs/TypeDeductionAnalysis
3+
url = https://github.com/NiccoloN/TypeDeductionAnalysis.git

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
2121
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
2222
#endif()
2323

24-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
24+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20")
2525

2626
message(STATUS "Found LLVM definitions ${LLVM_DEFINITIONS_LIST}")
2727
message(STATUS "Found LLVM include dirs ${LLVM_INCLUDE_DIRS}")
2828
message(STATUS "RTTI: ${LLVM_ENABLE_RTTI}")
2929

30+
add_subdirectory(libs/TypeDeductionAnalysis)
3031
add_subdirectory(passes)

passes/ASPIS.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "llvm/Pass.h"
77
#include <llvm/IR/Instructions.h>
88
#include "Utils/Utils.h"
9+
#include "TypeDeductionAnalysis.hpp"
910
#include <map>
1011
#include <set>
1112

@@ -40,7 +41,8 @@ class EDDI : public PassInfoMixin<EDDI> {
4041
std::set<Function*> toHardenFunctions;
4142
std::set<Value*> toHardenVariables;
4243
std::set<Value*> DuplicatedCalls;
43-
44+
tda::TypeDeductionAnalysis tda;
45+
tda::TypeDeductionAnalysis::Result deducedTypes;
4446
std::string entryPoint;
4547

4648
LinkageMap linkageMap;

passes/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_library(EDDI SHARED
77
FuncRetToRef.cpp
88
Utils/Utils.cpp
99
)
10+
target_link_libraries(EDDI PUBLIC TypeDeductionAnalysis)
1011
target_compile_definitions(EDDI PRIVATE DUPLICATE_ALL SELECTIVE_CHECKING=0 CHECK_AT_STORES CHECK_AT_CALLS CHECK_AT_BRANCH)
1112

1213
# REDDI
@@ -16,6 +17,7 @@ add_library(REDDI SHARED
1617
FuncRetToRef.cpp
1718
Utils/Utils.cpp
1819
)
20+
target_link_libraries(REDDI PUBLIC TypeDeductionAnalysis)
1921
target_compile_definitions(REDDI PRIVATE SELECTIVE_CHECKING=0 CHECK_AT_STORES CHECK_AT_CALLS CHECK_AT_BRANCH)
2022

2123

@@ -26,6 +28,7 @@ add_library(FDSC SHARED
2628
FuncRetToRef.cpp
2729
Utils/Utils.cpp
2830
)
31+
target_link_libraries(FDSC PUBLIC TypeDeductionAnalysis)
2932
target_compile_definitions(FDSC PRIVATE DUPLICATE_ALL SELECTIVE_CHECKING=1 CHECK_AT_STORES CHECK_AT_CALLS CHECK_AT_BRANCH)
3033

3134
# sEDDI
@@ -35,6 +38,7 @@ add_library(SEDDI SHARED
3538
FuncRetToRef.cpp
3639
Utils/Utils.cpp
3740
)
41+
target_link_libraries(SEDDI PUBLIC TypeDeductionAnalysis)
3842
target_compile_definitions(SEDDI PRIVATE DUPLICATE_ALL SELECTIVE_CHECKING=0 CHECK_AT_CALLS CHECK_AT_BRANCH)
3943

4044

@@ -43,12 +47,14 @@ add_library(CFCSS SHARED
4347
CFCSS.cpp
4448
Utils/Utils.cpp
4549
)
50+
target_link_libraries(CFCSS PUBLIC TypeDeductionAnalysis)
4651

4752
# RASM
4853
add_library(RASM SHARED
4954
RASM.cpp
5055
Utils/Utils.cpp
5156
)
57+
target_link_libraries(RASM PUBLIC TypeDeductionAnalysis)
5258
target_compile_definitions(RASM PRIVATE INTER_FUNCTION_CFC=0)
5359

5460

@@ -57,15 +63,18 @@ add_library(INTER_RASM SHARED
5763
RASM.cpp
5864
Utils/Utils.cpp
5965
)
66+
target_link_libraries(INTER_RASM PUBLIC TypeDeductionAnalysis)
6067
target_compile_definitions(INTER_RASM PRIVATE INTER_FUNCTION_CFC=1)
6168

6269
# RACFED
6370
add_library(RACFED SHARED
6471
RACFED.cpp
6572
Utils/Utils.cpp
6673
)
74+
target_link_libraries(RACFED PUBLIC TypeDeductionAnalysis)
6775

6876
add_library(PROFILER SHARED
6977
Profiling/ASPISCheckProfiler.cpp
7078
Utils/Utils.cpp
7179
)
80+
target_link_libraries(PROFILER PUBLIC TypeDeductionAnalysis)

passes/EDDI.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
#include <map>
3838
#include <queue>
3939
#include <unordered_set>
40-
// #include "../TypeDeductionAnalysis/TypeDeductionAnalysis.hpp"
4140

4241
#include "Utils/Utils.h"
4342

4443
using namespace llvm;
44+
using namespace tda;
4545

4646
#define DEBUG_TYPE "eddi_verification"
4747

@@ -1565,6 +1565,15 @@ PreservedAnalyses EDDI::run(Module &Md, ModuleAnalysisManager &AM) {
15651565
// Fixing the duplicated constructors
15661566
fixDuplicatedConstructors(Md);
15671567

1568+
deducedTypes = tda.run(Md, AM);
1569+
1570+
// Save deduced transparent types
1571+
for (auto& [value, deducedTypes] : deducedTypes.transparentTypes) {
1572+
if (!deducedTypes.empty()) {
1573+
errs() << "Deduced transparent type for " << *value << ": " << (*deducedTypes.begin()).get()->toString() << "\n";
1574+
}
1575+
}
1576+
15681577
// list of duplicated instructions to remove since they are equal to the original
15691578
std::set<CallBase *> GrayAreaCallsToFix;
15701579
int iFn = 1;

0 commit comments

Comments
 (0)