From patchwork Sun Sep 19 08:21:36 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Wildenhues X-Patchwork-Id: 65150 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]) by ozlabs.org (Postfix) with SMTP id E97B1B70AB for ; Sun, 19 Sep 2010 18:21:51 +1000 (EST) Received: (qmail 5495 invoked by alias); 19 Sep 2010 08:21:46 -0000 Received: (qmail 5476 invoked by uid 22791); 19 Sep 2010 08:21:44 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mailout-de.gmx.net (HELO mail.gmx.net) (213.165.64.22) by sourceware.org (qpsmtpd/0.43rc1) with SMTP; Sun, 19 Sep 2010 08:21:40 +0000 Received: (qmail invoked by alias); 19 Sep 2010 08:21:37 -0000 Received: from xdsl-89-0-68-71.netcologne.de (EHLO localhost.localdomain) [89.0.68.71] by mail.gmx.net (mp068) with SMTP; 19 Sep 2010 10:21:37 +0200 Received: from ralf by localhost.localdomain with local (Exim 4.69) (envelope-from ) id 1OxF9U-0001Ub-WD; Sun, 19 Sep 2010 10:21:37 +0200 Date: Sun, 19 Sep 2010 10:21:36 +0200 From: Ralf Wildenhues To: Paolo Carlini , gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org Subject: [PATCH v3 headers] variable uglification Message-ID: <20100919082136.GE5435@gmx.de> Mail-Followup-To: Ralf Wildenhues , Paolo Carlini , gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2010-08-04) X-IsSubscribed: yes 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 Hi Paolo, all, I noticed that C++ header uglification seems to be a slow manual process. That looks suboptimal, and shouldn't be the case, it should be mostly automatic and quick (in terms of developer time). My first idea was to just hunt the headers for suspicious words (avoiding the use of the preprocessor to catch all possible code): cd libstdc++-v3 set x `find include \( -name \*.cc -o -name \*.am -o -name \*.in \) \ -prune -o -type f -print` shift perl -e ' my %words; undef $/; # slurp whole file at once, for multiline match while (<>) { s/\/\/[^\n]*//g; # good enough for C++ comments s/\/\*.*?\*\///gs; # good enough for C comments foreach my $word (split /\b/) { $words{$word}++ if $word =~ m/^[a-zA-Z][a-zA-Z0-9_]*$/; # ignore _words } } foreach my $word (keys %words) { print "$words{$word}\t$word\n"; }' "$@" | sort -k1n | less which already shows lots of potential issues below ext/, but also false positives from preprocessor statements, string literals, arithmetic constant prefixes and suffixes. Also, I still have to generate a list of keywords and C++ API words to exclude, but glancing over them is fairly easy. My next idea would be to instantiate as much code as possible and extract debugging symbols, maybe that can be an easy second attack vector. Another idea would be a testsuite addition poisoning one- and two-character identifiers not part of the API? Might be too dangerous in the presence of broken system headers. Who designed C++ classes inside with multiple one-character member names in the API by the way? Anyway, I found a couple of instances with the above approach, patch below survived bootstrap and regtest on x86_64-unknown-linux-gnu. OK? Thanks, Ralf Uglify C++ headers some more. libstdc++-v3/ChangeLog: 2010-09-19 Ralf Wildenhues * include/ext/throw_allocator.h (hash<__gnu_cxx::throw_value_limit>::operator()): Uglify local. (hash<__gnu_cxx::throw_value_random>::operator()): Likewise. * include/parallel/set_operations.h (__symmetric_difference_func): Uglify remaining arguments to __count, __first_empty, _M_invoke. (__difference_func): Likewise for __count. * include/profile/impl/profiler_node.h (__object_info_base::__write): Uglify parameter. diff --git a/libstdc++-v3/include/ext/throw_allocator.h b/libstdc++-v3/include/ext/throw_allocator.h index 669d433..cc34478 100644 --- a/libstdc++-v3/include/ext/throw_allocator.h +++ b/libstdc++-v3/include/ext/throw_allocator.h @@ -737,8 +737,8 @@ namespace std size_t operator()(const __gnu_cxx::throw_value_limit& __val) const { - std::hash h; - size_t __result = h(__val._M_i); + std::hash __h; + size_t __result = __h(__val._M_i); return __result; } }; @@ -751,8 +751,8 @@ namespace std size_t operator()(const __gnu_cxx::throw_value_random& __val) const { - std::hash h; - size_t __result = h(__val._M_i); + std::hash __h; + size_t __result = __h(__val._M_i); return __result; } }; diff --git a/libstdc++-v3/include/parallel/set_operations.h b/libstdc++-v3/include/parallel/set_operations.h index f6b076f..f552c1d 100644 --- a/libstdc++-v3/include/parallel/set_operations.h +++ b/libstdc++-v3/include/parallel/set_operations.h @@ -103,11 +103,11 @@ namespace __gnu_parallel } _DifferenceType - __count(_IIter __a, _IIter __b, _IIter __c, _IIter d) const + __count(_IIter __a, _IIter __b, _IIter __c, _IIter __d) const { _DifferenceType __counter = 0; - while (__a != __b && __c != d) + while (__a != __b && __c != __d) { if (_M_comp(*__a, *__c)) { @@ -126,12 +126,12 @@ namespace __gnu_parallel } } - return __counter + (__b - __a) + (d - __c); + return __counter + (__b - __a) + (__d - __c); } _OutputIterator - __first_empty(_IIter __c, _IIter d, _OutputIterator __out) const - { return std::copy(__c, d, __out); } + __first_empty(_IIter __c, _IIter __d, _OutputIterator __out) const + { return std::copy(__c, __d, __out); } _OutputIterator __second_empty(_IIter __a, _IIter __b, _OutputIterator __out) const @@ -153,10 +153,10 @@ namespace __gnu_parallel _Compare _M_comp; _OutputIterator - _M_invoke(_IIter __a, _IIter __b, _IIter __c, _IIter d, + _M_invoke(_IIter __a, _IIter __b, _IIter __c, _IIter __d, _OutputIterator __r) const { - while (__a != __b && __c != d) + while (__a != __b && __c != __d) { if (_M_comp(*__a, *__c)) { @@ -177,11 +177,11 @@ namespace __gnu_parallel _DifferenceType __count(_IIter __a, _IIter __b, - _IIter __c, _IIter d) const + _IIter __c, _IIter __d) const { _DifferenceType __counter = 0; - while (__a != __b && __c != d) + while (__a != __b && __c != __d) { if (_M_comp(*__a, *__c)) { diff --git a/libstdc++-v3/include/profile/impl/profiler_node.h b/libstdc++-v3/include/profile/impl/profiler_node.h index d22a3e1..86f541f 100644 --- a/libstdc++-v3/include/profile/impl/profiler_node.h +++ b/libstdc++-v3/include/profile/impl/profiler_node.h @@ -148,7 +148,7 @@ namespace __gnu_profile __stack() const { return _M_stack; } - virtual void __write(FILE* f) const = 0; + virtual void __write(FILE* __f) const = 0; protected: __stack_t _M_stack;