Opened 9 years ago

Closed 8 years ago

#5293 closed bug (fixed)

Linker error from integer-gmp (OS X 10.7)

Reported by: jhenahan Owned by: chak
Priority: highest Milestone: 7.4.1
Component: Compiler Version: 7.0.4
Keywords: Cc: pho@…
Operating System: MacOS X Architecture: x86_64 (amd64)
Type of failure: GHC doesn't work at all Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

I recently upgraded to the latest dev build of OS X Lion and Xcode 4.2, and I've been having some linking issues related to integer-gmp. I installed ghc-7.0.4-x86_64 from the .pkg with no apparent problems, but running ghc --make test.hs (where test.hs is simply main = print "Hello, World!" (attached, for convenience)) produces the following:

Linking test ...
ld: warning: could not create compact unwind for _ffi_call_unix64: does not use RBP or
RSP based frame
ld: illegal text reloc to ___gmp_modlimb_invert_table from
/Library/Frameworks/GHC.framework/Versions/7.0.4-x86_64/usr/lib/ghc-
7.0.4/integer-gmp-0.2.0.3/libHSinteger-gmp-0.2.0.3.a(mp_minv_tab.o) in 
___gmpn_modexact_1c_odd for architecture x86_64
collect2: ld returned 1 exit status

The bit about the unwind was present on my Snow Leopard install with Xcode 4.0.2, and there were never any problems. What is new is the illegal text reloc error. What little I've been able to find online seems to suggest that this is due to Xcode's linker now being a bit safer (read pickier) and giving errors where once it might have given warnings.

I considered building ghc HEAD, but of course without a working ghc that's a bit of a futile effort.

I understand that Dan Knapp (dankna) has also moved up to Lion and is having no such issue, so I am particularly curious about our differing experiences. It may be that the picky linker is only a product of the most recent dev build of Xcode, but I can't be sure.

Any thoughts or pointers would be greatly appreciated. Also, apologies if I've put the ticket together incorrectly.

Attachments (1)

test.hs (28 bytes) - added by jhenahan 9 years ago.
test file

Download all attachments as: .zip

Change History (19)

Changed 9 years ago by jhenahan

Attachment: test.hs added

test file

comment:1 Changed 9 years ago by igloo

Milestone: 7.2.1
Priority: normalhighest

comment:2 in reply to:  description Changed 9 years ago by jhenahan

For clarity's sake, here are some symlinks, just in case they prove useful:

readlink /usr/bin/{gcc,cc,g++,c++}
llvm-gcc-4.2
llvm-gcc-4.2
llvm-g++-4.2
llvm-g++-4.2

And some other info

