public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/98555] New: Functions optimized to zero length break function pointer inequality
@ 2021-01-06  3:39 bugdal at aerifal dot cx
  2021-01-06  9:09 ` [Bug middle-end/98555] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: bugdal at aerifal dot cx @ 2021-01-06  3:39 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98555
           Summary: Functions optimized to zero length break function
                    pointer inequality
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bugdal at aerifal dot cx
  Target Milestone: ---

Given a function such as

void foo() { __builtin_unreachable(); }

or optimized to such due to unconditional undefined behavior when the function
is reached, GCC emits a zero-length function. This causes the address of foo to
be equal to the address of whatever function happens to follow foo, breaking
the language requirement that distinct functions' addresses compare not-equal.

As far as I can tell, all versions back to 4.x or earlier are affected.

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

* [Bug middle-end/98555] Functions optimized to zero length break function pointer inequality
  2021-01-06  3:39 [Bug middle-end/98555] New: Functions optimized to zero length break function pointer inequality bugdal at aerifal dot cx
@ 2021-01-06  9:09 ` rguenth at gcc dot gnu.org
  2021-01-06 14:38 ` [Bug rtl-optimization/98555] " rlcamp.pdx at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-01-06  9:09 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-01-06
             Status|UNCONFIRMED                 |NEW
            Version|unknown                     |10.2.0
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Due to "undefined behavior" of course means this isn't unexpected (you have to
expect anything there).  For the literally written function, sure.

Did you actually run into this for a relevant case?

[for QOI/security/whatever we probably want to at least emit a ret instruction]

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

* [Bug rtl-optimization/98555] Functions optimized to zero length break function pointer inequality
  2021-01-06  3:39 [Bug middle-end/98555] New: Functions optimized to zero length break function pointer inequality bugdal at aerifal dot cx
  2021-01-06  9:09 ` [Bug middle-end/98555] " rguenth at gcc dot gnu.org
@ 2021-01-06 14:38 ` rlcamp.pdx at gmail dot com
  2021-01-06 18:52 ` bugdal at aerifal dot cx
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rlcamp.pdx at gmail dot com @ 2021-01-06 14:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Campbell <rlcamp.pdx at gmail dot com> ---
> Did you actually run into this for a relevant case?

Yes. The relevant use case is where a sentinel value is needed that has
function pointer type, as function pointers are not interchangeable with other
types of pointers.

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

* [Bug rtl-optimization/98555] Functions optimized to zero length break function pointer inequality
  2021-01-06  3:39 [Bug middle-end/98555] New: Functions optimized to zero length break function pointer inequality bugdal at aerifal dot cx
  2021-01-06  9:09 ` [Bug middle-end/98555] " rguenth at gcc dot gnu.org
  2021-01-06 14:38 ` [Bug rtl-optimization/98555] " rlcamp.pdx at gmail dot com
@ 2021-01-06 18:52 ` bugdal at aerifal dot cx
  2021-01-10  4:40 ` vanyacpp at gmail dot com
  2021-03-16 21:05 ` bugdal at aerifal dot cx
  4 siblings, 0 replies; 6+ messages in thread
From: bugdal at aerifal dot cx @ 2021-01-06 18:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Rich Felker <bugdal at aerifal dot cx> ---
> Due to "undefined behavior" of course means this isn't unexpected

That would only be the case if undefined behavior were reached during
execution, but it's not. This bug affects programs that do not and cannot call
the zero-length function.

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

* [Bug rtl-optimization/98555] Functions optimized to zero length break function pointer inequality
  2021-01-06  3:39 [Bug middle-end/98555] New: Functions optimized to zero length break function pointer inequality bugdal at aerifal dot cx
                   ` (2 preceding siblings ...)
  2021-01-06 18:52 ` bugdal at aerifal dot cx
@ 2021-01-10  4:40 ` vanyacpp at gmail dot com
  2021-03-16 21:05 ` bugdal at aerifal dot cx
  4 siblings, 0 replies; 6+ messages in thread
From: vanyacpp at gmail dot com @ 2021-01-10  4:40 UTC (permalink / raw)
  To: gcc-bugs

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

Ivan Sorokin <vanyacpp at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vanyacpp at gmail dot com

--- Comment #4 from Ivan Sorokin <vanyacpp at gmail dot com> ---
(In reply to Richard Biener from comment #1)
> [for QOI/security/whatever we probably want to at least emit a ret
> instruction]

RET might be dangerous when the return type is non-void. Perhaps UD2 or INT3
would be better?

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

* [Bug rtl-optimization/98555] Functions optimized to zero length break function pointer inequality
  2021-01-06  3:39 [Bug middle-end/98555] New: Functions optimized to zero length break function pointer inequality bugdal at aerifal dot cx
                   ` (3 preceding siblings ...)
  2021-01-10  4:40 ` vanyacpp at gmail dot com
@ 2021-03-16 21:05 ` bugdal at aerifal dot cx
  4 siblings, 0 replies; 6+ messages in thread
From: bugdal at aerifal dot cx @ 2021-03-16 21:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Rich Felker <bugdal at aerifal dot cx> ---
Ping. Could this be solved without the need for target-specific logic by, in
some earlier layer, transforming entirely empty function bodies to
__builtin_trap()? (And thereby relying on the target's implementation thereof,
which defaults to a call to abort() if the target doesn't provide one.)

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

end of thread, other threads:[~2021-03-16 21:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-06  3:39 [Bug middle-end/98555] New: Functions optimized to zero length break function pointer inequality bugdal at aerifal dot cx
2021-01-06  9:09 ` [Bug middle-end/98555] " rguenth at gcc dot gnu.org
2021-01-06 14:38 ` [Bug rtl-optimization/98555] " rlcamp.pdx at gmail dot com
2021-01-06 18:52 ` bugdal at aerifal dot cx
2021-01-10  4:40 ` vanyacpp at gmail dot com
2021-03-16 21:05 ` bugdal at aerifal dot cx

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