Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 311361

Summary: dev-lang/ghc-6.12.1 doesn't handle ldscripts
Product: Gentoo Linux Reporter: Maciej Piechotka <uzytkownik2>
Component: Current packagesAssignee: Gentoo's Haskell Language team <haskell>
Status: RESOLVED FIXED    
Severity: normal CC: howard_b_golden
Priority: High    
Version: unspecified   
Hardware: All   
OS: Linux   
URL: http://hackage.haskell.org/trac/ghc/ticket/4049
Whiteboard:
Package list:
Runtime testing required: ---
Bug Depends on: 290974    
Bug Blocks:    

Description Maciej Piechotka 2010-03-25 23:05:14 UTC
Described also on http://bugs.gentoo.org/4411

% ghci -package zlib
GHCi, version 6.12.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package bytestring-0.9.1.5 ... linking ... done.
Loading package zlib-0.5.2.0 ... <command line>: can't load .so/.DLL for: z (/usr/lib64/libz.so: invalid ELF header)

Linking script can be replaces by symlink (at least on newer gcc):

% cat test.c
#include <zlib.h>

int main() {
	z_stream str;
	deflateInit(&str, 6);
}
% sudo ln -s libz.so.1 /lib/libz.so
% sudo mv /usr/lib64/libz.* /root
% ls -l /usr/lib/libz.so
ls: cannot access /usr/lib/libz.so: No such file or directory
% gcc test.c -lz
% ldd a.out 
	linux-vdso.so.1 =>  (0x00007fff5f3e1000)
	libz.so.1 => /lib/libz.so.1 (0x00007fc46d39f000)
	libc.so.6 => /lib/libc.so.6 (0x00007fc46d046000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fc46d5b7000)


Reproducible: Always
Comment 1 Maciej Piechotka 2010-03-25 23:05:56 UTC
Ups. Sorry:
% gcc -v
Using built-in specs.
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/paludis/sys-devel-gcc-4.4.3/work/gcc-4.4.3/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.4.3 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.3 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.3/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.4.3/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --with-ppl --with-cloog --enable-nls --without-included-gettext --with-system-zlib --disable-checking --disable-werror --enable-secureplt --enable-multilib --enable-libmudflap --disable-libssp --enable-libgomp --enable-cld --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.4.3/python --disable-libgcj --enable-objc-gc --enable-languages=c,c++,objc,obj-c++,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.4.3 p1.0'
Thread model: posix
gcc version 4.4.3 (Gentoo 4.4.3 p1.0)
Comment 2 Maciej Piechotka 2010-03-25 23:08:28 UTC
Ups. Sorry gcc does not solves problem. However moving libz.a to /lib does.
Comment 3 Ivan 2010-03-25 23:14:23 UTC
See also bug 290974
Comment 4 SpanKY gentoo-dev 2010-03-26 02:32:58 UTC
it'll fail on plenty of libraries
Comment 5 Ivan 2010-03-26 02:37:22 UTC
(In reply to comment #4)
> it'll fail on plenty of libraries
> 

Due to the problems I've mentioned in bug 290974.  This occurs with all versions of GHC (though there is a patch in the works to try and brute-force attempting to read linker scripts), though the zlib library is the main C library that does this that people are likely to use.
Comment 6 Maciej Piechotka 2010-05-05 16:58:08 UTC
Posted upstream.
Comment 7 Ivan 2010-05-06 00:28:33 UTC
(In reply to comment #6)
> Posted upstream.
> 

Bug ticket (for tracking purposes, etc.)?
Comment 8 Maciej Piechotka 2010-05-06 08:03:10 UTC
(In reply to comment #7)
> (In reply to comment #6)
> > Posted upstream.
> > 
> 
> Bug ticket (for tracking purposes, etc.)?
> 

In URL: http://hackage.haskell.org/trac/ghc/ticket/4049
Comment 9 Howard B. Golden 2010-07-01 00:05:04 UTC
(In reply to comment #0)

> % ghci -package zlib
> GHCi, version 6.12.1: http://www.haskell.org/ghc/  :? for help
> Loading package ghc-prim ... linking ... done.
> Loading package integer-gmp ... linking ... done.
> Loading package base ... linking ... done.
> Loading package bytestring-0.9.1.5 ... linking ... done.
> Loading package zlib-0.5.2.0 ... <command line>: can't load .so/.DLL for: z
> (/usr/lib64/libz.so: invalid ELF header)

On my system, I got the same results. However, I believe that your system and my system might be misconfigured.

Please run the following command and observe the result:

$ ls -l /lib64/libz*

My result is as follows:

lrwxrwxrwx 1 root root    13 Apr  5  2008 /lib64/libz.so -> libz.so.1.2.3
lrwxrwxrwx 1 root root    13 May 14 00:26 /lib64/libz.so.1 -> libz.so.1.2.5
-rwxr-xr-x 1 root root 92760 May 14 00:26 /lib64/libz.so.1.2.5

Please note that /lib64/libz.so is linked to the _nonexistent_ file libz.so.1.2.3. If you have a similar situation, it would explain the results you got above. You should change the symbolic link to point to the correct version of /lib64/libz.so (in my case, 1.2.5). This should give you correct results (not the "invalid ELF header") with ONLY "ghci -package zlib" (or the equivalent command "ghci -lz").

This fix for this problem is included in ghc-6.14.1, which is scheduled for "Octoberish" according to Ian Lynagh.
Comment 10 Howard B. Golden 2010-07-01 00:10:42 UTC
(In reply to comment #8)

> In URL: http://hackage.haskell.org/trac/ghc/ticket/4049

Trac ticket 4049 has been split into two parts. The problem reported here was already reported as Trac ticket 2615.

http://hackage.haskell.org/trac/ghc/ticket/2615

The fix has been accepted and will be in ghc-6.14.1.
Comment 11 Sergei Trofimovich (RETIRED) gentoo-dev 2011-05-22 08:36:35 UTC
Pushed to the tree as:

*ghc-6.12.3-r1 (27 Mar 2011)

  27 Mar 2011; Sergei Trofimovich <slyfox@gentoo.org> +ghc-6.12.3-r1.ebuild,
  +files/ghc-6.12.3-ticket-2615-linker-script.patch:
  Migrated to EAPI=3: initial PREFIX support (based on work of grobian);
  USE=unicode for ncurses is a required depend (bug #326237 by Josh
  Cartwright and others). Added linker script support to workaround bug
  #311361 by Maciej Piechotka.

Thanks to Maciej for the report and to Howard for the fix in upstream!