Skip to content

Commit 42617f1

Browse files
authored
Merge pull request #524 from secure-software-engineering/feature/statisticsUpdate
Feature/statistics update
2 parents a763a69 + 7a21637 commit 42617f1

9 files changed

Lines changed: 94 additions & 23 deletions

File tree

.docker/Dockerfile.devenv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ USER vscode
1616

1717
ENV CC "/usr/bin/clang-14"
1818
ENV CXX "/usr/bin/clang++-14"
19+
ENV PATH "/usr/local/llvm-14/bin:/home/vscode/.local/bin:$PATH"
1920
ENV CMAKE_GENERATOR "Ninja"

.github/workflows/docker.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Docker Image
2+
3+
on:
4+
push:
5+
branches: [ development ]
6+
7+
jobs:
8+
push_to_registries:
9+
name: Push Docker image to multiple registries
10+
runs-on: ubuntu-latest
11+
permissions:
12+
packages: write
13+
contents: read
14+
steps:
15+
- name: Check out the repo
16+
uses: actions/checkout@v3
17+
- name: Set up QEMU
18+
uses: docker/setup-qemu-action@v2
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v2
21+
# If we want to publish an image of PhASAR to the official docker hub we
22+
# can just use the following code and set the corresponding secrets.
23+
# - name: Log in to Docker Hub
24+
# uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
25+
# with:
26+
# username: ${{ secrets.DOCKER_USERNAME }}
27+
# password: ${{ secrets.DOCKER_TOKEN }}
28+
29+
- name: Log in to the Container registry
30+
uses: docker/login-action@v2
31+
with:
32+
registry: ghcr.io
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Extract metadata (tags, labels) for Docker
37+
id: meta
38+
uses: docker/metadata-action@v4
39+
with:
40+
images: ghcr.io/${{ github.repository }}
41+
# here we could add a second image for the official docker registry
42+
# sse/phasar
43+
- name: Build and push Docker images
44+
uses: docker/build-push-action@v3
45+
with:
46+
context: .
47+
platforms: linux/amd64,linux/arm64
48+
push: true
49+
tags: ${{ steps.meta.outputs.tags }}
50+
labels: ${{ steps.meta.outputs.labels }}

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
3131
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP -fvisibility-inlines-hidden -fstack-protector-strong -ffunction-sections -fdata-sections -pipe -g")
3232
else()
3333
message(STATUS "Selected Release Build")
34-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP -fvisibility-inlines-hidden -fstack-protector-strong -ffunction-sections -fdata-sections -pipe -march=native")
34+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MP -fvisibility-inlines-hidden -fstack-protector-strong -ffunction-sections -fdata-sections -pipe")
3535
endif()
3636

3737
# Enable testing

Dockerfile

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,61 @@
1-
FROM ubuntu:20.04
2-
ARG LLVM_INSTALL_DIR="/usr/local/llvm-12"
1+
FROM ubuntu:22.04
2+
ARG LLVM_INSTALL_DIR="/usr/local/llvm-14"
33
LABEL Name=phasar Version=1.0.0
44

55
RUN apt -y update && apt install bash sudo -y
66

7+
78
WORKDIR /usr/src/phasar
89
RUN mkdir -p /usr/src/phasar/utils
910

1011
COPY ./utils/InitializeEnvironment.sh /usr/src/phasar/utils/
1112
RUN ./utils/InitializeEnvironment.sh
1213

14+
RUN apt-get -y install --no-install-recommends \
15+
cmake \
16+
ninja-build \
17+
libstdc++6 \
18+
libboost-all-dev
19+
1320
COPY ./utils/InstallAptDependencies.sh /usr/src/phasar/utils/
1421
RUN ./utils/InstallAptDependencies.sh
1522

23+
RUN apt-get update && \
24+
apt-get install -y software-properties-common
25+
26+
RUN apt-key adv --fetch-keys https://apt.llvm.org/llvm-snapshot.gpg.key && \
27+
add-apt-repository -y 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main' && \
28+
apt-get update && \
29+
apt-get -y install --no-install-recommends \
30+
clang-14 \
31+
llvm-14-dev \
32+
libllvm14 \
33+
libclang-common-14-dev \
34+
libclang-14-dev \
35+
libclang-cpp14-dev \
36+
clang-tidy-14
37+
1638
RUN pip3 install Pygments pyyaml
1739

1840
# installing boost
1941
RUN apt install libboost-all-dev -y
2042

21-
# installing LLVM
22-
COPY utils/safeCommandsSet.sh /usr/src/phasar/utils/safeCommandsSet.sh
23-
COPY utils/install-llvm.sh /usr/src/phasar/utils/install-llvm.sh
24-
RUN ./utils/install-llvm.sh $(nproc) . ${LLVM_INSTALL_DIR} "llvmorg-12.0.0"
2543

