Ticket #4244 (closed feature request: fixed)

Opened 3 years ago

Last modified 2 months ago

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

Changed 3 years ago by slyfox

  • cc slyfox@… added

Changed 3 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.

Changed 3 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.

Changed 3 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

Changed 3 years ago by PHO

  • cc pho@… added

Changed 3 years ago by hgolden

  • cc howard_b_golden@… added

Changed 17 months ago by igloo

  • priority changed from normal to low
  • milestone changed from 7.4.1 to 7.6.1

Changed 9 months ago by igloo

  • milestone changed from 7.6.1 to 7.6.2

Changed 8 months ago by igloo

  • blockedby 3658 added

Changed 7 months ago by igloo

  • priority changed from low to highest
  • difficulty set to Unknown
  • milestone changed from 7.6.2 to 7.8.1

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")

Changed 2 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.

Changed 2 months ago by igloo

  • blockedby 3658 removed

Changed 2 months ago by igloo

  • status changed from new to closed
  • resolution set to fixed

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")

Changed 8 weeks ago by igloo

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