Per Function OLLVM Fail Becouse Missing Annotations
pinwhell opened this issue · 3 comments
pinwhell commented
__attribute__((annotate("nofla")))
double heavyComputation (int n) {
...
}
Generates:
@.str = private unnamed_addr constant [6 x i8] c"nofla\00", section "llvm.metadata"
@.str.1 = private unnamed_addr constant [9 x i8] c"main.cpp\00", section "llvm.metadata"
But
std::string llvm::readAnnotate(Function *f)
seems not able to find/retrieve the annotation(/s) "nofla" ..
to reproduce
// main.cpp
#include <iostream>
#include <vector>
#include <cmath>
// Function to perform some heavy processing
__attribute__((annotate("nofla")))
double heavyComputation (int n) {
// Initialize a vector to store intermediate results
std::vector<double> results(n);
// Perform some calculations
for (int i = 0; i < n; ++i) {
results[i] = 0;
for (int j = 1; j <= 1000; ++j) {
results[i] += sin(i * j) + cos(i / (j + 1.0));
}
results[i] = pow(results[i], 2.5) / (i + 1.0);
}
// Calculate the final result
double finalResult = 0;
for (double value : results) {
finalResult += sqrt(value);
}
std::cout << " + Some Bullshit ";
return finalResult;
}
int main() {
// Print "Hello, World!"
std::cout << "Hello, World!" << std::endl;
// Perform the heavy computation
int n = 1000; // Number of elements to process
double result = heavyComputation(n);
// Print the result of the computation
std::cout << "The result of the heavy computation is: " << result << std::endl;
return 0;
}
clang-cl main.cpp -o main.exe
pinwhell commented
I guess the annotation seems to be present but not attached to the function 🤔
DreamSoule commented
Utils.cpp:75
bool llvm::toObfuscate(bool flag, Function *f, std::string const &attribute) {
std::string attr = attribute;
std::string attrNo = "no" + attr; <<<<<
if (readAnnotate(f).find(attrNo) != std::string::npos) {
return false;
}
if (readAnnotate(f).find(attr) != std::string::npos) {
return true;
}
...
}
pinwhell commented
@DreamSoule even when including the no
attribute, was failing, #26 Fixed it