Opened 4 years ago

Last modified 4 months ago

#5495 new bug

simple program fails with -shared on mac

Reported by: mwotton Owned by:
Priority: low Milestone: 7.12.1
Component: Compiler Version: 7.2.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description (last modified by igloo)

sleipnir ➜  ~  ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.2.1
sleipnir ➜  ~  ghc --make foo.hs -shared
[1 of 1] Compiling Main             ( foo.hs, foo.o )
Linking foo ...
collect2: ld terminated with signal 11 [Segmentation fault]
sleipnir ➜  ~  cat foo.hs
main = putStrLn "hi"

This happened on both of the two systems I tried it on. Package installed from
http://www.haskell.org/ghc/dist/7.2.1/GHC-7.2.1-x86_64.pkg

Change History (12)

comment:1 Changed 3 years ago by igloo

  • Description modified (diff)

comment:2 Changed 3 years ago by igloo

  • Milestone set to 7.4.1
  • Owner set to igloo
  • Priority changed from normal to high

I'll see if I can reproduce this.

comment:3 Changed 3 years ago by igloo

  • Owner igloo deleted
  • Priority changed from high to normal

Ah, I hadn't noticed it was ld segfaulting. Here's a cut-down case:

$ cat h2.s 
.text
.globl _Main_main_info
_Main_main_info:
        leaq _ghczmprim_GHCziUnit_Z0T_closure(%rip),%rax
        jmp _base_GHCziBase_return_info
$ gcc -m64 -fno-stack-protector -c h2.s -o h2.o
$ gcc -m64 -fno-stack-protector -dynamiclib -o h h2.o -undefined dynamic_lookup
collect2: ld terminated with signal 11 [Segmentation fault: 11]
$ gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Interestingly, in 32bit mode we get an error when assembling:

$ gcc -m32 -fno-stack-protector -c h2.s -o h2.o
h2.s:4:`_ghczmprim_GHCziUnit_Z0T_closure(%rip)' is not a valid base/index expression

when compiling with an i386 compiler we instead generate:

    movl $_ghczmprim_GHCziUnit_Z0T_closure+1,-12(%ebp)

Does anyone know if this is our bug or Apple's?

comment:4 Changed 3 years ago by igloo

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

comment:5 Changed 3 years ago by igloo

  • Milestone changed from 7.6.1 to 7.6.2

comment:6 Changed 10 months ago by thoughtpolice

  • Milestone changed from 7.6.2 to 7.10.1

Moving to 7.10.1.

comment:7 Changed 5 months ago by thomie

  • difficulty set to Unknown
  • Status changed from new to infoneeded

Is this still a problem in 7.8.3?

comment:8 Changed 5 months ago by carter

I think so ...

> cat "main=putStrLn \"hi\""
> ghc --make foo.hs -shared -fforce-recomp
[1 of 1] Compiling Main             ( foo.hs, foo.o )
Linking foo ...
ld: illegal text reloc in '_c1Hl_info' to '_stg_ap_2_upd_info' for architecture x86_64
collect2: error: ld returned 1 exit status

a linker error seems to happen, though when GHC is configured to use clang, clang reports the error, whereas when using via GCC, its reported as a ld error

comment:9 follow-up: Changed 5 months ago by rwbarton

I'm not sure whether this is a bug at all. You need -dynamic also, to produce object files that can be linked dynamically.

Granted, the way that -shared and -dynamic interact with make mode is, at best, not obvious.

comment:10 Changed 5 months ago by thomie

  • Architecture changed from x86_64 (amd64) to Unknown/Multiple
  • Operating System changed from MacOS X to Unknown/Multiple
  • Status changed from infoneeded to new

comment:11 in reply to: ↑ 9 Changed 5 months ago by thomie

Replying to rwbarton:

I'm not sure whether this is a bug at all. You need -dynamic also, to produce object files that can be linked dynamically.

Yes, but igloo would know about that, so we should test if the issue from comment:3 is resolved.

Granted, the way that -shared and -dynamic interact with make mode is, at best, not obvious.

See #3704, #3713 and #3712 for that.

comment:12 Changed 4 months ago by thoughtpolice

  • Milestone changed from 7.10.1 to 7.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

Note: See TracTickets for help on using tickets.