Skip to content

Commit edfae6d

Browse files
committed
fix: lab8 no angr
1 parent 916ed0b commit edfae6d

File tree

2 files changed

+24
-58
lines changed

2 files changed

+24
-58
lines changed

.github/workflows/lab-autograding.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,7 @@ jobs:
5656
if [ ${{ steps.lab.outputs.result }} -eq 6 ]; then
5757
sudo apt install -y llvm-14
5858
fi
59+
if [ ${{ steps.lab.outputs.result }} -eq 8 ]; then
60+
python3 -m pip install angr
61+
fi
5962
./validate.sh

lab6/llvm-pass.so.cc

Lines changed: 21 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,34 @@
11
#include "llvm/Passes/PassPlugin.h"
22
#include "llvm/Passes/PassBuilder.h"
33
#include "llvm/IR/IRBuilder.h"
4-
#include "llvm/Support/raw_ostream.h"
54

65
using namespace llvm;
76

8-
struct LLVMPass : public PassInfoMixin<LLVMPass>
9-
{
10-
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
7+
struct LLVMPass : public PassInfoMixin<LLVMPass> {
8+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
119
};
1210

13-
PreservedAnalyses LLVMPass::run(Module &M, ModuleAnalysisManager &MAM)
14-
{
15-
LLVMContext &Ctx = M.getContext();
16-
IntegerType *Int32Ty = IntegerType::getInt32Ty(Ctx);
17-
PointerType *Int8PtrTy = Type::getInt8PtrTy(Ctx);
11+
PreservedAnalyses LLVMPass::run(Module &M, ModuleAnalysisManager &MAM) {
12+
LLVMContext &Ctx = M.getContext();
13+
IntegerType *Int32Ty = IntegerType::getInt32Ty(Ctx);
14+
FunctionCallee debug_func = M.getOrInsertFunction("debug", Int32Ty);
15+
ConstantInt *debug_arg = ConstantInt::get(Int32Ty, 48763);
1816

19-
20-
FunctionCallee debug_func = M.getOrInsertFunction("debug", Int32Ty);
21-
ConstantInt *debug_arg = ConstantInt::get(Int32Ty, 48763);
17+
for (auto &F : M) {
18+
errs() << "func: " << F.getName() << "\n";
2219

23-
// find main
24-
for (Function &F : M)
25-
{
26-
if (F.getName() != "main")
27-
continue;
28-
29-
// Entry block
30-
BasicBlock &EntryBB = F.getEntryBlock();
31-
IRBuilder<> Builder(&*EntryBB.getFirstInsertionPt());
32-
33-
// debug(48763)
34-
Builder.CreateCall(debug_func, {debug_arg});
35-
36-
// argc argv
37-
if (F.arg_size() >= 2)
38-
{
39-
auto ArgIt = F.arg_begin();
40-
Argument *Argc = ArgIt++;
41-
Argument *Argv = ArgIt;
42-
43-
// argc replace into 48763
44-
Argc->replaceAllUsesWith(debug_arg);
45-
46-
// argv[1] = "hayaku... motohayaku!"
47-
Constant *Str = Builder.CreateGlobalStringPtr("hayaku... motohayaku!", "hayaku_str");
48-
Value *One = ConstantInt::get(Int32Ty, 1);
49-
// argv get argv[1]
50-
Value *GEP = Builder.CreateGEP(Int8PtrTy, Argv, One, "argv1_ptr");
51-
Builder.CreateStore(Str, GEP);
52-
}
53-
54-
break;
55-
}
56-
57-
return PreservedAnalyses::none();
20+
}
21+
return PreservedAnalyses::none();
5822
}
5923

60-
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK llvmGetPassPluginInfo()
61-
{
62-
return {LLVM_PLUGIN_API_VERSION, "LLVMPass", "1.0",
63-
[](PassBuilder &PB)
64-
{
65-
PB.registerOptimizerLastEPCallback(
66-
[](ModulePassManager &MPM, OptimizationLevel OL)
67-
{
68-
MPM.addPass(LLVMPass());
69-
});
70-
}};
24+
extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
25+
llvmGetPassPluginInfo() {
26+
return {LLVM_PLUGIN_API_VERSION, "LLVMPass", "1.0",
27+
[](PassBuilder &PB) {
28+
PB.registerOptimizerLastEPCallback(
29+
[](ModulePassManager &MPM, OptimizationLevel OL) {
30+
MPM.addPass(LLVMPass());
31+
});
32+
}};
7133
}
34+

0 commit comments

Comments
 (0)