public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/99190] New: Undefined behaviour in libubsan
@ 2021-02-22  8:09 zeccav at gmail dot com
  2021-02-22  8:16 ` [Bug sanitizer/99190] " jakub at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: zeccav at gmail dot com @ 2021-02-22  8:09 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99190
           Summary: Undefined behaviour in libubsan
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zeccav at gmail dot com
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org
  Target Milestone: ---

// gcc -fsanitize=shift -w
// ldd a.out produces
// libubsan.so.1 => /home/vitti/local/gcc-150221-undefined/lib64/libubsan.so.1
// ./a.out produces
// ../../../../gcc-150221/libsanitizer/ubsan/ubsan_value.cpp:77:25: runtime
error: left shift of 0x0000000000000000fffffffffffffffb by 96 places cannot be
represented in type '__int128'
// ubsan_value.cpp:77 -> "return SIntMax(Val) << ExtraBits >> ExtraBits;"
int main (void)
{

  1 << -5;

  return 0;
}

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

* [Bug sanitizer/99190] Undefined behaviour in libubsan
  2021-02-22  8:09 [Bug sanitizer/99190] New: Undefined behaviour in libubsan zeccav at gmail dot com
@ 2021-02-22  8:16 ` jakub at gcc dot gnu.org
  2021-02-22  9:47 ` marxin at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-02-22  8:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
It is UB only in C++17 or earlier, so one way to "fix" it is build libubsan
with -std=gnu++20.
Or the SIntMax(Val) << ExtraBits >> ExtraBits can be replaced by
SIntMax(UIntMax(Val) << ExtraBits) >> ExtraBits.

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

* [Bug sanitizer/99190] Undefined behaviour in libubsan
  2021-02-22  8:09 [Bug sanitizer/99190] New: Undefined behaviour in libubsan zeccav at gmail dot com
  2021-02-22  8:16 ` [Bug sanitizer/99190] " jakub at gcc dot gnu.org
@ 2021-02-22  9:47 ` marxin at gcc dot gnu.org
  2021-02-22 15:17 ` marxin at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-02-22  9:47 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2021-02-22
           Assignee|unassigned at gcc dot gnu.org      |marxin at gcc dot gnu.org

--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
I'll handle it.

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

* [Bug sanitizer/99190] Undefined behaviour in libubsan
  2021-02-22  8:09 [Bug sanitizer/99190] New: Undefined behaviour in libubsan zeccav at gmail dot com
  2021-02-22  8:16 ` [Bug sanitizer/99190] " jakub at gcc dot gnu.org
  2021-02-22  9:47 ` marxin at gcc dot gnu.org
@ 2021-02-22 15:17 ` marxin at gcc dot gnu.org
  2021-02-22 15:52 ` zeccav at gmail dot com
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-02-22 15:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
Interesting, you are searching for UBSAN in libsanitizer.
Can you please share details how do you build libubsan with -fsanitize=shift?

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

* [Bug sanitizer/99190] Undefined behaviour in libubsan
  2021-02-22  8:09 [Bug sanitizer/99190] New: Undefined behaviour in libubsan zeccav at gmail dot com
                   ` (2 preceding siblings ...)
  2021-02-22 15:17 ` marxin at gcc dot gnu.org
@ 2021-02-22 15:52 ` zeccav at gmail dot com
  2021-02-22 16:15 ` zeccav at gmail dot com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: zeccav at gmail dot com @ 2021-02-22 15:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Vittorio Zecca <zeccav at gmail dot com> ---
To generate a sanitized version of libgfortran I built whole sanitized
gcc with the following command:

CFLAGS="-g -O0 -fsanitize=undefined -lubsan" LIBS="-lubsan"
CXXFLAGS=$CFLAGS ../gcc-150221/configure
--prefix=/home/vitti/local/gcc-150221-undefined
--enable-languages=c,c++,fortran --disable-multilib --disable-lto
--disable-plugin
--disable-bootstrap

But I remember I had to tweak the build here and there.
It is not trivial.

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

* [Bug sanitizer/99190] Undefined behaviour in libubsan
  2021-02-22  8:09 [Bug sanitizer/99190] New: Undefined behaviour in libubsan zeccav at gmail dot com
                   ` (3 preceding siblings ...)
  2021-02-22 15:52 ` zeccav at gmail dot com
@ 2021-02-22 16:15 ` zeccav at gmail dot com
  2021-02-23  9:14 ` marxin at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: zeccav at gmail dot com @ 2021-02-22 16:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Vittorio Zecca <zeccav at gmail dot com> ---
Sorry I meant libubsan, but I am building the whole gcc, g++, and gfortran
sanitized version.

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

* [Bug sanitizer/99190] Undefined behaviour in libubsan
  2021-02-22  8:09 [Bug sanitizer/99190] New: Undefined behaviour in libubsan zeccav at gmail dot com
                   ` (4 preceding siblings ...)
  2021-02-22 16:15 ` zeccav at gmail dot com
@ 2021-02-23  9:14 ` marxin at gcc dot gnu.org
  2021-02-23 10:16 ` marxin at gcc dot gnu.org
  2021-02-23 16:30 ` zeccav at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-02-23  9:14 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |https://reviews.llvm.org/D9
                   |                            |7263

--- Comment #6 from Martin Liška <marxin at gcc dot gnu.org> ---
I can reproduce it and I've just made an upstream pull request:
https://reviews.llvm.org/D97263

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

* [Bug sanitizer/99190] Undefined behaviour in libubsan
  2021-02-22  8:09 [Bug sanitizer/99190] New: Undefined behaviour in libubsan zeccav at gmail dot com
                   ` (5 preceding siblings ...)
  2021-02-23  9:14 ` marxin at gcc dot gnu.org
@ 2021-02-23 10:16 ` marxin at gcc dot gnu.org
  2021-02-23 16:30 ` zeccav at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-02-23 10:16 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Martin Liška <marxin at gcc dot gnu.org> ---
Fixed in master with g:e03e58c1844d04678f95b278f3eff2a5fbaeff75.

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

* [Bug sanitizer/99190] Undefined behaviour in libubsan
  2021-02-22  8:09 [Bug sanitizer/99190] New: Undefined behaviour in libubsan zeccav at gmail dot com
                   ` (6 preceding siblings ...)
  2021-02-23 10:16 ` marxin at gcc dot gnu.org
@ 2021-02-23 16:30 ` zeccav at gmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: zeccav at gmail dot com @ 2021-02-23 16:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Vittorio Zecca <zeccav at gmail dot com> ---
I can confirm the new libubsan works on my test case.

Keep up the good work!

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

end of thread, other threads:[~2021-02-23 16:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-22  8:09 [Bug sanitizer/99190] New: Undefined behaviour in libubsan zeccav at gmail dot com
2021-02-22  8:16 ` [Bug sanitizer/99190] " jakub at gcc dot gnu.org
2021-02-22  9:47 ` marxin at gcc dot gnu.org
2021-02-22 15:17 ` marxin at gcc dot gnu.org
2021-02-22 15:52 ` zeccav at gmail dot com
2021-02-22 16:15 ` zeccav at gmail dot com
2021-02-23  9:14 ` marxin at gcc dot gnu.org
2021-02-23 10:16 ` marxin at gcc dot gnu.org
2021-02-23 16:30 ` zeccav at gmail dot com

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).