From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 24B873871015 for ; Tue, 24 Nov 2020 20:03:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 24B873871015 Received: by mail-wr1-x42d.google.com with SMTP id g14so8407866wrm.13 for ; Tue, 24 Nov 2020 12:03:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=C9PTuNurrntnv4sQRMu+NeLh/zxoWoLgaP1tV2CTRlI=; b=AvKd7cm/qKH/SeVM0s+r77ylAIxXRWGE97obxecaeGnZQfuw4hH4bZhxGDbFgG4o9o JZOTiiTNYBazC8F04MZVsYcWgPlddewDKcyODvIibLlUJWPcssQcRtr1QbIa+RRBHid7 qPPYYc8piYOhvZwgzOg1wxSqxgZTKjlMa3Gm5p3+1TX9kYjjR695toRd5r7TDKVXjXlh DWLqR3Isd2dTsKCjavAG6hUBkX6BaOLX7zgenTELuJf1/uwvVs0LY/NI5cW5cLUKbZgh t4hPYrit8pAnJyRUFHt0Ga8dyWdKd8PLOBvfmqDO8ulFmNgmvmTWp1YqWY1b7cgY/VIc tvuw== X-Gm-Message-State: AOAM53210EyjGSXnhD5twipJscibzvSN1yx0Ga6d+hTih+byt06Komge W9bp/CHqmUpaJdDsY076mk2uq9TcWzDpFaR3auk= X-Google-Smtp-Source: ABdhPJxXP5R1eSv8PhMkT0Us0fyWyiXVKE0TENIhV/4MD4JrZ5vkI4DQqAU+Rz+g+eAqFFK1pLUZB8PezdQi0bnb2dg= X-Received: by 2002:adf:fe48:: with SMTP id m8mr147192wrs.89.1606248216077; Tue, 24 Nov 2020 12:03:36 -0800 (PST) MIME-Version: 1.0 References: <60df078038824a71bd34e65773e770b8@vector.com> In-Reply-To: <60df078038824a71bd34e65773e770b8@vector.com> From: Jonathan Wakely Date: Tue, 24 Nov 2020 20:03:24 +0000 Message-ID: Subject: Re: Anonymous namespaces and global vs.local symbols in nm output To: "Kacvinsky, Tom" Cc: "gcc-help@gcc.gnu.org" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, 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 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 20:03:41 -0000 On Tue, 24 Nov 2020 at 19:11, Kacvinsky, Tom via Gcc-help wrote: > > 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=gold global_noans.cpp > > produces this nm output > > 0000000000082745 T _ZN3foo3barERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIhSaIhEERSi > > 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,global.so -fuse-ld=gold global.cpp > > produces this nm output > > 00000000000826b5 t _ZN3foo12_GLOBAL__N_13barERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIhSaIhEERSi > > And now we note the symbolis local. I tried building the shared library with a -Wl,--version-script=global.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 being lobal. Why do you want to change it? G++ is doing the right thing. What are you trying to achieve?