What I have done.
Test1
1 #include <stdio.h>
2
3 int test[16];
4
5 int main()
6 {
7 test[17] = -1;
8 }
/tmp $ gcc ./main.c -o main -fsanitize=address
/tmp $ ./main
/tmp $
Test2
1 #include <stdio.h>
2
3 int test[16] = {1};
4
5 int main()
6 {
7 test[17] = -1;
8 }
/tmp $ gcc ./main.c -o main -fsanitize=address
/tmp $ ./main
=================================================================
==19776==ERROR: AddressSanitizer: global-buffer-overflow on address
...
Looks like global buffer overflow detection is not working for global variables which are placed in bss (is it so?). What are the reasons behind this?
Update:
The code which does store is not optimized out. System information:
$ gcc --version
gcc (Ubuntu 7.2.0-8ubuntu3.2) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.