Opened 5 years ago

Last modified 13 months ago

#5495 new bug

simple program fails with -shared on mac

Reported by: mwotton Owned by:
Priority: low Milestone:
Component: Runtime System (Linker) Version: 7.2.1
Keywords: Cc:
Operating System: MacOS X Architecture: Unknown/Multiple
Type of failure: Compile-time crash Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

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 (15)

comment:1 Changed 5 years ago by igloo

Description: modified (diff)

comment:2 Changed 5 years ago by igloo

Milestone: 7.4.1
Owner: set to igloo
Priority: normalhigh

I'll see if I can reproduce this.

comment:3 Changed 5 years ago by igloo

Owner: igloo deleted
Priority: highnormal

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 5 years ago by igloo

Milestone: 7.4.17.6.1
Priority: normallow

comment:5 Changed 4 years ago by igloo

Milestone: 7.6.17.6.2

comment:6 Changed 3 years ago by thoughtpolice

Milestone: 7.6.27.10.1

Moving to 7.10.1.

comment:7 Changed 2 years ago by thomie

difficulty: Unknown
Status: newinfoneeded

Is this still a problem in 7.8.3?

comment:8 Changed 2 years 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 Changed 2 years 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 2 years ago by thomie

Architecture: x86_64 (amd64)Unknown/Multiple
Operating System: MacOS XUnknown/Multiple
Status: infoneedednew

comment:11 in reply to:  9 Changed 2 years 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 2 years ago by thoughtpolice

Milestone: 7.10.17.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.

comment:13 Changed 18 months ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

comment:14 Changed 18 months ago by thomie

Component: CompilerRuntime System (Linker)
Operating System: Unknown/MultipleMacOS X

comment:15 Changed 13 months ago by thomie

Milestone: 8.0.1
Note: See TracTickets for help on using tickets.