From patchwork Fri Aug 21 21:11:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 509646 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 96EC11401EF for ; Sat, 22 Aug 2015 07:12:06 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=afPwMLys; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=K5+Av/+03iVFhxLv3 3HAt18yPt3+uZojej3ul30rIKCcUoQj0oor3ESA+bokuYlpmKGGlk3A78wF+s8CU xX/SlD3WYVZ0h82GygDJcFolrq0Y+4d+1KooBMU3GeZ/RDqkaaUYZazYMX6wPxet IX4QR/XsjAr5h4lEe6CBx1EmXo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=1lk2QGO8Z+Y/fLs61RlRrIf Fu50=; b=afPwMLysA4PoqbbWWvKR5LYRgbzsw2nm3tRa15DFWHb871NzGnxKNkj JjdQYJKXla+gABrVn93KR35qiZOwF5g/WepRCdLFRFKonRRya+kDTLNzcj539Q/0 SFdW2GEXzwq1BupqS/3FZC0CO749kXfC/Amni91kGRMcNK2ttmQE= Received: (qmail 82892 invoked by alias); 21 Aug 2015 21:11:58 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 82867 invoked by uid 89); 21 Aug 2015 21:11:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_40, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-wi0-f181.google.com Received: from mail-wi0-f181.google.com (HELO mail-wi0-f181.google.com) (209.85.212.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 21 Aug 2015 21:11:54 +0000 Received: by widdq5 with SMTP id dq5so1814276wid.1; Fri, 21 Aug 2015 14:11:51 -0700 (PDT) X-Received: by 10.180.107.1 with SMTP id gy1mr6445140wib.16.1440191511137; Fri, 21 Aug 2015 14:11:51 -0700 (PDT) Received: from [192.168.0.22] (arf62-1-82-237-250-248.fbx.proxad.net. [82.237.250.248]) by smtp.googlemail.com with ESMTPSA id b13sm4497775wic.15.2015.08.21.14.11.49 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Aug 2015 14:11:50 -0700 (PDT) Message-ID: <55D79415.90600@gmail.com> Date: Fri, 21 Aug 2015 23:11:49 +0200 From: =?windows-1252?Q?Fran=E7ois_Dumont?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: Jonathan Wakely CC: "libstdc++@gcc.gnu.org" , gcc-patches Subject: Re: Elimitate duplication of get_catalogs in different abi References: <55B694F5.3070606@gmail.com> <55BA81B1.9030206@gmail.com> <20150805205744.GC13355@redhat.com> In-Reply-To: <20150805205744.GC13355@redhat.com> On 05/08/2015 22:57, Jonathan Wakely wrote: > On 30/07/15 21:57 +0200, François Dumont wrote: >> It seems that this patch results in unresolved symbols. >> >> I am quite sure that the code is right but build system should be >> adapted. >> >> I noticed that *_cow.cc files are built with -fimplicit-templates. I try >> to apply the same with the old abi but I still experiment unresolved >> symbols. >> >> Any help is welcome. > > OK, I'll look into it next week, when I'm back from the GNU Cauldron. > > I think I found a better way to handle this problem. It is c++locale.cc that needs to be built with --fimplicit-templates. I even think that the *_cow.cc file do not need this option but as I don't know what is the drawback of this option I kept it. I also explicitely used the file name c++locale.cc even if it is an alias to a configurable source file. I guess there must be some variable to use no ? With this patch there are 6 additional symbols. I guess I need to declare those in the scripts even if it is for internal library usage, right ? François diff --git libstdc++-v3/config/locale/gnu/c++locale_internal.h libstdc++-v3/config/locale/gnu/c++locale_internal.h index f1959d6..eeac620 100644 --- libstdc++-v3/config/locale/gnu/c++locale_internal.h +++ libstdc++-v3/config/locale/gnu/c++locale_internal.h @@ -36,8 +36,13 @@ #include #include +#include +#include // ::strdup + +#include + #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) - + extern "C" __typeof(nl_langinfo_l) __nl_langinfo_l; extern "C" __typeof(strcoll_l) __strcoll_l; extern "C" __typeof(strftime_l) __strftime_l; @@ -61,3 +66,49 @@ extern "C" __typeof(wctype_l) __wctype_l; #endif #endif // GLIBC 2.3 and later + +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + struct Catalog_info + { + Catalog_info(messages_base::catalog __id, const char* __domain, + locale __loc) + : _M_id(__id), _M_domain(strdup(__domain)), _M_locale(__loc) + { } + + ~Catalog_info() + { free(_M_domain); } + + messages_base::catalog _M_id; + char* _M_domain; + locale _M_locale; + }; + + class Catalogs + { + public: + Catalogs() : _M_catalog_counter(0) { } + ~Catalogs(); + + messages_base::catalog + _M_add(const char* __domain, locale __l); + + void + _M_erase(messages_base::catalog __c); + + const Catalog_info* + _M_get(messages_base::catalog __c) const; + + private: + mutable __gnu_cxx::__mutex _M_mutex; + messages_base::catalog _M_catalog_counter; + vector _M_infos; + }; + + Catalogs& + get_catalogs(); + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace diff --git libstdc++-v3/config/locale/gnu/c_locale.cc libstdc++-v3/config/locale/gnu/c_locale.cc index 4612c64..708af0e 100644 --- libstdc++-v3/config/locale/gnu/c_locale.cc +++ libstdc++-v3/config/locale/gnu/c_locale.cc @@ -31,9 +31,12 @@ #include #include #include +#include #include #include +#include + namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION @@ -170,6 +173,85 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __changed; } + struct _CatalogIdComp + { + bool + operator()(messages_base::catalog __cat, const Catalog_info* __info) const + { return __cat < __info->_M_id; } + + bool + operator()(const Catalog_info* __info, messages_base::catalog __cat) const + { return __info->_M_id < __cat; } + }; + + Catalogs::~Catalogs() + { + for (vector::iterator __it = _M_infos.begin(); + __it != _M_infos.end(); ++__it) + delete *__it; + } + + messages_base::catalog + Catalogs::_M_add(const char* __domain, locale __l) + { + __gnu_cxx::__scoped_lock lock(_M_mutex); + + // The counter is not likely to roll unless catalogs keep on being + // opened/closed which is consider as an application mistake for the + // moment. + if (_M_catalog_counter == numeric_limits::max()) + return -1; + + auto_ptr info(new Catalog_info(_M_catalog_counter++, + __domain, __l)); + + // Check if we managed to allocate memory for domain. + if (!info->_M_domain) + return -1; + + _M_infos.push_back(info.get()); + return info.release()->_M_id; + } + + void + Catalogs::_M_erase(messages_base::catalog __c) + { + __gnu_cxx::__scoped_lock lock(_M_mutex); + + vector::iterator __res = + lower_bound(_M_infos.begin(), _M_infos.end(), __c, _CatalogIdComp()); + if (__res == _M_infos.end() || (*__res)->_M_id != __c) + return; + + delete *__res; + _M_infos.erase(__res); + + // Just in case closed catalog was the last open. + if (__c == _M_catalog_counter - 1) + --_M_catalog_counter; + } + + const Catalog_info* + Catalogs::_M_get(messages_base::catalog __c) const + { + __gnu_cxx::__scoped_lock lock(_M_mutex); + + vector::const_iterator __res = + lower_bound(_M_infos.begin(), _M_infos.end(), __c, _CatalogIdComp()); + + if (__res != _M_infos.end() && (*__res)->_M_id == __c) + return *__res; + + return 0; + } + + Catalogs& + get_catalogs() + { + static Catalogs __catalogs; + return __catalogs; + } + _GLIBCXX_END_NAMESPACE_VERSION } // namespace @@ -211,3 +293,4 @@ _GLIBCXX_END_NAMESPACE_VERSION extern "C" void ldbl (void) __attribute__ ((alias (#dbl))) _GLIBCXX_LDBL_COMPAT(_ZSt14__convert_to_vIdEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct, _ZSt14__convert_to_vIeEvPKcRT_RSt12_Ios_IostateRKP15__locale_struct); #endif // _GLIBCXX_LONG_DOUBLE_COMPAT + diff --git libstdc++-v3/config/locale/gnu/messages_members.cc libstdc++-v3/config/locale/gnu/messages_members.cc index 2e6122d..90f4b8d 100644 --- libstdc++-v3/config/locale/gnu/messages_members.cc +++ libstdc++-v3/config/locale/gnu/messages_members.cc @@ -31,115 +31,13 @@ #include #include -#include -#include -#include #include // std::free #include // ::strdup -#include -#include - namespace { using namespace std; - typedef messages_base::catalog catalog; - - struct Catalog_info - { - Catalog_info(catalog __id, const string& __domain, locale __loc) - : _M_id(__id), _M_domain(__domain), _M_locale(__loc) - { } - - catalog _M_id; - string _M_domain; - locale _M_locale; - }; - - class Catalogs - { - public: - Catalogs() : _M_catalog_counter(0) { } - - ~Catalogs() - { - for (vector::iterator __it = _M_infos.begin(); - __it != _M_infos.end(); ++__it) - delete *__it; - } - - catalog - _M_add(const string& __domain, locale __l) - { - __gnu_cxx::__scoped_lock lock(_M_mutex); - - // The counter is not likely to roll unless catalogs keep on being - // opened/closed which is consider as an application mistake for the - // moment. - if (_M_catalog_counter == numeric_limits::max()) - return -1; - - std::auto_ptr info(new Catalog_info(_M_catalog_counter++, - __domain, __l)); - _M_infos.push_back(info.get()); - return info.release()->_M_id; - } - - void - _M_erase(catalog __c) - { - __gnu_cxx::__scoped_lock lock(_M_mutex); - - vector::iterator __res = - lower_bound(_M_infos.begin(), _M_infos.end(), __c, _Comp()); - if (__res == _M_infos.end() || (*__res)->_M_id != __c) - return; - - delete *__res; - _M_infos.erase(__res); - - // Just in case closed catalog was the last open. - if (__c == _M_catalog_counter - 1) - --_M_catalog_counter; - } - - const Catalog_info* - _M_get(catalog __c) const - { - __gnu_cxx::__scoped_lock lock(_M_mutex); - - vector::const_iterator __res = - lower_bound(_M_infos.begin(), _M_infos.end(), __c, _Comp()); - - if (__res != _M_infos.end() && (*__res)->_M_id == __c) - return *__res; - - return 0; - } - - private: - struct _Comp - { - bool operator()(catalog __cat, const Catalog_info* __info) const - { return __cat < __info->_M_id; } - - bool operator()(const Catalog_info* __info, catalog __cat) const - { return __info->_M_id < __cat; } - }; - - mutable __gnu_cxx::__mutex _M_mutex; - catalog _M_catalog_counter; - std::vector _M_infos; - }; - - Catalogs& - get_catalogs() - { - static Catalogs __catalogs; - return __catalogs; - } - const char* get_glibc_msg(__c_locale __locale_messages __attribute__((unused)), const char* __name_messages __attribute__((unused)), @@ -180,7 +78,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bind_textdomain_codeset(__s.c_str(), __nl_langinfo_l(CODESET, __codecvt._M_c_locale_codecvt)); - return get_catalogs()._M_add(__s, __l); + return get_catalogs()._M_add(__s.c_str(), __l); } template<> @@ -202,7 +100,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __dfault; return get_glibc_msg(_M_c_locale_messages, _M_name_messages, - __cat_info->_M_domain.c_str(), + __cat_info->_M_domain, __dfault.c_str()); } @@ -218,7 +116,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bind_textdomain_codeset(__s.c_str(), __nl_langinfo_l(CODESET, __codecvt._M_c_locale_codecvt)); - return get_catalogs()._M_add(__s, __l); + return get_catalogs()._M_add(__s.c_str(), __l); } template<> @@ -248,7 +146,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __builtin_memset(&__state, 0, sizeof(mbstate_t)); { const wchar_t* __wdfault_next; - size_t __mb_size = __wdfault.size() * __conv.max_length();; + size_t __mb_size = __wdfault.size() * __conv.max_length(); char* __dfault = static_cast(__builtin_alloca(sizeof(char) * (__mb_size + 1))); char* __dfault_next; @@ -260,7 +158,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Make sure string passed to dgettext is \0 terminated. *__dfault_next = '\0'; __translation = get_glibc_msg(_M_c_locale_messages, _M_name_messages, - __cat_info->_M_domain.c_str(), __dfault); + __cat_info->_M_domain, __dfault); // If we end up getting default value back we can simply return original // default value. diff --git libstdc++-v3/src/c++98/Makefile.am libstdc++-v3/src/c++98/Makefile.am index a5b68a1..c5a8866 100644 --- libstdc++-v3/src/c++98/Makefile.am +++ libstdc++-v3/src/c++98/Makefile.am @@ -155,6 +155,12 @@ vpath % $(top_srcdir)/src/c++98 libc__98convenience_la_SOURCES = $(sources) +# Use special rules to compile with -fimplicit-templates. +c++locale.lo: c++locale.cc + $(LTCXXCOMPILE) -fimplicit-templates -c $< +c++locale.o: c++locale.cc + $(CXXCOMPILE) -fimplicit-templates -c $< + if ENABLE_DUAL_ABI GLIBCXX_ABI_FLAGS = -D_GLIBCXX_USE_CXX11_ABI=@glibcxx_cxx98_abi@ # Use special rules to compile with the non-default string ABI. diff --git libstdc++-v3/src/c++98/Makefile.in libstdc++-v3/src/c++98/Makefile.in index b1a1b49..3c3bbbd 100644 --- libstdc++-v3/src/c++98/Makefile.in +++ libstdc++-v3/src/c++98/Makefile.in @@ -776,6 +776,12 @@ basic_file.cc: ${glibcxx_srcdir}/$(BASIC_FILE_CC) $(LN_S) ${glibcxx_srcdir}/$(BASIC_FILE_CC) ./$@ || true vpath % $(top_srcdir)/src/c++98 + +# Use special rules to compile with -fimplicit-templates. +c++locale.lo: c++locale.cc + $(LTCXXCOMPILE) -fimplicit-templates -c $< +c++locale.o: c++locale.cc + $(CXXCOMPILE) -fimplicit-templates -c $< # Use special rules to compile with the non-default string ABI. @ENABLE_DUAL_ABI_TRUE@collate_members_cow.lo: collate_members_cow.cc @ENABLE_DUAL_ABI_TRUE@ $(LTCXXCOMPILE) $(GLIBCXX_ABI_FLAGS) -fimplicit-templates -c $<