Bug 107860 - Compilation failure, ambiguous fisttp
Summary: Compilation failure, ambiguous fisttp
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: build
Depends on:
Blocks:
 
Reported: 2022-11-24 16:45 UTC by simon
Modified: 2023-07-05 13:34 UTC (History)
0 users

See Also:
Host: aarch64-apple-darwin21
Target: x86_64-apple-darwin21
Build: aarch64-apple-darwin21
Known to work:
Known to fail:
Last reconfirmed: 2022-11-24 00:00:00


Attachments
config.log (7.40 KB, text/plain)
2022-11-24 17:35 UTC, simon
Details
gcc/config.log (35.35 KB, text/plain)
2022-11-24 17:41 UTC, simon
Details

Note You need to log in before you can comment on or make changes to this bug.
Description simon 2022-11-24 16:45:14 UTC
Building the snapshot gcc-13-20221120 on macOS 13 (actually an aarch64 machine, but using x86_64-apple-darwin21 compiler under Rosetta) with Command Line Tools 14.1.
Source patched as commit ac50541 for PR107781.

Phase 1 (actually configured with --disable-bootstrap) fails with this (I was building with -j7, so had to extract the relevant parts of the log:

checking __sync extensions... /Volumes/Miscellaneous1/x86_64/gcc-13-20221120/gcc/./gcc/xgcc -B/Volumes/Miscellaneous1/x86_64/gcc-13-20221120/gcc/./gcc/ -B/opt/gcc-13-20221120/x86_64-apple-darwin21/bin/ -B/opt/gcc-13-20221120/x86_64-apple-darwin21/lib/ -isystem /opt/gcc-13-20221120/x86_64-apple-darwin21/include -isystem /opt/gcc-13-20221120/x86_64-apple-darwin21/sys-include --sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk   -c -g -O2  -fno-common  -W -Wall -gnatpg -nostdinc  -fno-toplevel-reorder  \
	  g-debpoo.adb -o g-debpoo.o
...
/var/folders/ch/k_zwspdx3qsfbt1_x21zld6m0000gn/T//ccJJp5X6.s:11992:2: error: ambiguous instructions require an explicit suffix (could be 'fisttps', or 'fisttpl')
        fisttp  -408(%rbp)
        ^
/var/folders/ch/k_zwspdx3qsfbt1_x21zld6m0000gn/T//ccJJp5X6.s:12278:2: error: ambiguous instructions require an explicit suffix (could be 'fisttps', or 'fisttpl')
        fisttp  -408(%rbp)
        ^
...
make[6]: *** [g-debpoo.o] Error 1

Configure script (BUILD set to x86_64-apple-darwin21):
+++++++++++++++
XCODE=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
CLU=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

$GCC_SRC/configure                                                      \
  --prefix=$PREFIX                                                      \
  --without-libiconv-prefix                                             \
  --disable-libmudflap                                                  \
  --disable-libstdcxx-pch                                               \
  --disable-libsanitizer                                                \
  --disable-libcc1                                                      \
  --disable-libcilkrts                                                  \
  --disable-multilib                                                    \
  --disable-nls                                                         \
  --enable-languages=c,c++,ada                                          \
  --host=$BUILD                                                         \
  --target=$BUILD                                                       \
  --build=$BUILD                                                        \
  --without-isl                                                         \
  --with-build-sysroot="$(xcrun --show-sdk-path)"                       \
  --with-sysroot=                                                       \
  --with-specs="%{!sysroot=*:--sysroot=%:if-exists-else($XCODE $CLU)}"  \
  --with-build-config=no                                                \
  --disable-bootstrap                                                   \
   CFLAGS=-Wno-deprecated-declarations                                  \
   CXXFLAGS=-Wno-deprecated-declarations
+++++++++++
Comment 1 Andrew Pinski 2022-11-24 17:05:20 UTC
Can you attach config.log from the gcc directory?

It should have done detected filds :

    gcc_GAS_CHECK_FEATURE([filds and fists mnemonics],
       gcc_cv_as_ix86_filds,,
       [filds (%ebp); fists (%ebp)],,
       [AC_DEFINE(HAVE_AS_IX86_FILDS, 1,
         [Define if your assembler uses filds and fists mnemonics.])])
Comment 2 simon 2022-11-24 17:35:26 UTC
Created attachment 53960 [details]
config.log

As requested
Comment 3 simon 2022-11-24 17:41:11 UTC
Created attachment 53961 [details]
gcc/config.log

As requested (this time, sorry about previous attempt)
Comment 4 Andrew Pinski 2022-11-24 17:45:22 UTC
configure:27158: checking assembler for filds and fists mnemonics
configure:27167: /usr/bin/as    -o conftest.o conftest.s >&5
conftest.s:1:8: error: unknown token in expression
filds (%ebp); fists (%ebp)
       ^
conftest.s:1:7: error: invalid operand
filds (%ebp); fists (%ebp)
      ^

Oh this is a configure issue on how to test as here.
But I don't know exactly how to fix it really because GCC configure with no option is the right thing to do for the target.

You might need a wrapper as to do the right thing really for this kind of building ....
Comment 5 Andrew Pinski 2022-11-24 17:46:59 UTC
Note you could in theory just build a cross compiler but you still need a wrapper as to configure to detect the correct thing ....
Comment 6 simon 2022-11-25 14:02:14 UTC
The situation with aarch64-apple-darwin vs x86_64-apple-darwin isn't I think quite like the standard cross-compilation scenario, because of Apple's Rosetta x86_64 emulation and the fact that all the low-level tools (as, ld, ...) support both architectures.

If I take an x86_64-apple-darwin compiler and run it on aarch64-apple-darwin it will generate x86_64 assembler and invoke as, ld with the right switches to create x86_84 binaries and executables; the executables will run on aarch64 under Rosetta or on x86_64 natively.

So I'm not sure what --build, --host should have been set to (given I don't want a cross-compiler; the cross- facilities are provided by macOS under the hood).

