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

Use more explicit architecture compiler options on Linux #64366

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aaronfranke
Copy link
Member

@aaronfranke aaronfranke commented Aug 13, 2022

This PR takes a piece out of #55778. Specifically, this PR was driven by this review comment from @akien-mga:

Screen Shot 2022-08-13 at 10 42 41 AM

I tested this PR on x86_64, arm64, and rv64 hosts & targets, and compiling x86_32 on x86_64.

@aaronfranke aaronfranke added this to the 4.0 milestone Aug 13, 2022
@aaronfranke aaronfranke requested review from a team as code owners August 13, 2022 16:06
@YuriSizov YuriSizov modified the milestones: 4.0, 4.1 Feb 10, 2023
@akien-mga akien-mga modified the milestones: 4.1, 4.2 Jun 19, 2023
@aaronfranke aaronfranke modified the milestones: 4.2, 4.3 Oct 11, 2023
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You seem to have missed some cross-compilation code further down that does some of this already, which should likely be removed. The hardcoded lib folder path are actually bogus on many distros, but shouldn't be needed(?).

diff --git a/platform/linuxbsd/detect.py b/platform/linuxbsd/detect.py
index 72bffceb1f..02d8d20fbf 100644
--- a/platform/linuxbsd/detect.py
+++ b/platform/linuxbsd/detect.py
@@ -469,16 +469,6 @@ def configure(env: "Environment"):
     if platform.system() == "FreeBSD":
         env.Append(LINKFLAGS=["-lkvm"])
 
-    ## Cross-compilation
-    # TODO: Support cross-compilation on architectures other than x86.
-    host_is_64_bit = sys.maxsize > 2**32
-    if host_is_64_bit and env["arch"] == "x86_32":
-        env.Append(CCFLAGS=["-m32"])
-        env.Append(LINKFLAGS=["-m32", "-L/usr/lib/i386-linux-gnu"])
-    elif not host_is_64_bit and env["arch"] == "x86_64":
-        env.Append(CCFLAGS=["-m64"])
-        env.Append(LINKFLAGS=["-m64", "-L/usr/lib/i686-linux-gnu"])
-
     # Link those statically for portability
     if env["use_static_cpp"]:
         env.Append(LINKFLAGS=["-static-libgcc", "-static-libstdc++"])

Edit: I'm moving this up in #84307 which will conflict with this PR, but it's a safe-ish fixup for 4.2. You can rebase and remove that whole block as yours supersedes it fully.

Comment on lines 90 to 98
env.Append(CCFLAGS=["-m64", "-march=x86-64"])
env.Append(LINKFLAGS=["-m64", "-march=x86-64"])
elif env["arch"] == "x86_32":
env.Append(CCFLAGS=["-m32", "-march=i686"])
env.Append(LINKFLAGS=["-m32", "-march=i686"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are both -m64/-m32 and -march needed at the same time, or does the latter make the old -m64 and -m32 flags redundant?

Copy link
Member Author

@aaronfranke aaronfranke Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are both required, yes.

If you try to use -march= on x86 without the proper bitness or specifying -m32/-m64 it will not work.

While confusing, -m32/-m64 specifically refers to x86_32 and x86_64, not 32-bit and 64-bit in general.

Co-authored-by: Joaquim Monteiro <joaquim.monteiro@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants