Bug 196567 - iconv() function crashes with cryptic error message if linked statically
Summary: iconv() function crashes with cryptic error message if linked statically
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 10.1-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-06 18:13 UTC by devnull
Modified: 2023-06-05 01:16 UTC (History)
1 user (show)

See Also:


Attachments
add bug information to iconv manpage (94 bytes, patch)
2015-09-26 11:12 UTC, satanist+freebsd
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description devnull freebsd_committer freebsd_triage 2015-01-06 18:13:15 UTC
Hi everyone,

I’ve been trying to link a program statically that calls the iconv(3) function and was confronted with it printing the rather cryptic message "Service unavailable" and immediately exiting the program. After some websearch, I found this thread on the freebsd-current mailinglist:

* https://docs.freebsd.org/cgi/getmsg.cgi?fetch=140017+0+archive/2013/freebsd-current/20130825.freebsd-current
* https://docs.freebsd.org/cgi/getmsg.cgi?fetch=177755+0+archive/2013/freebsd-current/20130825.freebsd-current
* https://docs.freebsd.org/cgi/getmsg.cgi?fetch=195390+0+archive/2013/freebsd-current/20130825.freebsd-current

It appears nothing has happened since that thread, so I add it to the tracker now so it won’t get forgotten and because I just experienced that issue as well.

Here’s the minimal example program from that ML thread to reproduce the crash:

~~~~~~~~~~~~~~~~~~~~~~
int main(void)
{
        iconv_t ic = iconv_open("UTF-8", "ISO-8859-1");
        if (ic == (iconv_t)-1)
                err(1, "iconv_open failed");
        iconv_close(ic);
        return 0;
}
~~~~~~~~~~~~~~~~~~~~~~

Save in `foo.c` and compile like this:

~~~~~~~~~~~~~~~~~~~~~~
$ cc -static foo.c -o foo
~~~~~~~~~~~~~~~~~~~~~~

Then run:

~~~~~~~~~~~~~~~~~~~~~~
$ ./foo
foo: iconv_open failed: Invalid argument
Service unavailable
~~~~~~~~~~~~~~~~~~~~~~

I can confirm this behaviour stil exists in FreeBSD 10.1-RELEASE. The above example program still "works" (i.e. fails and demonstrates the problem).

Expected behaviour is to print a useful and understandable error message if it really isn’t possible to get iconv() to work in a statically linked program.

Greetings,
Marvin
Comment 1 satanist+freebsd 2015-09-26 11:12:34 UTC
Created attachment 161413 [details]
add bug information to iconv manpage
Comment 2 satanist+freebsd 2015-09-26 11:18:37 UTC
Is somebody on this bug? It's annoying to debug.

Some workaround ideas:
1) let linking fail
2) don't write to stdout, some programms use this to communicate.
3) make the error message less cryptic. for example "dynamic linking Service unavailable"
4) add information to the manpage