From owner-freebsd-current@FreeBSD.ORG Wed Aug 21 19:49:17 2013 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 5DFCC343; Wed, 21 Aug 2013 19:49:17 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (tensor.andric.com [87.251.56.140]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E6E8025F2; Wed, 21 Aug 2013 19:49:16 +0000 (UTC) Received: from [IPv6:2001:7b8:3a7::54c7:215e:50e:d278] (unknown [IPv6:2001:7b8:3a7:0:54c7:215e:50e:d278]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id 7465B5C43; Wed, 21 Aug 2013 21:49:14 +0200 (CEST) From: Dimitry Andric Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Problems with iconv in base and static linking Date: Wed, 21 Aug 2013 21:49:12 +0200 Message-Id: To: Mime-Version: 1.0 (Mac OS X Mail 6.5 \(1508\)) X-Mailer: Apple Mail (2.1508) Cc: Baptiste Daroussin , Bryan Drewery X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Aug 2013 19:49:17 -0000 Hi, While packaging my just-rebuilt ports today, I noticed a strange message occurring during the package creation stage: $ sudo make -C /usr/ports/ports-mgmt/pkg repackage ===> Building package for pkg-1.1.4_1 Creating package for pkg-1.1.4_1 Service unavailable$ In fact, *every* make package/repackage produces the "Service unavailable" message. The message is actually produced by the pkg(8) command, which is run as follows: /usr/local/sbin/pkg-static create -o /usr/ports/packages pkg-1.1.4_1 Now comes the interesting part: if you use /usr/local/sbin/pkg instead, the "Service unavailable" message does *not* appear. It turns out this is because pkg(8) uses libarchive, which is now compiled with iconv support from base by default. But the iconv in base does *not* work properly in statically linked executables. For example, take this small program: #include #include 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; } If you compile and link this statically, it will produce: $ cc -static iconv-test.c -o iconv-test-static $ ./iconv-test-static iconv-test-static: iconv_open failed: Invalid argument Service unavailable$ The reason for the message is that libc's iconv tries to dlopen(3) a dynamic library in /usr/lib/i18n, which does not work in static executables. As a quick fix for pkg(8), we could build the static version of libarchive without -DHAVE_ICONV and friends. This also helps other consumers of libarchive that link statically. Of course, there may be other consumers of libc's iconv that might want to link statically, so it should really be fixed there instead. For example, by not doing the dlopen, and failing gracefully. Or maybe by actually linking in (a subset of) the /usr/lib/i18n libraries. -Dimitry