ld -v
@(#)PROGRAM:ld  PROJECT:ld64-123.4.1
llvm version 3.0svn, from Apple Clang 3.0 (build 209.9.2)

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.

gcc-4.2 --version
i686-apple-darwin11-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
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.

comment:3 Changed 9 years ago by PHO

Cc: pho@… added

comment:4 Changed 9 years ago by igloo

Milestone: 7.2.17.4.1

punting until after the 10.7 release, so we can reproduce it

comment:5 Changed 9 years ago by chak

This same issue generates a warning in Xcode 4.1. To work around it until GHC gets fixed, add the option -optl-Wl,-no_pie when linking.

comment:6 Changed 8 years ago by chak

Resolution: duplicate
Status: newclosed

Duplicate of #5019

comment:7 Changed 8 years ago by chak

Resolution: duplicate
Status: closednew

I spoke too quickly. The warning is still a warning. The fatal error is new with Xcode 4.2 and seems to be in the GNU gmp library. Is there a newer version of the library that works with Xcode 4.2?

comment:8 in reply to:  7 Changed 8 years ago by jhenahan

Replying to chak:

I spoke too quickly. The warning is still a warning. The fatal error is new with Xcode 4.2 and seems to be in the GNU gmp library. Is there a newer version of the library that works with Xcode 4.2?

I tried building libgmp 5.0.2 (the latest stable release) through homebrew and I wasn't able to get GHC to compile with it. I may just not have set the right flags, though. If you've got any pointers, I can certainly try them out. I'm not sure what version of GMP is currently distributed with Xcode 4.2. I can also attempt to compile GMP from source, if that might make a difference. I've since switched back to Snow Leopard to continue working with GHC, but I've heard that GHC is functional with Xcode 4.1 on Lion, so I may be switching up again in the near future so more germane prodding can continue.

comment:9 Changed 8 years ago by chak

You can use GHC with Xcode 4.1 on Lion. That's what I am using.

comment:10 Changed 8 years ago by chak

Status: newmerge

I just pushed

commit 30ccc9f39dd2cf1ad14e6116778aa1fd94526c19
Author: Manuel M T Chakravarty <chak@cse.unsw.edu.au>
Date:   Wed Jul 27 23:05:01 2011 +1000

   On OS X x86_64, use "-Wl,-no_pie" and "-Wl,-no_compact_unwind" to avoid linker warnings

   - "-Wl,-no_pie" can be removed once GMP gets updated

This fixes the problem on Lion (x86_64) with Xcode 4.1.

If anybody has Xcode 4.2 lying around, let me know if it fixes the fatal error as well. (I'm not keen on the dance with two simultaneous Xcode installations and don't want to remove 4.1.)

A better fix would be to update gmp (and to remove "-Wl,-no_pie" again). Hence, I leave this bug open.

PLEASE MERGE TO 7.2

comment:11 Changed 8 years ago by igloo@…

commit 4e044840808ffac427582d288f6de07e2cdd544d

Author: Ian Lynagh <igloo@earth.li>
Date:   Wed Aug 3 20:25:52 2011 +0100

    Stop using -Wl,-no_pie on OS X
    
    Now that the in-tree gmp has been upgraded, it should no longer be
    necessary, according to #5293.

 compiler/main/DriverPipeline.hs |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

comment:12 Changed 8 years ago by igloo

Resolution: fixed
Status: mergeclosed

comment:13 Changed 8 years ago by chak

Resolution: fixed
Status: closednew

Unfortunately, the new GMP by itself isn't sufficient to fix the PIC-related problem. GMP uses m4 scripts to pre-process the code written in assembly and there appears to be a bug in the m4 configuration. I am on it.

comment:14 Changed 8 years ago by chak

Status: newmerge
commit 82b8576c040e2d8fa5f524624478ac0effe18753
Author: Manuel M T Chakravarty <chak@cse.unsw.edu.au>
Date:   Fri Aug 5 00:17:14 2011 +1000

   This should finally fix #5293 by fixing two bugs in GMP's configuration setup

   * GMP uses m4 scripts to pre-process hand coded assembly routines
   * These didn't properly account for OS X/i86_64 always using PIC

comment:15 Changed 8 years ago by igloo

Status: mergenew

I've reinstated the workaround on the 7.2 branch.

Manuel, have you sent your patch to the GMP developers? If not, could you do so please?

comment:16 Changed 8 years ago by igloo

Owner: set to chak

comment:17 in reply to:  15 ; Changed 8 years ago by chak

Replying to igloo:

I've reinstated the workaround on the 7.2 branch.

To be able to cope with pre-installed GMPs? Even if you leave the linker option in, I would suggest to merge commit 82b8576c040e2d8fa5f524624478ac0effe18753 (to integer-gmp) in 7.2. Then, people can at least generate PIC if they want to.

Personally, I would even omit the linker option and have people with a broken, pre-installed GMP get the warnings. They are only warnings and don't break the install and they are there for a good reason (i.e., they are accurate warnings).

Manuel, have you sent your patch to the GMP developers? If not, could you do so please?

I just sent it.

comment:18 in reply to:  17 Changed 8 years ago by igloo

Resolution: fixed
Status: newclosed

Replying to chak:

Replying to igloo:

I've reinstated the workaround on the 7.2 branch.

To be able to cope with pre-installed GMPs?

Because it seemed like the safest change at this stage of the release process.

Manuel, have you sent your patch to the GMP developers? If not, could you do so please?

I just sent it.

Great, thanks. For future reference: "Broken PIC support in OS X" http://gmplib.org/list-archives/gmp-bugs/2011-August/002316.html

Note: See TracTickets for help on using tickets.