Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mips32: object is FP32 while it claim as FPXX #39435

Open
wzssyqa opened this issue Jun 6, 2020 · 10 comments
Open

mips32: object is FP32 while it claim as FPXX #39435

wzssyqa opened this issue Jun 6, 2020 · 10 comments
Labels
Milestone

Comments

@wzssyqa
Copy link

@wzssyqa wzssyqa commented Jun 6, 2020

MIPS32: switch to fpxx from fp32 or even fp64
In Long term, we should switch to FPXX or FP64, so I keep #39289 open

To add .gnu.attributes and .MIPS.abiflags section, currently we can just use -mfp32 option to gcc:

--- a/src/cmd/go/internal/work/exec.go
+++ b/src/cmd/go/internal/work/exec.go
@@ -2411,7 +2411,7 @@ func (b *Builder) gccArchArgs() []string
        case "mips64", "mips64le":
                return []string{"-mabi=64"}
        case "mips", "mipsle":
-               return []string{"-mabi=32", "-march=mips32"}
+               return []string{"-mabi=32", "-march=mips32", "-mfp32"}
        case "ppc64":
                if cfg.Goos == "aix" {
                        return []string{"-maix64"}
@wzssyqa
Copy link
Author

@wzssyqa wzssyqa commented Jun 7, 2020

For exe that is not linked with libc etc, It will contains no .gnu.attributes and .MIPS.abiflags section, kernel will treat them as FP32. It make it just work.

@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Jun 8, 2020

The proposed change looks good to me. Want to send a CL? Thanks.

I think you may also want to do a similar change in cmd/cgo/gcc.go.

For a side note, I wonder if we want to pass softfloat flags to C compiler if softfloat is set.

Also cc @ianlancetaylor

@toothrot toothrot added the NeedsFix label Jun 8, 2020
@toothrot toothrot added this to the Backlog milestone Jun 8, 2020
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 8, 2020

I agree about passing -msoft-float when appropriate.

Do we currently assume 32-bit floating point registers in the Go compiler? If so I agree about passing -mfp32. At some point the Go linker will need to generate the appropriate sections.

@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Jun 8, 2020

Do we currently assume 32-bit floating point registers in the Go compiler?

Yes.

@wzssyqa
Copy link
Author

@wzssyqa wzssyqa commented Jun 9, 2020

Do we currently assume 32-bit floating point registers in the Go compiler? If so I agree about passing -mfp32. At some point the Go linker will need to generate the appropriate sections.

Yes. #39289 is about it.
Now we spilt a ldc1 into 2 lwc1, which makes assume 32-bit float FPR.
Before we assume that we are full FPXX support, we need more investment.

@gopherbot
Copy link

@gopherbot gopherbot commented Jun 9, 2020

Change https://golang.org/cl/237058 mentions this issue: MIPS/cgo: Add -mfp32 and -mhard/soft-float to gcc

@wzssyqa
Copy link
Author

@wzssyqa wzssyqa commented Jun 9, 2020

Or, should we split it to 2 patch?

@wzssyqa
Copy link
Author

@wzssyqa wzssyqa commented Jun 19, 2020

what's more should I do?

@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Jun 19, 2020

what's more should I do?

As far as I can tell, nothing. Thanks for sending the CL.

wzssyqa added a commit to wzssyqa/go that referenced this issue Jun 21, 2020
For mips32 currently, we are using FP32, while the gcc may be FPXX,
which may generate .MIPS.abiflags and .gnu.attributes section with
value as FPXX. So the kernel will treat the exe as FPXX, and may
choose to use FR=1 FPU mode for it.
Currently, in Go, we use 2 lwc1 to load both half of a double value
to a pair of even-odd FPR. This behavior can only work with FR=0 mode.

In FR=1 mode, all of 32 FPR are 64bit. If we lwc1 the high-half of a double
value to an odd FPR, and try to use the previous even FPR to compute, the
real high-half of even FPR will be unpredicatable.
We set -mfp32 to force the gcc generate FP32 code and section value.

More details about FP32/FPXX/FP64 are explained in:
https://web.archive.org/web/20180828210612/https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking

When GOMIPS/GOMIPS64 is set as softfloat, we should also pass
 -msoft-float to gcc.

Fixes golang#39435

Change-Id: I54026ad416a815fe43a9261ebf6d02e5519c3930
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.