Opened 9 years ago

Closed 6 years ago

#4244 closed feature request (fixed)

Use system linker in GHCi to support alpha, ia64, ppc64

Reported by: batterseapower Owned by:
Priority: highest Milestone: 7.8.1
Component: GHCi Version: 6.13
Keywords: Cc: slyfox@…, pho@…, howard_b_golden@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: #3658 Blocking: #7824
Related Tickets: Differential Rev(s):
Wiki Page:


Sergei Trofimovich says:

> AFAIK the current linker is meant to support Mach O, ELF and COFF,
> which should cover almost every platform GHC is able to run on. Now,
> it's not ideal that GHC maintains its own dynamic linker
> implementation, but if someone has discovered a bugs with it (or any
> other bug preventing TH from working) I'm sure GHC HQ would be
> interested in knowing.

Unfortunately, GHC itself not just 'dlopen's shared objects. It loads them
by pieces manually setting up relocations (see makeSymbolExtra by link below).

Each operating system on certaion $ARCH defines it's own ELF spec, which consists of two parts:
   1. common part. platform agnostic (byte sex, byte width, symbol string table,
      section flags, dynamic section attributes and etc.)
   2. platform dependant. certain section types, such as TOC sections (ppc64),
      are implemented to solve some certain architecture constraints. You cannot
      program them "in advance".
          $ grep PPC64 /usr/include/elf.h
      will show way more fun things to be implemented for perfect .so support.

The best thing to make sure is to look at the real support for ELF in ghci:

Please, look at file ghc/rtc/Linker.c and function do_Elf_Rela_relocations();a=headblob;f=/rts/Linker.c

Conclusion: having ELF aware system is not enough to have ghci support in any form.

Practically, current gentoo supports ghci on:
   i386, amd64, ppc32, sparc(i'm unsure)
and does not support it on:
   alpha, ia64, ppc64

Ideally, GHC (and haddock as a result) should support 'ghci'less template-haskell support
at least on platforms w/o ghci.

Or alternatively haddock could be buildable on 'ghci'less GHC.
It could ignore template-haskell statements (anyway you will not be able to build
'TH'ful source on such platform)

See also #3445 #3654 and Simon's email at

So we need to reuse the system linker or extend our custom one to catch all the cases we see in the wild.

Change History (14)

comment:1 Changed 9 years ago by slyfox

Cc: slyfox@… added

comment:2 Changed 8 years ago by igloo

Milestone: 6.16.1

The best way to achieve this is probably to switch to using dynamic libraries for GHCi.

comment:3 Changed 8 years ago by hgolden

Please also look at #3333. I'm working on adding loading of weak symbols (for ELF only) to the custom linker. I'm not doing anything for MACHO and COFF.

I agree that using the system's dynamic linker is the goal.

comment:4 Changed 8 years ago by slyfox

Properly implemented system's linker should also solve problems with vanilla ghci on PaX kernel:

comment:5 Changed 8 years ago by PHO

Cc: pho@… added

comment:6 Changed 8 years ago by hgolden

Cc: howard_b_golden@… added

comment:7 Changed 7 years ago by igloo

Priority: normallow

comment:8 Changed 6 years ago by igloo


comment:9 Changed 6 years ago by igloo

Blocked By: 3658 added

comment:10 Changed 6 years ago by igloo

difficulty: Unknown
Priority: lowhighest

This will be fixed once dynamic-by-default is enabled again:

commit c22850f7c950009ee4de84c20dc4a6cf7c0b500f

Author: Ian Lynagh <>
Date:   Thu Nov 22 21:35:29 2012 +0000

    Enable dynamic-by-default for unregisterised arches
    This makes ghci work on platforms without any special support in the
    GHCi linker:
    Prelude> (System.Info.os, System.Info.arch)

comment:11 Changed 6 years ago by igloo

Blocking: 7824 added

(In #7824) Thanks for the report. I assume that this is an unregisterised compiler, in which case this will be fixed once #4244 is fixed.

comment:12 Changed 6 years ago by igloo

Blocked By: 3658 removed

comment:13 Changed 6 years ago by igloo

Resolution: fixed
Status: newclosed

This now works, with DYNAMIC_GHC_PROGRAMS="YES" (which is the case on all non-Windows platforms in HEAD):

$ inplace/bin/ghc-stage2 --interactive
GHCi, version 7.7.20130423:  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> 5+6
Prelude> (System.Info.os, System.Info.arch)

comment:14 Changed 6 years ago by igloo

Blocked By: 3658 added
Note: See TracTickets for help on using tickets.