gcc 4.x not supporting x87 FPU math?
Asked Answered
G

2

6

I've been trying to compile gcc 4.x from the sources using --with-fpmath=387 but I'm getting this error: "Invalid --with-fpmath=387". I looked in the configs and found that it doesn't support this option (even though docs still mention it as a possible option):

case ${with_fpmath} in
  avx)
    tm_file="${tm_file} i386/avxmath.h"
    ;;
  sse)
    tm_file="${tm_file} i386/ssemath.h"
    ;;
  *)
    echo "Invalid --with-fpmath=$with_fpmath" 1>&2
    exit 1

Basically, I started this whole thing because I need to supply an executable for an old target platform (in fact, it's an old Celeron but without any SSE2 instructions that are apparently used by libstdc++ by DEFAULT). The executable crashes at the first instruction (movq XMM0,...) coming from copying routines in libstdc++ with an "Illegal instruction" message. Is there any way to resolve this? I need to be on a fairly recent g++ to be able to port my existing code base.

I was wondering if it's possible to supply these headers/sources from an older build to enable support for regular x87 instructions, so that no SSE instructions are referenced?

UPDATE: Please note I'm talking about compiled libstdc++ having SSE2 instructions in the object code, so the question is not about gcc command line arguments. No matter what I'm supplying to gcc when compiling my code, it will link with libstdc++ that already has built-in SSE2 instructions.

The real answer is not to use ANY --with-fpmath switches when compiling GCC. I got confused by the configure script switch statement thinking that it only supports sse or avx, while, in fact, the default value (not mentioned in this switch is "387"). So make sure you don't use --with-fpmath when running configure. I recompiled GCC without it and it now works fine.

Thanks.

Gilus answered 12/1, 2014 at 2:11 Comment(1)
As you've found the solution please either close this question or add your update as an answer and accept that answer.Discomfort
G
1

Please note the question was about compiled libstdc++ having SSE2 instructions in the object code, so the question was not about gcc command line arguments. No matter what I'm supplying to gcc when compiling my code, it will link with libstdc++ that already has built-in SSE2 instructions.

The real answer is not to use ANY --with-fpmath switches when compiling GCC. I got confused by the configure script switch statement thinking that it only supports sse or avx, while, in fact, the default value (not mentioned in this switch is "387"). So make sure you don't use --with-fpmath when running configure. I recompiled GCC without it and it now works fine.

Gilus answered 10/3, 2014 at 14:5 Comment(1)
You do that with -mno-sse if your GCC defaults to enabling -msse2 or something even in 32-bit mode.Freeboard
I
6

The argument to tell gcc to produce code for a specific target is -march=CPU where CPU is the particular cpu you want. For an old celeron, you probably want -march=pentium2 or -march=pentium3

To control the fp codegen separately, newer versions of gcc use -mfpmath= -- in your case, you want -mfpmath=387.

All of these and many others are covered in the gcc documentation

edit

In order to use those flags for building libraries (such as libstdc++) that you'll later link in to programs, you need to configure the build for the library to use the appropriate flags. libstdc++ gets built as part of the g++ build, so you'll need to do a custom build -- you can use configure CXXFLAGS=-mfpmath=387 to set extra flags to use while building things.

Imaimage answered 12/1, 2014 at 2:32 Comment(1)
Thanks Chris, but I'm talking about compilation of appropriate libstdc++ that uses the earlier mentioned settings to generate code I'll be linking too later. I.e. no matter what arguments I'll supply to the compiler it will be linking with the libstdc++ that ALREADY has SSE2 instructions. Hence this needs to be done at the early compilation stage when all dependencies of g++ are compiled. PS I can't perform dynamic linking as the target OS doesn't have any libstdc++ installed - it all has to be statically linked.Gilus
G
1

Please note the question was about compiled libstdc++ having SSE2 instructions in the object code, so the question was not about gcc command line arguments. No matter what I'm supplying to gcc when compiling my code, it will link with libstdc++ that already has built-in SSE2 instructions.

The real answer is not to use ANY --with-fpmath switches when compiling GCC. I got confused by the configure script switch statement thinking that it only supports sse or avx, while, in fact, the default value (not mentioned in this switch is "387"). So make sure you don't use --with-fpmath when running configure. I recompiled GCC without it and it now works fine.

Gilus answered 10/3, 2014 at 14:5 Comment(1)
You do that with -mno-sse if your GCC defaults to enabling -msse2 or something even in 32-bit mode.Freeboard

© 2022 - 2024 — McMap. All rights reserved.