Bug 114757 - stringop-overflow warning with -fsanitize=address while building JDK
Summary: stringop-overflow warning with -fsanitize=address while building JDK
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 13.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Wstringop-overflow
  Show dependency treegraph
 
Reported: 2024-04-17 20:08 UTC by Sonia Zaldana Calles
Modified: 2024-04-17 20:37 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-04-17 00:00:00


Attachments
debug log file (212.89 KB, text/plain)
2024-04-17 20:11 UTC, Sonia Zaldana Calles
Details
ZMarkStack.ii (258.07 KB, application/zip)
2024-04-17 20:34 UTC, Sonia Zaldana Calles
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sonia Zaldana Calles 2024-04-17 20:08:21 UTC
Hi all, 

I've come across an ASAN bug while building mainline JDK.

System: Linux x86
Gcc version: 13.2.1

Please find the stack trace below:

```
/home/szaldana/jdk/src/hotspot/share/gc/z/zMarkStack.cpp: In constructor ‘ZMarkStripeSet::ZMarkStripeSet(uintptr_t)’:
/home/szaldana/jdk/src/hotspot/share/gc/z/zMarkStack.cpp:43:17: error: writing 80 bytes into a region of size 8 [-Werror=stringop-overflow=]
   43 | _stripes[i] = ZMarkStripe(base);
      | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
In file included from /home/szaldana/jdk/src/hotspot/share/gc/z/zMarkStack.inline.hpp:27,
                 from /home/szaldana/jdk/src/hotspot/share/gc/z/zMarkStack.cpp:25:
/home/szaldana/jdk/src/hotspot/share/gc/z/zMarkStack.hpp:57:15: note: destination object ‘ZStackList<ZStack<ZMarkStackEntry, 254> >::_base’ of size 8
   57 | uintptr_t _base;
      | ^~~~~
/home/szaldana/jdk/src/hotspot/share/gc/z/zMarkStack.cpp:43:17: error: writing 80 bytes into a region of size 8 [-Werror=stringop-overflow=]
   43 | _stripes[i] = ZMarkStripe(base);
      | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
/home/szaldana/jdk/src/hotspot/share/gc/z/zMarkStack.hpp:57:15: note: destination object ‘ZStackList<ZStack<ZMarkStackEntry, 254> >::_base’ of size 8
   57 | uintptr_t _base;
      | ^~~~~
```