2644
# installing wllvm
2745
RUN pip3 install wllvm
2846

29-
ENV CC=${LLVM_INSTALL_DIR}/bin/clang
30-
ENV CXX=${LLVM_INSTALL_DIR}/bin/clang++
31-
ENV LD_LIBRARY_PATH=${LLVM_INSTALL_DIR}/lib:$LD_LIBRARY_PATH
47+
ENV CC=/usr/bin/clang-14
48+
ENV CXX=/usr/bin/clang++-14
3249

3350
COPY . /usr/src/phasar
3451

3552
RUN git submodule init
3653
RUN git submodule update
37-
RUN mkdir -p build && \
38-
cd build && \
39-
cmake -DCMAKE_BUILD_TYPE=Release .. && \
40-
make -j $(nproc) && \
41-
make install && \
42-
ldconfig
54+
RUN mkdir -p build && cd build && \
55+
cmake .. \
56+
-DCMAKE_BUILD_TYPE=Release \
57+
-DCMAKE_CXX_COMPILER=$CXX \
58+
-G Ninja && \
59+
cmake --build .
4360

4461
ENTRYPOINT [ "./build/tools/phasar-llvm/phasar-llvm" ]

include/phasar/Controller/AnalysisController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ enum class AnalysisControllerEmitterOptions : uint32_t {
4949
EmitPTAAsText = (1 << 11),
5050
EmitPTAAsDot = (1 << 12),
5151
EmitPTAAsJson = (1 << 13),
52-
EmitStatisticAsJson = (1 << 14),
52+
EmitStatisticsAsJson = (1 << 14),
5353
};
5454

5555
class AnalysisController {

include/phasar/PhasarLLVM/Passes/GeneralStatisticsAnalysis.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class GeneralStatistics {
4848
std::set<const llvm::Type *> AllocatedTypes;
4949
std::set<const llvm::Instruction *> AllocaInstructions;
5050
std::set<const llvm::Instruction *> RetResInstructions;
51+
std::string ModuleName = "";
5152

5253
public:
5354
/**

lib/Controller/AnalysisController.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ void AnalysisController::emitRequestedHelperAnalysisResults() {
273273
}
274274
}
275275

276-
if (EmitterOptions & AnalysisControllerEmitterOptions::EmitStatisticAsJson) {
276+
if (EmitterOptions & AnalysisControllerEmitterOptions::EmitStatisticsAsJson) {
277277
if (!ResultDirectory.empty()) {
278-
if (auto OFS = openFileStream("/psr-IrStatistic.json")) {
278+
if (auto OFS = openFileStream("/psr-IrStatistics.json")) {
279279
IRDB.printAsJson(*OFS);
280280
}
281281
} else {

lib/PhasarLLVM/Passes/GeneralStatisticsAnalysis.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ GeneralStatisticsAnalysis::run(llvm::Module &M,
4242
static const std::set<std::string> MemAllocatingFunctions = {
4343
"operator new(unsigned long)", "operator new[](unsigned long)", "malloc",
4444
"calloc", "realloc"};
45+
Stats.ModuleName = M.getName();
4546
for (auto &F : M) {
4647
++Stats.Functions;
4748
for (auto &BB : F) {
@@ -217,11 +218,12 @@ GeneralStatistics::getRetResInstructions() const {
217218

218219
nlohmann::json GeneralStatistics::getAsJson() const {
219220
nlohmann::json J;
221+
J["ModuleName"] = GeneralStatistics::ModuleName;
220222
J["Instructions"] = getInstructions();
221223
J["Functions"] = Functions;
222-
J["Alloca Instructions"] = AllocaInstructions.size();
223-
J["Call Sites"] = CallSites;
224-
J["Global Variables"] = Globals;
224+
J["AllocaInstructions"] = AllocaInstructions.size();
225+
J["CallSites"] = CallSites;
226+
J["GlobalVariables"] = Globals;
225227
return J;
226228
}
227229

tools/phasar-llvm/phasar-llvm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ int main(int Argc, const char **Argv) {
408408
EmitterOptions |= AnalysisControllerEmitterOptions::EmitPTAAsJson;
409409
}
410410
if (PhasarConfig::VariablesMap().count("emit-statistic-as-json")) {
411-
EmitterOptions |= AnalysisControllerEmitterOptions::EmitStatisticAsJson;
411+
EmitterOptions |= AnalysisControllerEmitterOptions::EmitStatisticsAsJson;
412412
}
413413
if (PhasarConfig::VariablesMap().count("follow-return-past-seeds")) {
414414
SolverConfig.setFollowReturnsPastSeeds(

0 commit comments

Comments
 (0)