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

all: pass -march=x86_64-vX to CGo compiler when GOAMD64=vX is set #48936

Open
Jacalz opened this issue Oct 13, 2021 · 2 comments
Open

all: pass -march=x86_64-vX to CGo compiler when GOAMD64=vX is set #48936

Jacalz opened this issue Oct 13, 2021 · 2 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@Jacalz
Copy link
Contributor

Jacalz commented Oct 13, 2021

What version of Go are you using (go version)?

This only applies to Go 1.18 at the moment because GOAMD64 is WIP.

What operating system and processor architecture are you using (go env)?

x86_64 with v1, v2, v3, v4 using GOAMD64 variable.

What did you do?

I propose that building using the GOAMD64=vX variable set should apply the correct -march=x86_64-vX (i.e. GOAMD64=v3 -> -march=x86_64-v3) to the C compiler used for CGo. This allows C-code to also get optimized to use the updated target architecture with newer instructions that are supported for that target. We would need to check that the C-compiler supports these target architectures before potentially applying a target that does not exist (seems like GCC11 and Clang12 are the initial supported versions: https://www.phoronix.com/scan.php?page=news_item&px=GCC-11-x86-64-Feature-Levels).

Related to #45453

@mvdan
Copy link
Member

mvdan commented Oct 13, 2021

Does the Go toolchain already know enough about C/C++ toolchains to tell whether they support this -march flag? Is there a cheap way to figure that out? Picking up the question from #45453 (comment).

@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 13, 2021
@toothrot toothrot added this to the Backlog milestone Oct 13, 2021
@ianlancetaylor
Copy link
Contributor

@mvdan in cmd/go we use (*Builder).gccSupportsFlag. In cmd/link we use linkerFlagSupported. We can do something similar in cmd/cgo if required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants