[llvm-dev] partial instrumentation seems broken
adi t via llvm-dev
llvm-dev at lists.llvm.org
Tue Jul 28 14:47:45 PDT 2020
Hi all,
I used the instruction from here:
https://clang.llvm.org/docs/SanitizerCoverage.html#partially-disabling-instrumentation
to compile the following c file
#include <stdint.h>
#include <stdio.h>
#include <sanitizer/coverage_interface.h>
void __sanitizer_cov_trace_pc_guard_init(uint32_t *start,
uint32_t *stop) {
static uint64_t N; // Counter for the guards.
if (start == stop || *start) return; // Initialize only once.
printf("INIT: %p %p\n", start, stop);
for (uint32_t *x = start; x < stop; x++)
*x = ++N; // Guards should start from 1.
}
void __sanitizer_cov_trace_pc_guard(uint32_t *guard) {
if (!*guard) return; // Duplicate the guard check.
void *PC = __builtin_return_address(0);
char PcDescr[1024];
}
int addition(int num1, int num2)
{
int sum;
sum = num1+num2;
if(sum)
return sum;
else
return 0;
}
int substraction(int num1, int num2)
{
int sum;
sum = num1-num2;
if(sum)
return sum;
else
return -1;
}
int main()
{
int var1, var2,res;
printf("Enter number 1: ");
scanf("%d",&var1);
printf("Enter number 2: ");
scanf("%d",&var2);
if(var1 >1){
res = addition(var1, var2);
printf ("Output: %d", res);
}
if(var2 > 2){
res = substraction(var1, var2);
printf ("Output2: %d", res);
}
return 0;
}
test.sh
export CC=clang
export LDFLAGS="-O0 -g -fsanitize-coverage=trace-pc-guard
-fsanitize-coverage-allowlist=./whitelist.txt
-fsanitize-coverage-blocklist=./blacklist.txt"
$CC $LD_LFAGS test.c -o test
blacklist.txt contains:
fun:addition*
and whitelist.txt contains
src:*
fun:*
Basically I want everything to be instrumented except function addition.
I'm using clang 11.
The problem is if I look in the disassembly of the binary
sanitizer_cov_trace_pc_guard in any of the 3 functions:
main/addition/substraction. It should instrument all , except addition.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200728/1037a2e0/attachment.html>
More information about the llvm-dev
mailing list