Opened 3 years ago

Closed 3 years ago

#5103 closed bug (fixed)

LLVM backend broken with LLVM 2.9

Reported by: tener Owned by: dterei
Priority: normal Milestone:
Component: Compiler (LLVM) Version: 7.1
Keywords: Cc: dons00@…, johan.tibell@…, daniel.is.fischer@…, p.giarrusso@…
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: None/Unknown Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

Even simplest programs like

module Main where
main = return ()

Fail when compiled with -fllvm

The error is:

ghc -fllvm --make llvm.hs
[1 of 1] Compiling Main             ( llvm.hs, llvm.o )
/tmp/ghc3024_0/ghc3024_0.s: Assembler messages:

/tmp/ghc3024_0/ghc3024_0.s:175:0:
     Error: can't resolve `Main_main_srt' {.rodata section} - `Main_main_info' {.text; .text 6# section}

/tmp/ghc3024_0/ghc3024_0.s:185:0:
     Error: can't resolve `ZCMain_main_srt' {.rodata section} - `ZCMain_main_info' {.text; .text 12# section}

Attachments (1)

as (141 bytes) - added by dterei 3 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 3 years ago by tener

Additional info:

llvmc --version
Low Level Virtual Machine (http://llvm.org/):
  llvm version 2.9
  Optimized build.
  Built Apr  7 2011 (11:28:04).
  Host: x86_64-unknown-linux-gnu
  Host CPU: corei7

  Registered Targets:
    (none)

uname -a
Linux raptor 2.6.37-ARCH #1 SMP PREEMPT Fri Mar 25 15:10:00 CET 2011 x86_64 Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz GenuineIntel GNU/Linux

The Linux distro is Arch Linux.

comment:2 follow-up: Changed 3 years ago by dterei

  • Owner changed from davidterei@… to dterei

Yeah this is a known issue. On Mac OS X things should work but on Linux and Windows LLVM has changed how section labels are handled and so this is the problem.

A work around is this. Put the attached script on your path before the system 'as' program so it runs instead. Basically the script runs sed over the assembly to fix up the labels before running 'as' as usual.

Otherwise you'll have to wait for the next GHC release. LLVM 2.9 works fine otherwise. I actually helped fix 2 fairly major bugs in the RC's to make sure of this.

Changed 3 years ago by dterei

comment:3 in reply to: ↑ 2 Changed 3 years ago by tener

Replying to dterei:

Yeah this is a known issue. On Mac OS X things should work but on Linux and Windows LLVM has changed how section labels are handled and so this is the problem.

A work around is this. Put the attached script on your path before the system 'as' program so it runs instead. Basically the script runs sed over the assembly to fix up the labels before running 'as' as usual.

Otherwise you'll have to wait for the next GHC release. LLVM 2.9 works fine otherwise. I actually helped fix 2 fairly major bugs in the RC's to make sure of this.

Do you mean that GHC HEAD should work fine? I tried but it failed with the same error.

Also the script you provided doesn't solve the issue, unfortunately:

  • $4 should be renamed to $5, at least on x86_64
  • the errors are still the same

Perhaps on 64 bit platform labels have different handling still?

comment:4 Changed 3 years ago by tener

I found a problem: sed patter uses space, whereas in .s files found on my machine \t are used. After this fix everything is fine.

$5 is needed because of extra --64 flag passed to the "as"

comment:5 Changed 3 years ago by dterei

hehe, yeah the 'fix' is a little temperamental but you seem to have figured it out.

comment:6 Changed 3 years ago by tibbe

  • Cc johan.tibell@… added

comment:7 Changed 3 years ago by daniel.is.fischer

  • Cc daniel.is.fischer@… added

Also broken with llvm-3.0 (the package is llvm-2.9.99, so alpha or beta, on openSuSE 11.3),

$ llc --version
Low Level Virtual Machine (http://llvm.org/):
  llvm version 3.0
  Optimized build with assertions.
  Built Apr  9 2011 (14:36:06).
  Host: i386-pc-linux-gnu
  Host CPU: nocona

  Registered Targets:
    alpha   - Alpha [experimental]
    arm     - ARM
    bfin    - Analog Devices Blackfin [experimental]
    c       - C backend
    cellspu - STI CBEA Cell SPU [experimental]
    cpp     - C++ backend
    mblaze  - MBlaze
    mips    - Mips
    mipsel  - Mipsel
    msp430  - MSP430 [experimental]
    ppc32   - PowerPC 32
    ppc64   - PowerPC 64
    ptx     - PTX
    sparc   - Sparc
    sparcv9 - Sparc V9
    systemz - SystemZ
    thumb   - Thumb
    x86     - 32-bit X86: Pentium-Pro and above
    x86-64  - 64-bit X86: EM64T and AMD64
    xcore   - XCore
$ opt --version
Low Level Virtual Machine (http://llvm.org/):
  llvm version 3.0
  Optimized build with assertions.
  Built Apr  9 2011 (14:36:06).
  Host: i386-pc-linux-gnu
  Host CPU: nocona

  Registered Targets:
    (none)

Putting the above as script in ~/bin doesn't help, since no as is called:

Running phase LlvmOpt
*** LLVM Optimiser:
opt /tmp/ghc9231_0/ghc9231_0.ll -o /tmp/ghc9231_0/ghc9231_0.bc -O1
Running phase LlvmLlc
*** LLVM Compiler:
llc -O2 -relocation-model=static /tmp/ghc9231_0/ghc9231_0.bc -o /tmp/ghc9231_0/ghc9231_0.s
Running phase As
*** Assembler:
/usr/bin/gcc -I. -c /tmp/ghc9231_0/ghc9231_0.s -o nothing.o -fno-stack-protector -DDONT_WANT_WIN32_DLL_SUPPORT
/tmp/ghc9231_0/ghc9231_0.s: Assembler messages:

/tmp/ghc9231_0/ghc9231_0.s:185:0:
     Error: can't resolve `Main_main2_srt' {.rodata section} - `Main_main2_info' {.text; .text 10# section}

/tmp/ghc9231_0/ghc9231_0.s:206:0:
     Error: can't resolve `ZCMain_main_srt' {.rodata section} - `ZCMain_main_info' {.text; .text 20# section}

comment:8 Changed 3 years ago by dterei

I don't put any effort into support pre-released versions of LLVM sorry. So your on your own there, however the error is the same error as with 2.9, so the 'as' hack should work. Its a very hacky hack though so you probably need to modify it for your particular machine as tener in the comments above.

comment:9 Changed 3 years ago by dterei

  • Summary changed from LLVM backeng broken with LLVM 2.9 to LLVM backend broken with LLVM 2.9

comment:10 Changed 3 years ago by dons

  • Cc dons00@… added

comment:11 Changed 3 years ago by dons

I needed to tweak the regex to include tabs,

sed 's/.section[    ]*\".text\; .text/.section        .text\; .text/' "$4" > "$4.fixed_s"

comment:12 Changed 3 years ago by Blaisorblade

  • Cc p.giarrusso@… added

FYI, after being hit by this bug on a new installation (GHC 7.0.3/Linux/64bit/bindist), I added a mention of this bug in the installation instruction:
http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/Backends/LLVM/Installing

comment:13 Changed 3 years ago by dterei

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.