GHC static binaries with glibc-2.12?

Alexander Dunlap alexander.dunlap at
Thu Oct 21 01:23:59 EDT 2010

On Mon, Oct 11, 2010 at 2:11 AM, Simon Marlow <marlowsd at> wrote:
> On 10/10/2010 05:22, Alexander Dunlap wrote:
>> On Fri, Oct 8, 2010 at 12:46 AM, Simon Marlow<marlowsd at>  wrote:
>>> On 08/10/2010 03:23, Alexander Dunlap wrote:
>>>> I recently upgraded my Arch Linux system to glibc 2.12 and static
>>>> binaries compiled with GHC 6.12.3 all fail with the message
>>>> "mkTextEncoding: invalid argument (Invalid argument)". This did not
>>>> happen with glibc 2.11. Has anyone else had this problem? Does anyone
>>>> have any advice for debugging it?
>>> Probably something to do with iconv.  Doesn't iconv need to load its
>>> codec
>>> modules dynamically at runtime?
>>> Cheers,
>>>        Simon
>> Yes, it does, but strace seems to show that the program is looking in
>> the right place for the iconv libraries. Is there some way to step
>> through the code of a statically-linked program? I'm not sure how to
>> proceed debugging a Haskell-originated error that only occurs with
>> static linking (so I can't use the GHCi debugger).
> The error is almost certainly being returned by iconv(), which is called via
> this wrapper in base/cbits/iconv.c:
> size_t hs_iconv(iconv_t cd,
>                const char* * inbuf, size_t * inbytesleft,
>                char* * outbuf, size_t * outbytesleft)
> {
>    // (void*) cast avoids a warning.  Some iconvs use (const
>    // char**inbuf), other use (char **inbuf).
>    return iconv(cd, (void*)inbuf, inbytesleft, outbuf, outbytesleft);
> }
> you could run the program in gdb and set a breakpoint on hs_iconv, or iconv
> itself.  Since it will be compiled without debugging information you'll have
> to poke around on the C stack yourself to find the arguments.
> Alternatively get a GHC build and instrument the code in
> libraries/base/GHC/IO/Encoding/IConv.hs to see what's going on.
> Cheers,
>        Simon

$ gdb ./main-static
GNU gdb (GDB) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu".
For bug reporting instructions, please see:
Reading symbols from /home/alex/tmp/main-static...(no debugging
symbols found)...done.
(gdb) break iconv
Breakpoint 1 at 0x80bbd66
(gdb) break hs_iconv
Breakpoint 2 at 0x8065de6
(gdb) run
Starting program: /home/alex/tmp/main-static
[Thread debugging using libthread_db enabled]
main-static: mkTextEncoding: invalid argument (Invalid argument)

Program exited with code 01.

Does this indicate that the error is occurring before iconv is even
called? Or do I have to do something else to make the breakpoint work.
(Sorry, I'm not an expert with GDB.)


More information about the Glasgow-haskell-users mailing list