http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60580

            Bug ID: 60580
           Summary: aarch64 generates wrong code for __attribute__
                    ((optimize("no-omit-frame-pointer")))
           Product: gcc
           Version: 4.8.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chemobejk at gmail dot com

Created attachment 32388
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32388&action=edit
Example C code used i the command lines

We have a piece of code that we compile with -fomit-frame-pointer. The
exception is one low-level function that *MUST NOT* rely on the SP register,
i.e. that one function must be compiled with -fno-omit-frame-pointer. This
works fine with the GCC ARM backend, i.e. we have in the C code the following
function attribute:

 /*
  * This function calls XXX(), which modifies SP. This is incompatible to
  * -fomit-frame-pointer generated code as SP is used to access the frame.
  */
 __attribute__ ((optimize("no-omit-frame-pointer")))
 void some_low_level_function(....)


We are now trying to compile that piece of code with the aarch64 backend and
get incorrect code that uses SP to access the frame. I tried with the following
pre-compiled aarch64 toolchains:


Linaro release 2014.02:
COLLECT_GCC=gcc-linaro-aarch64-linux-gnu-4.8-2014.02_linux/bin/aarch64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/workarea/stefanb/playground/aarch64/gcc-linaro-aarch64-linux-gnu-4.8-2014.02_linux/bin/../libexec/gcc/aarch64-linux-gnu/4.8.3/lto-wrapper
Target: aarch64-linux-gnu
Configured with:
/cbuild/slaves/oorts/crosstool-ng/builds/aarch64-linux-gnu-linux/.build/src/gcc-linaro-4.8-2014.02/configure
--build=i686-build_pc-linux-gnu --host=i686-build_pc-linux-gnu
--target=aarch64-linux-gnu
--prefix=/cbuild/slaves/oorts/crosstool-ng/builds/aarch64-linux-gnu-linux/install
--with-sysroot=/cbuild/slaves/oorts/crosstool-ng/builds/aarch64-linux-gnu-linux/install/aarch64-linux-gnu/libc
--enable-languages=c,c++,fortran --disable-multilib --enable-multiarch
--with-arch=armv8-a --with-pkgversion='crosstool-NG linaro-1.13.1-4.8-2014.02 -
Linaro GCC 2014.02' --with-bugurl=https://bugs.launchpad.net/gcc-linaro
--enable-__cxa_atexit --disable-libmudflap --enable-libgomp --disable-libssp
--with-gmp=/cbuild/slaves/oorts/crosstool-ng/builds/aarch64-linux-gnu-linux/.build/aarch64-linux-gnu/build/static
--with-mpfr=/cbuild/slaves/oorts/crosstool-ng/builds/aarch64-linux-gnu-linux/.build/aarch64-linux-gnu/build/static
--with-mpc=/cbuild/slaves/oorts/crosstool-ng/builds/aarch64-linux-gnu-linux/.build/aarch64-linux-gnu/build/static
--with-isl=/cbuild/slaves/oorts/crosstool-ng/builds/aarch64-linux-gnu-linux/.build/aarch64-linux-gnu/build/static
--with-cloog=/cbuild/slaves/oorts/crosstool-ng/builds/aarch64-linux-gnu-linux/.build/aarch64-linux-gnu/build/static
--with-libelf=/cbuild/slaves/oorts/crosstool-ng/builds/aarch64-linux-gnu-linux/.build/aarch64-linux-gnu/build/static
--enable-threads=posix --disable-libstdcxx-pch --enable-linker-build-id
--enable-plugin
--with-local-prefix=/cbuild/slaves/oorts/crosstool-ng/builds/aarch64-linux-gnu-linux/install/aarch64-linux-gnu/libc
--enable-c99 --enable-long-long
Thread model: posix
gcc version 4.8.3 20140203 (prerelease) (crosstool-NG linaro-1.13.1-4.8-2014.02
- Linaro GCC 2014.02)


Android AOSP:

COLLECT_GCC=prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.8/bin/aarch64-linux-android-gcc
 
COLLECT_LTO_WRAPPER=/workarea/stefanb/repos/tmake-only/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.8/bin/../libexec/gcc/aarch64-linux-android/4.8/lto-wrapper
 
