public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/114757] New: [ASAN] ASAN miscalculates size of region when building the JDK
@ 2024-04-17 20:08 szaldana at redhat dot com
  2024-04-17 20:11 ` [Bug other/114757] " szaldana at redhat dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: szaldana at redhat dot com @ 2024-04-17 20:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114757

            Bug ID: 114757
           Summary: [ASAN] ASAN miscalculates size of region when building
                    the JDK
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: szaldana at redhat dot com
  Target Milestone: ---

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug other/114757] [ASAN] ASAN miscalculates size of region when building the JDK
  2024-04-17 20:08 [Bug other/114757] New: [ASAN] ASAN miscalculates size of region when building the JDK szaldana at redhat dot com
@ 2024-04-17 20:11 ` szaldana at redhat dot com
  2024-04-17 20:14 ` [Bug tree-optimization/114757] stringop-overflow warning with -fsanitize=address while building JDK pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: szaldana at redhat dot com @ 2024-04-17 20:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114757

--- Comment #1 from Sonia Zaldana Calles <szaldana at redhat dot com> ---
Created attachment 57975
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57975&action=edit
debug log file

Contains a .txt file with the debug log.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/114757] stringop-overflow warning with -fsanitize=address while building JDK
  2024-04-17 20:08 [Bug other/114757] New: [ASAN] ASAN miscalculates size of region when building the JDK szaldana at redhat dot com
  2024-04-17 20:11 ` [Bug other/114757] " szaldana at redhat dot com
@ 2024-04-17 20:14 ` pinskia at gcc dot gnu.org
  2024-04-17 20:34 ` szaldana at redhat dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-17 20:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114757

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|other                       |tree-optimization
             Blocks|                            |88443
   Last reconfirmed|                            |2024-04-17
     Ever confirmed|0                           |1
           Keywords|                            |diagnostic
            Summary|[ASAN] ASAN miscalculates   |stringop-overflow warning
                   |size of region when         |with -fsanitize=address
                   |building the JDK            |while building JDK
             Status|UNCONFIRMED                 |WAITING

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
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?


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88443
[Bug 88443] [meta-bug] bogus/missing -Wstringop-overflow warnings

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/114757] stringop-overflow warning with -fsanitize=address while building JDK
  2024-04-17 20:08 [Bug other/114757] New: [ASAN] ASAN miscalculates size of region when building the JDK szaldana at redhat dot com
  2024-04-17 20:11 ` [Bug other/114757] " szaldana at redhat dot com
  2024-04-17 20:14 ` [Bug tree-optimization/114757] stringop-overflow warning with -fsanitize=address while building JDK pinskia at gcc dot gnu.org
@ 2024-04-17 20:34 ` szaldana at redhat dot com
  2024-04-17 20:36 ` szaldana at redhat dot com
  2024-04-17 20:37 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: szaldana at redhat dot com @ 2024-04-17 20:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114757

--- Comment #3 from Sonia Zaldana Calles <szaldana at redhat dot com> ---
Created attachment 57976
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57976&action=edit
ZMarkStack.ii

Preprocessed file for ZMarkStack

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/114757] stringop-overflow warning with -fsanitize=address while building JDK
  2024-04-17 20:08 [Bug other/114757] New: [ASAN] ASAN miscalculates size of region when building the JDK szaldana at redhat dot com
                   ` (2 preceding siblings ...)
  2024-04-17 20:34 ` szaldana at redhat dot com
@ 2024-04-17 20:36 ` szaldana at redhat dot com
  2024-04-17 20:37 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: szaldana at redhat dot com @ 2024-04-17 20:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114757

--- Comment #4 from Sonia Zaldana Calles <szaldana at redhat dot com> ---
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 ) )

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug tree-optimization/114757] stringop-overflow warning with -fsanitize=address while building JDK
  2024-04-17 20:08 [Bug other/114757] New: [ASAN] ASAN miscalculates size of region when building the JDK szaldana at redhat dot com
                   ` (3 preceding siblings ...)
  2024-04-17 20:36 ` szaldana at redhat dot com
@ 2024-04-17 20:37 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-17 20:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114757

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |UNCONFIRMED
     Ever confirmed|1                           |0

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-04-17 20:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-17 20:08 [Bug other/114757] New: [ASAN] ASAN miscalculates size of region when building the JDK szaldana at redhat dot com
2024-04-17 20:11 ` [Bug other/114757] " szaldana at redhat dot com
2024-04-17 20:14 ` [Bug tree-optimization/114757] stringop-overflow warning with -fsanitize=address while building JDK pinskia at gcc dot gnu.org
2024-04-17 20:34 ` szaldana at redhat dot com
2024-04-17 20:36 ` szaldana at redhat dot com
2024-04-17 20:37 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).