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

            Bug ID: 117181
           Summary: i386 call instruction to invalid address
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lilyclark823 at gmail dot com
  Target Milestone: ---

Created attachment 59365
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59365&action=edit
.i for code above

Version: gcc (GCC) 14.2.1 20240910

System: x86_64-pc-linux-gnu

Configured with: /build/gcc/src/gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues
--with-build-config=bootstrap-lto --with-linker-hash-style=gnu
--with-system-zlib --enable-__cxa_atexit --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-werror

Command: cc -c -m32 -O0 -ffreestanding -save-temps -o kernel.o
kernel/bugkernel.c

Output: Sucessful build

Bug: When compiling -O0 it inserts a call instruction that calls half way into
itself see below

Output from 'objdump -D kernel.o'
00000000 <entry>:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   83 ec 10                sub    $0x10,%esp
   6:   e8 fc ff ff ff          call   7 <entry+0x7>

This calls half way into itself causing it to be offset from real instructions

Compiling with 'fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations'
added made no difference in the call

Compiling with '-fsanitize=undefined' added, it generates a similar call but at
a further offset
   8:   e8 fc ff ff ff          call   9 <entry+0x9>

Higher optimization levels do not compile this call at all and work as intended

Reply via email to