Opened 4 years ago

Closed 12 months 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 Difficulty: Unknown
Test Case: Blocked By: #3658
Blocking: #7824 Related Tickets:

Description

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()
   http://darcs.haskell.org/cgi-bin/darcsweb.cgi?r=ghc;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 http://www.haskell.org/pipermail/cvs-ghc/2009-November/051196.html

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 4 years ago by slyfox

  • Cc slyfox@… added

comment:2 Changed 4 years ago by igloo

  • Milestone set to 6.16.1

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

comment:3 Changed 4 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 4 years ago by slyfox

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

https://bugs.gentoo.org/show_bug.cgi?id=299709

comment:5 Changed 4 years ago by PHO

  • Cc pho@… added

comment:6 Changed 4 years ago by hgolden

  • Cc howard_b_golden@… added

comment:7 Changed 2 years ago by igloo

  • Milestone changed from 7.4.1 to 7.6.1
  • Priority changed from normal to low

comment:8 Changed 20 months ago by igloo

  • Milestone changed from 7.6.1 to 7.6.2

comment:9 Changed 19 months ago by igloo

  • Blocked By 3658 added

comment:10 Changed 17 months ago by igloo

  • Difficulty set to Unknown
  • Milestone changed from 7.6.2 to 7.8.1
  • Priority changed from low to highest

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

commit c22850f7c950009ee4de84c20dc4a6cf7c0b500f

Author: Ian Lynagh <ian@well-typed.com>
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)
    ("linux","s390")

comment:11 Changed 13 months 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 12 months ago by igloo

  • Blocked By 3658 removed

comment:13 Changed 12 months ago by igloo

  • Resolution set to fixed
  • Status changed from new to closed

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: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> 5+6
11
Prelude> (System.Info.os, System.Info.arch)
("linux","s390")

comment:14 Changed 12 months ago by igloo

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