https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97803
Bug ID: 97803 Summary: c-c++-common/asan/pointer-compare-1.c assumes variable placement Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: testsuite Assignee: unassigned at gcc dot gnu.org Reporter: hjl.tools at gmail dot com Target Milestone: --- c-c++-common/asan/pointer-compare-1.c has char global1[100] = {}, global2[100] = {}; char __attribute__((used)) smallest_global[5] = {}; char small_global[7] = {}; char __attribute__((used)) little_global[10] = {}; char __attribute__((used)) medium_global[4000] = {}; char large_global[5000] = {}; char __attribute__((used)) largest_global[6000] = {}; They are used to has layout: 0000000000404380 B largest_global 0000000000405b20 B large_global 0000000000406ee0 B medium_global 0000000000407ea0 B little_global 0000000000407ee0 B small_global 0000000000407f20 B smallest_global 0000000000407f60 B global2 0000000000408000 B global1 00000000004080e0 B __odr_asan.largest_global 00000000004080e1 B __odr_asan.large_global 00000000004080e2 B __odr_asan.medium_global 00000000004080e3 B __odr_asan.little_global 00000000004080e4 B __odr_asan.small_global 00000000004080e5 B __odr_asan.smallest_global 00000000004080e6 B __odr_asan.global2 00000000004080e7 B __odr_asan.global1 With SHF_GNU_RETAIN change: https://gitlab.com/x86-gcc/gcc/-/tree/users/hjl/elf/shf_retain the new layout become: 0000000000404380 B large_global 0000000000405740 B small_global 0000000000405780 B global2 0000000000405820 B global1 0000000000405900 B __odr_asan.largest_global 0000000000405901 B __odr_asan.large_global 0000000000405902 B __odr_asan.medium_global 0000000000405903 B __odr_asan.little_global 0000000000405904 B __odr_asan.small_global 0000000000405905 B __odr_asan.smallest_global 0000000000405906 B __odr_asan.global2 0000000000405907 B __odr_asan.global1 0000000000405920 B largest_global 00000000004070c0 B medium_global 0000000000408080 B little_global 00000000004080c0 B smallest_global and test fails.