From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from de-smtp-delivery-103.mimecast.com (de-smtp-delivery-103.mimecast.com [51.163.158.103]) by sourceware.org (Postfix) with ESMTP id 5AE523850404 for ; Tue, 24 Nov 2020 19:02:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5AE523850404 Received: from vistrexch1.vi.vector.int (vistrannat0.vector-informatik.com [217.89.139.174]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-7-9JN-IKAEPdCp9hiI-nI_1w-1; Tue, 24 Nov 2020 20:02:46 +0100 X-MC-Unique: 9JN-IKAEPdCp9hiI-nI_1w-1 From: "Kacvinsky, Tom" To: "gcc-help@gcc.gnu.org" Subject: Anonymous namespaces and global vs.local symbols in nm output Thread-Topic: Anonymous namespaces and global vs.local symbols in nm output Thread-Index: AdbClGLvPJUBieRwSXKKVOFfeG0Sjg== Date: Tue, 24 Nov 2020 19:02:45 +0000 Message-ID: <60df078038824a71bd34e65773e770b8@vector.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.1.243.140] x-g-data-mailsecurity-for-exchange-state: 0 x-g-data-mailsecurity-for-exchange-error: 0 x-g-data-mailsecurity-for-exchange-sender: 23 x-g-data-mailsecurity-for-exchange-server: fd11e558-21db-41f5-81f0-adbe955f7b0d MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: vector.com Content-Language: en-US X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HTML_MESSAGE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Nov 2020 19:02:51 -0000 This code #include #include #include #include typedef std::vector Signature; namespace foo { bool bar (const std::string& input, const Signature& signature, std::istream& key) { return true; } } when compiled with g++ -fPIC -o global_noans.so -shared -static-libgcc -static-libstdc++ -Wl,-= h,global.so -fuse-ld=3Dgold global_noans.cpp produces this nm output 0000000000082745 T _ZN3foo3barERKNSt7__cxx1112basic_stringIcSt11char_traits= IcESaIcEEERKSt6vectorIhSaIhEERSi Notice how it is a global symbol? On the other hand, this code#include #include #include #include typedef std::vector Signature; namespace foo { namespace { bool bar(const std::string& input, const Signature& signature, std::istream& key) { return true; } } } when compiled with g++ -fPIC -o global.so -shared -static-libgcc -static-libstdc++ -Wl,-h,glob= al.so -fuse-ld=3Dgold global.cpp produces this nm output 00000000000826b5 t _ZN3foo12_GLOBAL__N_13barERKNSt7__cxx1112basic_stringIcS= t11char_traitsIcESaIcEEERKSt6vectorIhSaIhEERSi And now we note the symbolis local. I tried building the shared library wi= th a -Wl,--version-script=3Dglobal.map, where global.map is set up to make the symbol glocal instead of local, and that did not work= . I also tried compiling the source code with void __attribute__ ((visibility ("default"))) but that made no difference, either, in the anonymous namespace symbol bein= g lobal. I have pinged the binutils list and they said this might be a g++ version issue (I am using GCC 8.3.0 with binutils 2.34,= gold linker). If this is a g++ issues, I am assuming the issue is anonymous name spaces make the symbol local, but if that isn't the cause= , I'll got back to the binutils folks. I am also going to try a later version of GCC and binutils. Thanks, TOm