Twister's --enable-asan
may hamper GCC bug detection
#69397
Unanswered
LukaszMrugala
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Reproduction
Let us create a simple testcase:
We can see that the code there is not correct. the
helper
function sets theptr
pointer to its local array, which goes out of scope as soon as we leave the function. Thus, we use a pointer to freed memory.Case 1: No asan
I have run this command:
twister -T <path_to_test> -p native_sim -i
to check what Twister will do without the Address Sanitiser. It turns out that even without it, Twister is runs the test, it errors out with this snippet of logs:Which is great! GCC itself seemed to catch our error. Even without additional options, our end users can get useful information when creating new tests and making a mistake. However, with asan, we should get even better information. After all, this mistake is used as an example of what ASan can detect! (Note that this type of bug requires additional ASan option to actually be caught by ASan, but that's not the main point)
Case 2: Address sanitiser
To this end, I have run such command:
twister -T <path_to_test> -p native_sim -i --enable-asan
. It differs from the previous one only by the--enable-asan
flag.However, this time Twister run through the test and deemed it correct. The test has passed and no mistakes were reported.
What does
--enable-asan
actually do?The relevant parts of Twister code are here:
zephyr/scripts/pylib/twister/twisterlib/handlers.py
Lines 265 to 270 in a48c958
zephyr/scripts/pylib/twister/twisterlib/testinstance.py
Lines 280 to 282 in a48c958
When we take a look at the buildlog, the difference can be seen in the
ccache
call, where the asan version has two additional flags:-fsanitize-recover=all -fsanitize=address
.Why is it a problem?
Users expect to have an increased understanding of problems in their code when using additional diagnostic tools. Sanitisers especially should help the users detect more rather than fewer bugs in their code.
I have encountered this problem accidentally, when creating blackbox testcases. I think someone more well-versed in GCC and ASan might shine more light on this.
Beta Was this translation helpful? Give feedback.
All reactions