Opened 7 years ago

Closed 2 years ago

Last modified 2 years ago

#3814 closed feature request (duplicate)

Compile to more than one (sub)-architecture

Reported by: filcab Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.12.1
Keywords: architecture, compiler, x86_64 Cc: filcab+ghc@…, karel.gardas@…, dankna@…, william.knop.nospam@…, shelarcy@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #4163 Differential Rev(s):
Wiki Page:

Description (last modified by igloo)

GHC, as far as I can tell, can only compile files for one architecture (let's call it the "host architecture").

This brings some problems... The biggest of which is that we lose the option of building for 32/64 bits in one of the "hybrid" architectures (For example, in x86_64-linux or i386-darwin)

If I build a ghc in a x86_64 linux I will only get the x86_64 code generator and not the i386 generator. This will stop me from building a program which links with a library that only has a 32-bit version. If I want a GHC which will only compile for the i386, I will have to cross-compile, which is not very pretty.

The same will happen on the Mac OS X side (even though the x86_64-darwin port is still on its way...).

But GHC "should" (IMHO) be able to do like GCC and be able to generate code for both architecturess (i386 and x86_64), through the usage of compiler flags (which would also be passed to any gcc sub-process, if need be). At least if it is installed in a x86_64 (and PPC, if PPC64 is supported) system.

Even better would be to do like LLVM's llc which enables a user to generate an assembly file for a target architecture from any other architecture.

Example of an LLVM target list:

filcab@fry:/stuff/src> llc --version
Low Level Virtual Machine (
  llvm version 2.7svn
  DEBUG build with assertions.
  Built Jan 10 2010 (00:25:59).
  Host: x86_64-unknown-linux-gnu
  Host CPU: core2

  Registered Targets:
    arm     - ARM
    c       - C backend
    cellspu - STI CBEA Cell SPU [experimental]
    cpp     - C++ backend
    mips    - Mips
    msil    - MSIL backend
    ppc64   - PowerPC 64
    sparc   - Sparc
    x86     - 32-bit X86: Pentium-Pro and above
    x86-64  - 64-bit X86: EM64T and AMD64

Change History (10)

comment:1 Changed 7 years ago by filcab

Cc: filcab+ghc@… added

comment:2 Changed 7 years ago by igloo

Description: modified (diff)

comment:3 Changed 7 years ago by igloo

Milestone: _|_

This is something we're slowly working towards. See also #964.

comment:4 Changed 6 years ago by kgardas

Cc: karel.gardas@… added

comment:5 Changed 6 years ago by dankna

Cc: dankna@… added

comment:6 Changed 6 years ago by altaic

Cc: william.knop.nospam@… added

comment:7 Changed 4 years ago by morabbin

See also #964.

comment:8 Changed 4 years ago by shelarcy

Cc: shelarcy@… added

comment:9 Changed 2 years ago by thomie

difficulty: Unknown
Resolution: duplicate
Status: newclosed

comment:10 Changed 2 years ago by rwbarton

The description touches on two issues: (1) being able to cross-compile at all and (2) being able to generate code for several different targets with the same compiler by using command-line switches. We have (1) currently (though it's a bit DIY), but not (2). But I'll let someone else file a feature request for (2) if they want it, since I'm not convinced it's sufficiently more valuable than just having one ghc installed for each target.

Note: See TracTickets for help on using tickets.