The "region of size 8" seems like a bug in ASAN. It is presumably what ASAN thinks is the size of ```_stripes[i]``` in [zMarkStack.cpp](https://github.com/openjdk/jdk/blob/master/src/hotspot/share/gc/z/zMarkStack.cpp#L43), but that's wrong.

[ZMarkStripe](https://github.com/openjdk/jdk/blob/master/src/hotspot/share/gc/z/zMarkStack.hpp#L82) is made up of two [ZStackList](https://github.com/openjdk/jdk/blob/master/src/hotspot/share/gc/z/zMarkStack.hpp#L55) entries. Note how each one of those is 16 bytes. 

Additionally,  note how ```ZStackList``` is 64 byte aligned to make each one have its own cache line. So the memory layout is something like this: 

```
0 ---
  ZStackList 
16 ----
  padding
64 ----
  ZStackList
80 ---
  padding 
128 ---
```

Thus, ```sizeof(ZMarkStripe)``` should be 128. 

On the other hand, the "writing 80 bytes" seems correct, as that is the size of ```ZMarkStripe``` excluding trailing padding. The assignment doesn't need to copy that trailing padding. 

If you'd like to reproduce the bug, it suffices to [build the jdk](https://openjdk.org/groups/build/doc/building.html) passing the ```--enable-asan``` flag to the ```bash configure``` arguments. 

Find the bug reported in the JDK [here](https://bugs.openjdk.org/browse/JDK-8330047). 

I'm also attaching the log file with the commands that trigger the stack trace above. 


Looking forward to your comments! 

Sonia
Comment 1 Sonia Zaldana Calles 2024-04-17 20:11:24 UTC
Created attachment 57975 [details]
debug log file

Contains a .txt file with the debug log.
Comment 2 Andrew Pinski 2024-04-17 20:14:25 UTC
Note the documentation has the following warning about warnings and sanitizers:
```
Note that sanitizers tend to increase the rate of false positive warnings, most notably those around -Wmaybe-uninitialized. We recommend against combining -Werror and [the use of] sanitizers.
```


https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc/Instrumentation-Options.html#index-fsanitize_003daddress

Can you attach the preprocessed source as requested by https://gcc.gnu.org/bugs/ ? And the exact options which are being used to invoke gcc?
Comment 3 Sonia Zaldana Calles 2024-04-17 20:34:35 UTC
Created attachment 57976 [details]
ZMarkStack.ii

Preprocessed file for ZMarkStack
Comment 4 Sonia Zaldana Calles 2024-04-17 20:36:47 UTC
Command to compile zMarkStack.cpp 

( /usr/bin/rm -f /home/szaldana/jdk/build/linux-x86_64-server-release/hotspot/variant-server/libjvm/objs/zMarkStack.o.log && /usr/bin/g++ -MMD -MF /home/szaldana/jdk/build/linux-x86_64-server-release/hotspot/variant-server/libjvm/objs/zMarkStack.d.tmp -I/home/szaldana/jdk/build/linux-x86_64-server-release/hotspot/variant-server/libjvm/objs/precompiled -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D_GNU_SOURCE -D_REENTRANT -pipe -fno-rtti -fno-exceptions -fvisibility=hidden -fno-strict-aliasing -fno-omit-frame-pointer -fstack-protector -std=c++14 -DLIBC=gnu -DLINUX -D_FILE_OFFSET_BITS=64 -Wall -Wextra -Wformat=2 -Wpointer-arith -Wsign-compare -Wunused-function -Wundef -Wunused-value -Wreturn-type -Wtrampolines -Woverloaded-virtual -Wreorder -fPIC -fmacro-prefix-map=/home/szaldana/jdk/= -DVM_LITTLE_ENDIAN -D_LP64=1 -fno-lifetime-dse -Wno-format-zero-length -Wtype-limits -Wuninitialized -m64 -fsanitize=address -Wno-stringop-truncation -fno-omit-frame-pointer -fno-common -DADDRESS_SANITIZER -DNDEBUG -DPRODUCT -DTARGET_ARCH_x86 -DINCLUDE_SUFFIX_OS=_linux -DINCLUDE_SUFFIX_CPU=_x86 -DINCLUDE_SUFFIX_COMPILER=_gcc -DTARGET_COMPILER_gcc -DAMD64 -DHOTSPOT_LIB_ARCH='"amd64"' -DCOMPILER1 -DCOMPILER2 -I/home/szaldana/jdk/build/linux-x86_64-server-release/hotspot/variant-server/gensrc/adfiles -I/home/szaldana/jdk/src/hotspot/share -I/home/szaldana/jdk/src/hotspot/os/linux -I/home/szaldana/jdk/src/hotspot/os/posix -I/home/szaldana/jdk/src/hotspot/cpu/x86 -I/home/szaldana/jdk/src/hotspot/os_cpu/linux_x86 -I/home/szaldana/jdk/build/linux-x86_64-server-release/hotspot/variant-server/gensrc -I/home/szaldana/jdk/src/hotspot/share/precompiled -I/home/szaldana/jdk/src/hotspot/share/include -I/home/szaldana/jdk/src/hotspot/os/posix/include -I/home/szaldana/jdk/build/linux-x86_64-server-release/support/modules_include/java.base -I/home/szaldana/jdk/build/linux-x86_64-server-release/support/modules_include/java.base/linux -I/home/szaldana/jdk/src/java.base/share/native/libjimage -m64 -I/home/szaldana/jdk/build/linux-x86_64-server-release/hotspot/variant-server/gensrc/adfiles -I/home/szaldana/jdk/src/hotspot/share -I/home/szaldana/jdk/src/hotspot/os/linux -I/home/szaldana/jdk/src/hotspot/os/posix -I/home/szaldana/jdk/src/hotspot/cpu/x86 -I/home/szaldana/jdk/src/hotspot/os_cpu/linux_x86 -I/home/szaldana/jdk/build/linux-x86_64-server-release/hotspot/variant-server/gensrc -I/home/szaldana/jdk/build/linux-x86_64-server-release/support/modules_include/java.base -I/home/szaldana/jdk/src/java.base/unix/native/include -I/home/szaldana/jdk/src/java.base/share/native/include -g -gdwarf-4 -fdebug-prefix-map=/home/szaldana/jdk/= -fdebug-prefix-map=/usr/include/=/usr/include/ -fdebug-prefix-map=/usr/lib/gcc/x86_64-redhat-linux/13/include/=/usr/local/gcc_include/ -fdebug-prefix-map=/usr/include/c++/13/=/usr/local/gxx_include/ -fdebug-prefix-map=/home/szaldana/jdk/build/linux-x86_64-server-release/= -Wno-unused-parameter -Wno-unused -Wno-array-bounds -Wno-comment -Wno-delete-non-virtual-dtor -Wno-empty-body -Wno-implicit-fallthrough -Wno-int-in-bool-context -Wno-maybe-uninitialized -Wno-missing-field-initializers -Wno-shift-negative-value -Wno-unknown-pragmas -Werror -O3 -c -o /home/szaldana/jdk/build/linux-x86_64-server-release/hotspot/variant-server/libjvm/objs/zMarkStack.o /home/szaldana/jdk/src/hotspot/share/gc/z/zMarkStack.cpp -frandom-seed="zMarkStack.cpp" > >(/usr/bin/tee -a /home/szaldana/jdk/build/linux-x86_64-server-release/hotspot/variant-server/libjvm/objs/zMarkStack.o.log) 2> >(/usr/bin/tee -a /home/szaldana/jdk/build/linux-x86_64-server-release/hotspot/variant-server/libjvm/objs/zMarkStack.o.log >&2) || ( exitcode=$? && /usr/bin/cp /home/szaldana/jdk/build/linux-x86_64-server-release/hotspot/variant-server/libjvm/objs/zMarkStack.o.log /home/szaldana/jdk/build/linux-x86_64-server-release/make-support/failure-logs/hotspot_variant-server_libjvm_objs_zMarkStack.o.log && /usr/bin/cp /home/szaldana/jdk/build/linux-x86_64-server-release/hotspot/variant-server/libjvm/objs/zMarkStack.o.cmdline /home/szaldana/jdk/build/linux-x86_64-server-release/make-support/failure-logs/hotspot_variant-server_libjvm_objs_zMarkStack.o.cmdline && exit $exitcode ) )