Opened 3 years ago

Closed 3 years ago

#9895 closed feature request (fixed)

No -mtriple param being passed to opt/llc when cross compiling

Reported by: erikd Owned by: erikd
Priority: normal Milestone: 7.10.2
Component: Compiler (LLVM) Version: 7.9
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC doesn't work at all Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D576, Phab:D585
Wiki Page:

Description

Currently trying to build an x86_64-linu to arm64-linux cross-compiler.

After fixing some code in rts/StgCRun.c i ran into an issue where ghc was calling llc and generating x86_64 assembly instead of aarch64 assembly.

For now, I've hacked compiler/main/SysTools.hs to add -mtriple=aarch64-linux-gnu to the opt and llc command lines and that allows me to get a bit further in the compile process.

For cross-compiling, passing something like this -mtriple=... is pretty much mandatory. I suggest adding it by doing the following:

  • Add a crossCompiling :: Bool field to DynFlags.
  • Add the -mtriple=... string to the sOpt_lo and sOpt_lc fields of Settings when we are cross-compiling.
  • Possibly also store the triple string in the Platform struct.

Comments?

Change History (9)

comment:1 Changed 3 years ago by erikd

Luite clued me in on the existance of a "settings" file which is read by the function initSysTools in the SysTools module. Currently the extra options for LLVM's opt and llc are initialized as:

    sOpt_lo      = [],
    sOpt_lc      = [],

Adding the -mtriple=... option here seems the obvious place.

comment:2 Changed 3 years ago by erikd

Checking the LLVM docs, it seems that -mtriple=.... is supported at least as far back as LLVM 3.2.

comment:3 Changed 3 years ago by erikd

Differential Rev(s): D576
Status: newpatch

comment:4 Changed 3 years ago by rwbarton

Differential Rev(s): D576Phab:D576

comment:5 Changed 3 years ago by thoughtpolice

Milestone: 7.10.17.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:6 Changed 3 years ago by Erik de Castro Lopo <erikd@…>

In 58ac9c8f6e986bac817ad08d5a2fd11cd167f029/ghc:

LlvmCodeGen cross-compiling fixes (#9895)

Summary:
* Throw an error when cross-compiling without a target definition.
  When cross compiling via LLVM, a target 'datalayout' and 'triple' must
  be defined or LLVM will generate code for the compile host instead of
  the compile target.

* Add aarch64-unknown-linux-gnu target.
  The datalayout and triple lines were found by using clang to compile a
  small C program and -emit-llvm to get the LLVM IR output.

Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>

Test Plan: validate

Reviewers: rwbarton, carter, hvr, bgamari, austin

Reviewed By: austin

Subscribers: carter, thomie, garious

Differential Revision: https://phabricator.haskell.org/D585

GHC Trac Issues: #9895

comment:7 Changed 3 years ago by thoughtpolice

Component: CompilerCompiler (LLVM)
Differential Rev(s): Phab:D576Phab:D576, Phab:D585
Resolution: fixed
Status: patchclosed
Type of failure: None/UnknownGHC doesn't work at all

Closing due to the patch being merged.

comment:8 Changed 3 years ago by erikd

Milestone: 7.12.17.10.2
Status: closedmerge

Please merge this patch to ghc-7.10 branch as it fixes x86_64/linux to aarch64/linux cross compiling.

Last edited 3 years ago by erikd (previous) (diff)

comment:9 Changed 3 years ago by thoughtpolice

Status: mergeclosed

Merged to ghc-7.10.

Note: See TracTickets for help on using tickets.