Target: aarch64-linux-android                                                   
Configured with: /tmp/AOSP-toolchain/build/../gcc/gcc-4.8/configure
--prefix=/tmp/toolchain-build-aarch64-linux-4.8/prefix
--target=aarch64-linux-android --host=x86_64-linux-gnu --build=x86_64-linux-gnu
--with-gnu-as --with-gnu-ld --enable-languages=c,c++
--with-gmp=/tmp/toolchain-build-aarch64-linux-4.8/temp-install
--with-mpfr=/tmp/toolchain-build-aarch64-linux-4.8/temp-install
--with-mpc=/tmp/toolchain-build-aarch64-linux-4.8/temp-install
--with-cloog=/tmp/toolchain-build-aarch64-linux-4.8/temp-install
--with-isl=/tmp/toolchain-build-aarch64-linux-4.8/temp-install
--with-ppl=/tmp/toolchain-build-aarch64-linux-4.8/temp-install
--disable-ppl-version-check --disable-cloog-version-check
--disable-isl-version-check --enable-cloog-backend=isl
--with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm'
--disable-libssp --enable-threads --disable-nls --disable-libmudflap
--disable-libgomp --disable-libstdc__-v3 --disable-sjlj-exceptions
--disable-shared --disable-tls --disable-libitm --enable-initfini-array
--disable-nls --prefix=/tmp/toolchain-build-aarch64-linux-4.8/prefix
--with-sysroot=/tmp/toolchain-build-aarch64-linux-4.8/prefix/sysroot
--with-binutils-version=2.23 --with-mpfr-version=3.1.1 --with-mpc-version=1.0.1
--with-gmp-version=5.0.5 --with-gcc-version=4.8 --with-gdb-version=7.6
--with-gxx-include-dir=/tmp/toolchain-build-aarch64-linux-4.8/prefix/include/c++/4.8
--with-bugurl=http://source.android.com/source/report-bugs.html
--disable-bootstrap --disable-libquadmath --enable-plugins --enable-libgomp
--disable-libsanitizer --enable-gold --enable-graphite=yes
--with-cloog-version=0.18.0 --with-isl-version=0.11.1
--enable-eh-frame-hdr-for-static --disable-gold --disable-libgomp
--program-transform-name='s&^&aarch64-linux-android-&'
Thread model: posix
gcc version 4.8 (GCC)


With the attached test.c I get the following assembler code for func2():

Case 1:
aarch64-linux-android-gcc -O0 -march=armv8-a -fno-omit-frame-pointer -S test.c
-o -

 func2:
        stp     x29, x30, [sp, -32]!
        add     x29, sp, 0
        str     wzr, [x29,16]
        bl      func_no_leaf
        ldp     x29, x30, [sp], 32
        ret

-> Correct code

Case 2:
aarch64-linux-android-gcc -O0 -march=armv8-a -fno-omit-frame-pointer
-DINCLUDE_ATTRIBUTE -S test.c -o -

 func2:
        sub     sp, sp, #32
        str     x30, [sp]
        str     wzr, [sp,16]
        bl      func_no_leaf
        ldr     x30, [sp]
        add     sp, sp, 32
        ret

-> WRONG BEHAVIOUR: adding the function attribute to the source code forces the
whole module code to be compiled with -fomit-frame-pointer!

Case 3:
aarch64-linux-android-gcc -O0 -march=armv8-a -fomit-frame-pointer
-DINCLUDE_ATTRIBUTE -S test.c -o -

 func2:
        sub     sp, sp, #32
        str     x30, [sp]
        str     wzr, [sp,16]
        bl      func_no_leaf
        ldr     x30, [sp]
        add     sp, sp, 32
        ret

-> WRONG BEHAVIOUR: although there is a function attribute for func2() the code
looks like case 2, instead of the correct code in case 1

Case 4:
aarch64-linux-android-gcc -O0 -march=armv8-a -fomit-frame-pointer
-mno-omit-leaf-frame-pointer -DINCLUDE_ATTRIBUTE -S test.c -o -

 func2:
        stp     x29, x30, [sp, -32]!
        add     x29, sp, 0
        str     wzr, [x29,16]
        bl      func_no_leaf
        ldp     x29, x30, [sp], 32
        ret

-> CORRECT: func2() uses frame pointer, all other code omits the frame pointer.
This is the workaround we currently have to use to get our code to work.

Reply via email to