Bug 36211 - __iconv_adaptor chooses char** where const char** is required
Summary: __iconv_adaptor chooses char** where const char** is required
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.4.1
Assignee: David Billinghurst
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-11 14:11 UTC by Tim Prince
Modified: 2009-05-21 11:35 UTC (History)
3 users (show)

See Also:
Host: i686-pc-cygwin
Target: i686-pc-cygwin
Build: i686-pc-cygwin
Known to work:
Known to fail:
Last reconfirmed: 2009-05-14 21:51:26


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Prince 2008-05-11 14:11:35 UTC
libstdc++ testsuite cases which require libiconv fail on account of trying the wrong choice in __iconv_adaptor:
/cygdrive/c/gnu/gcc-4.4-20080509/xp/i686-pc-cygwin/libstdc++-v3/include/ext/code
cvt_specializations.h:302: undefined reference to `_libiconv'^M

#ifndef LIBICONV_PLUG
#define iconv libiconv
#endif
extern size_t iconv (iconv_t cd, const char* * inbuf, size_t *inbytesleft, char*
 * outbuf, size_t *outbytesleft);
Comment 1 Tim Prince 2008-05-11 15:57:43 UTC
2 unicode.cc tests fail.  Several other tests with -liconv pass.
Comment 2 Paolo Carlini 2008-05-11 17:13:19 UTC
Why, exactly, do you believe the problem is with the const? The code and the comment in codecvt_specializations.h appear to indicate that we are already dealing correctly with the issue and indeed you are reporting that other tests link fine...
Comment 3 Tim Prince 2008-05-11 17:26:47 UTC
I see that the failing case is looking for a libiconv in the library to match the char ** prototype, and failing to find one, while the one in the actual library is set up for the const char ** version.  The comment in codecvt_specializations.h indicates this should be taken care of by  __iconv_adaptor, yet the link failure shows this is not working.
I don't understand the usage well enough to know what to conclude, why some cases (do they also exercise __iconv_adaptor ?) work, while the unicode.cc cases fail to link at that point.
This problem has been brought up by others in mail lists, but as far as I know no one wrote up a PR.
Comment 4 Paolo Carlini 2008-05-11 17:31:23 UTC
Please add pointers to the discussions on those mailing lists.
Comment 5 Tim Prince 2008-05-11 18:04:56 UTC
Only the gcc-testresults reports where others report the same thing are clearly relevant:
http://gcc.gnu.org/ml/gcc-testresults/2008-03/msg01444.html
http://gcc.gnu.org/ml/gcc-testresults/2007-05/msg01528.html


In other cases, the poster did not provide sufficient information to establish conclusively it was the same problem.
It is generally not reported in testresults whether libstdc++ tests were run with libiconv installed.  If libiconv is not installed, none of these tests are attempted.
Comment 6 Paolo Carlini 2008-05-11 18:13:19 UTC
Frankly, we badly need more details and/or the help of a cygwin maintainer, because by looking statically at the code I don't see how possibly __iconv_adaptor can be wrong and most (all?) the active libstdc++ maintainers do not have a cygwin machine available.
Comment 7 Danny Smith 2008-05-11 22:46:00 UTC
Following is with mingw but it applies to cygwin as well 

This is the command line from log for FAILing 22_locale/locale/cons/unicode.cc

Executing on host: /develop/svn/trunk/build/./gcc/g++ -shared-libgcc -B/develop/svn/trunk/build/./gcc -nostdinc++ -L/develop/svn/trunk/build/mingw32/libstdc++-v3/src -L/develop/svn/trunk/build/mingw32/libstdc++-v3/src/.libs -L/develop/svn/trunk/build/mingw32/winsup/mingw -L/develop/svn/trunk/build/mingw32/winsup/w32api/lib -isystem /develop/svn/trunk/src/winsup/mingw/include -isystem /develop/svn/trunk/src/winsup/w32api/include -B/mingw/mingw32/bin/ -B/mingw/mingw32/lib/ -isystem /mingw/mingw32/include -isystem /mingw/mingw32/sys-include -g -O2 -D_GLIBCXX_ASSERT -fmessage-length=0 -ffunction-sections -fdata-sections -g -O2 -g -O2   -DLOCALEDIR="." -nostdinc++ -I/develop/svn/trunk/build/mingw32/libstdc++-v3/include/mingw32 -I/develop/svn/trunk/build/mingw32/libstdc++-v3/include -I/develop/svn/trunk/src/libstdc++-v3/libsupc++ -I/develop/svn/trunk/src/libstdc++-v3/include/backward -I/develop/svn/trunk/src/libstdc++-v3/testsuite/util -Wl,--gc-sections /mingw/lib/libiconv.a /develop/svn/trunk/src/libstdc++-v3/testsuite/22_locale/locale/cons/unicode.cc    -include bits/stdc++.h ./libtestc++.a  -lm   -o ./unicode.exe    (timeout = 600)


Note that although the correct libiconv "/mingw/lib/libiconv.a" is passed to linker, it is  passed  *before*  the objects and libraries that reference libiconv symbols.
With PE-COFF, the order of objects really does  matter and  since the libiconv symbols have not yet been referenced when the linker looks at the lib, the symbols are not resolved. They are not resolved lazily as is possible in ELF


Danny
Comment 8 Tim Prince 2008-05-12 01:58:23 UTC
Yes, -liconv precedes the source file, where it must follow:
Executing on host: /cygdrive/c/gnu/gcc-4.4-20080509/xp/./gcc/g++ -shared-libgcc
-B/cygdrive/c/gnu/gcc-4.4-20080509/xp/./gcc -nostdinc++ -L/cygdrive/c/gnu/gcc-4.
4-20080509/xp/i686-pc-cygwin/libstdc++-v3/src -L/cygdrive/c/gnu/gcc-4.4-20080509
/xp/i686-pc-cygwin/libstdc++-v3/src/.libs -B/usr/local/gcc44/i686-pc-cygwin/bin/
 -B/usr/local/gcc44/i686-pc-cygwin/lib/ -isystem /usr/local/gcc44/i686-pc-cygwin
/include -isystem /usr/local/gcc44/i686-pc-cygwin/sys-include -g -O2 -D_GLIBCXX_
ASSERT -fmessage-length=0 -ffunction-sections -fdata-sections -g -O2 -g -O2   -D
LOCALEDIR="." -nostdinc++ -I/cygdrive/c/gnu/gcc-4.4-20080509/xp/i686-pc-cygwin/l
ibstdc++-v3/include/i686-pc-cygwin -I/cygdrive/c/gnu/gcc-4.4-20080509/xp/i686-pc
-cygwin/libstdc++-v3/include -I/cygdrive/c/gnu/gcc-4.4-20080509/libstdc++-v3/lib
supc++ -I/cygdrive/c/gnu/gcc-4.4-20080509/libstdc++-v3/include/backward -I/cygdr
ive/c/gnu/gcc-4.4-20080509/libstdc++-v3/testsuite/util -Wl,--gc-sections -liconv
 /cygdrive/c/gnu/gcc-4.4-20080509/libstdc++-v3/testsuite/22_locale/locale/cons/u
nicode.cc    -include bits/stdc++.h ./libtestc++.a     -o ./unicode.exe    (time
Comment 9 David Billinghurst 2009-05-14 03:24:05 UTC
Draft patch http://gcc.gnu.org/ml/libstdc++/2009-05/msg00090.html
Comment 10 David Billinghurst 2009-05-14 21:51:26 UTC
Patch is approved - http://gcc.gnu.org/ml/libstdc++/2009-05/msg00098.html
Comment 11 David Billinghurst 2009-05-15 09:24:15 UTC
Subject: Bug 36211

Author: billingd
Date: Fri May 15 09:23:58 2009
New Revision: 147565

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147565
Log:
2009-05-15  David Billinghurst <billingd@gcc.gnu.org>

	PR libstdc++/36211
	* testsuite/lib/libstdc++.exp(v3_target_compile):  Add
	cxxldflags to additional_flags rather than cxx_final.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/testsuite/lib/libstdc++.exp

Comment 12 David Billinghurst 2009-05-21 11:31:10 UTC
Subject: Bug 36211

Author: billingd
Date: Thu May 21 11:30:55 2009
New Revision: 147762

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=147762
Log:
2009-05-21  David Billinghurst <billingd@gcc.gnu.org>

	Backport from mainline:
	PR libstdc++/36211
	* testsuite/lib/libstdc++.exp(v3_target_compile):  Add
	cxxldflags to additional_flags rather than cxx_final.

Modified:
    branches/gcc-4_4-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_4-branch/libstdc++-v3/testsuite/lib/libstdc++.exp

Comment 13 David Billinghurst 2009-05-21 11:32:40 UTC
Fixed in 4.4 and trunk.