In what I was trying to do, the host machine was aarch64-apple-darwin22, but notably aarch64 running Rosetta. The boot compiler was x86_64-apple-darwin21.

Anyway, the issue here was the way that configure invoked the assembler; /usr/bin/as will assume it's targeting aarch64 (aka arm64) unless told different.

These are the results of compiling the test case:

   $ cat conftest-filds-fists.s
   // $gcc_cv_as $gcc_cv_as_flags  -o conftest.o conftest.s
           filds (%ebp)
           fists (%ebp)

with /usr/bin/as -c -b conftest-filds-fists.s -o conftest-filds-fists.o

(a) on x86_64

Apple clang version 14.0.0 (clang-1400.0.29.201)
Target: x86_64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1as -triple x86_64-apple-macosx12.0.0 -filetype obj -main-file-name conftest-filds-fists.s -target-cpu penryn -fdebug-compilation-dir=/Users/simon/tmp -dwarf-debug-producer "Apple clang version 14.0.0 (clang-1400.0.29.201)" -dwarf-version=4 -mrelocation-model pic --mrelax-relocations -mllvm -disable-aligned-alloc-awareness=1 -o conftest-filds-fists.o conftest-filds-fists.s

(b) on aarch64

$ /usr/bin/as -c -v conftest-filds-fists.s -o conftest-filds-fists.o
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1as -triple arm64-apple-macosx13.0.0 -filetype obj -main-file-name conftest-filds-fists.s -target-cpu apple-m1 -target-feature +v8.5a -target-feature +fp-armv8 -target-feature +neon -target-feature +crc -target-feature +crypto -target-feature +dotprod -target-feature +fp16fml -target-feature +ras -target-feature +lse -target-feature +rdm -target-feature +rcpc -target-feature +zcm -target-feature +zcz -target-feature +fullfp16 -target-feature +sm4 -target-feature +sha3 -target-feature +sha2 -target-feature +aes -fdebug-compilation-dir=/Volumes/Miscellaneous1/x86_64/gcc-13-20221120/gcc -dwarf-debug-producer "Apple clang version 14.0.0 (clang-1400.0.29.202)" -dwarf-version=4 -mrelocation-model pic --mrelax-relocations -mllvm -disable-aligned-alloc-awareness=1 -o conftest-filds-fists.o conftest-filds-fists.s
conftest-filds-fists.s:2:16: error: unknown token in expression
        filds (%ebp)
               ^
conftest-filds-fists.s:2:15: error: invalid operand
        filds (%ebp)
              ^
conftest-filds-fists.s:3:16: error: unknown token in expression
        fists (%ebp)
               ^
conftest-filds-fists.s:3:15: error: invalid operand
        fists (%ebp)
              ^
(c) on aarch64, with -arch x86_64

$ /usr/bin/as -c -v conftest-filds-fists.s -o conftest-filds-fists.o -arch x86_64
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: x86_64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1as -triple x86_64-apple-macosx13.0.0 -filetype obj -main-file-name conftest-filds-fists.s -target-cpu penryn -fdebug-compilation-dir=/Volumes/Miscellaneous1/x86_64/gcc-13-20221120/gcc -dwarf-debug-producer "Apple clang version 14.0.0 (clang-1400.0.29.202)" -dwarf-version=4 -mrelocation-model pic --mrelax-relocations -mllvm -disable-aligned-alloc-awareness=1 -o conftest-filds-fists.o conftest-filds-fists.s

========================

I think the solution to this PR might be to set it as INVALID or WONTFIX? up to you.
Comment 7 Andrew Pinski 2022-11-25 14:08:40 UTC
The same issue you would run into even on Linux with qemu and gnu as (though gcc does not add the right target options to as as it assumes you have one that targets your target by default.
Comment 8 Andrew Pinski 2022-12-05 23:34:08 UTC
You need to do "arch -x86_64 bash" to this build really.
Otherwise you end up with the arm64 assembler.
So if you start with that, it should work.
Comment 9 simon 2023-07-05 13:34:35 UTC
(In reply to Andrew Pinski from comment #8)
> You need to do "arch -x86_64 bash" to this build really.
> Otherwise you end up with the arm64 assembler.
> So if you start with that, it should work.

Exactly so.

I don't think I completely understood your point at the time, sorry about that, but today I verified it!