在使用 g++ 创建的共享库中隐藏实例化模板 [英] Hiding instantiated templates in shared library created with g++

查看:16
本文介绍了在使用 g++ 创建的共享库中隐藏实例化模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下内容的文件:

#include <map>A类{};无效 doSomething() {std::map<int, A>米;}

当使用 g++ 编译成共享库时,该库包含 std::map 的所有方法的动态符号.由于 A 对该文件是私有的,因此 std::map 不可能在具有相同参数的任何其他共享库中实例化,所以我想隐藏模板实例化(出于本文档中描述的一些原因).p>

我认为我应该能够通过添加模板类的显式实例并将其标记为隐藏来做到这一点,如下所示:

#include <map>A类{};模板类 __attribute__((visibility ("hidden"))) std::map;无效 doSomething() {std::map<int, A>米;}

但是,这没有任何效果:符号仍然全部导出.我还尝试使用以下命令包围整个文件:

#pragma GCC可见性推送(隐藏)...#pragma GCC 可见性弹出

但这对 std::map<int, A> 方法的可见性也没有影响(尽管它确实隐藏了 doSomething).同样,使用 -fvisibility=hidden 编译对 std::map 的方法的可见性没有影响.

我上面链接的文档描述了使用导出地图来限制可见性,但这似乎很乏味.

有没有办法在 g++ 中做我想做的事情(除了使用导出映射)?如果是这样,它是什么?如果没有,是否有充分的理由为什么必须始终导出这些符号,或者这只是 g++ 中的一个遗漏?

解决方案

来自 GCC 错误报告 #36022,标记为 INVALID,Benjamin Kosnik 评论道:

<块引用>

[A]n 将在 DSO 之间抛出的异常类必须是用默认可见性显式标记,以便 `type_info' 节点将DSO 之间的统一.因此,libstdc++ 具有命名空间 std 的基本原理具有可见性默认."

另外,查看 std::map 的 libstdc++ 源代码(我的在 /usr/include/c++/4.4.4/bits/stl_map.h 中),看来 libstdc++ 强制默认可见性的方式是使用 _GLIBCXX_BEGIN_NESTED_NAMESPACE 宏,该宏在 stl_map.h 的顶部使用:

#define _GLIBCXX_VISIBILITY_ATTR(V) __attribute__ ((__visibility__ (#V)))# 定义 _GLIBCXX_BEGIN_NESTED_NAMESPACE(X, Y) _GLIBCXX_BEGIN_NAMESPACE(X)# 定义 _GLIBCXX_BEGIN_NAMESPACE(X) 命名空间 X _GLIBCXX_VISIBILITY_ATTR(default) {

因此,您的 STL 实现明确覆盖 -fvisibility=hidden#pragma GCC visibility push(hidden)/#pragma GCC visibility pop.

如果你真的想强制 std::map 成员隐藏可见性,那么我认为你可以使用类似的东西:

//确保默认可见性与任何用作异常类型的类一起使用#include <内存>#include <新>#include <stdexcept>//现在使用隐藏可见性包含 `std::map` 的定义#include <bits/c++config.h>#undef _GLIBCXX_VISIBILITY_ATTR#define _GLIBCXX_VISIBILITY_ATTR(V) __attribute__ ((__visibility__ ("hidden")))#include <地图>#undef _GLIBCXX_VISIBILITY_ATTR#define _GLIBCXX_VISIBILITY_ATTR(V) __attribute__ ((__visibility__ (#V)))//恢复`_GLIBCXX_VISIBILITY_ATTR`

然后,以下一系列命令将验证 std::map 成员是否可以从共享对象中剥离:

  1. g++ -c -fPIC -fvisibility=hidden test.cpp
  2. g++ -shared -Wl,-soname,libtest.so.1 -o libtest.so.1.0 test.o
  3. strip -x libtest.so.1.0
  4. readelf -s libtest.so.1.0

请注意,在第 3 步之前,readelf -s libtest.so.1.0 打印(对我而言):

符号表 '.dynsym' 包含 23 个条目:Num:值大小类型绑定 Vis Ndx 名称0: 00000000 0 NOTYPE 本地默认值1: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__2:00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses3: 00000000 0 FUNC 全局默认值 UND _ZdlPv@GLIBCXX_3.4 (2)4:00000000 0 FUNC 全局默认值和 __gxx_personality_v0@CXXABI_1.3 (3)5:00000000 0 FUNC 全局默认值 UND _Unwind_Resume@GCC_3.0 (4)6: 00000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@GLIBC_2.1.3 (5)7: 00000d02 5 功能弱默认 12 _ZNSt4pairIKi1AED1Ev8: 00000d6c 35 FUNC 弱默认值 12 _ZNSaISt4pairIKi1AEEC1ISt9: 00000d96 35 功能弱默认 12 _ZN9__gnu_cxx13new_alloca10: 000023bc 0 NOTYPE 全球默认 ABS _end11: 000023b4 0 NOTYPE 全球默认 ABS _edata12:00000d5e 5 功能弱默认 12 _ZN9__gnu_cxx13new_alloca13: 000023b4 0 NOTYPE 全球默认 ABS __bss_start14: 00000bac 5 功能弱默认 12 _ZN9__gnu_cxx13new_alloca15:00000d08 35 功能弱默认 12 _ZN9__gnu_cxx13new_alloca16:000007f4 0 FUNC 全局默认值 10 _init17: 00000c4a 35 功能弱默认 12 _ZNSaISt13_Rb_tree_nodeIS18:00000df8 0 FUNC 全局默认值 13 _fini19:00000dba 5 功能弱默认 12 _ZN9__gnu_cxx13new_alloca20: 00000cde 35 FUNC 弱默认值 12 _ZNSaISt4pairIKi1AEED1Ev21: 00000d90 5 功能弱默认 12 _ZN9__gnu_cxx13new_alloca22: 00000ac6 35 功能弱默认 12 _ZNSaISt13_Rb_tree_nodeIS符号表 '.symtab' 包含 84 个条目:Num:值大小类型绑定 Vis Ndx 名称0: 00000000 0 NOTYPE 本地默认值1: 000000f4 0 部分本地默认值 12: 00000118 0 部分本地默认值 23: 000001c0 0 部分本地默认值 34: 0000022c 0 部分本地默认值 45: 0000039c 0 部分本地默认值 56: 000006b6 0 部分本地默认值 67: 000006e4 0 部分本地默认值 78: 00000754 0 部分本地默认值 89: 0000077c 0 部分本地默认值 910: 000007f4 0 部分本地默认值 1011: 00000824 0 部分本地默认值 1112: 00000930 0 部分本地默认值 1213: 00000df8 0 部分本地默认值 1314: 00000e14 0 部分本地默认值 1415: 00000ef8 0 部分本地默认值 1516: 00001240 0 部分本地默认值 1617: 0000225c 0 部分本地默认值 1718: 00002264 0 部分本地默认值 1819: 0000226c 0 部分本地默认值 1920: 00002270 0 部分本地默认值 2021: 00002358 0 部分本地默认值 2122: 00002364 0 部分本地默认值 2223: 000023ac 0 部分本地默认值 2324: 000023b4 0 部分本地默认值 2425: 00000000 0 部分本地默认值 2526: 00000000 0 文件本地默认 ABS crtstuff.c27: 0000225c 0 对象本地默认值 17 __CTOR_LIST__28:00002264 0 对象本地默认值 18 __DTOR_LIST__29: 0000226c 0 对象本地默认值 19 __JCR_LIST__30:00000930 0 FUNC 本地默认值 12 __do_global_dtors_aux31: 000023b4 1 对象本地默认值 24 已完成.594232:000023b8 4 对象本地默认值 24 dtor_idx.594433: 000009b0 0 FUNC 本地默认值 12 frame_dummy34: 00000000 0 文件本地默认 ABS crtstuff.c35:00002260 0 对象本地默认值 17 __CTOR_END__36: 0000123c 0 对象本地默认值 15 __FRAME_END__37:0000226c 0 对象本地默认值 19 __JCR_END__38: 00000dc0 0 FUNC 本地默认值 12 __do_global_ctors_aux39: 00000000 0 文件本地默认 ABS 测试.cpp40: 00000d64 8 FUNC 本地隐藏 12 _ZNKSt8_Rb_treeIiSt4pairI41: 000023b0 4 对象本地隐藏 23 DW.ref.__gxx_personality_42: 00000b40 11 FUNC 本地隐藏 12 _ZNSt8_Rb_treeIiSt4pairIK43: 00000bc8 129 FUNC 本地隐藏 12 _ZNSt8_Rb_treeIiSt4pairIK44: 00000bb1 11 FUNC 本地隐藏 12 _ZNSt8_Rb_treeIiSt4pairIK45: 00000b4c 96 FUNC 本地隐藏 12 _ZNSt8_Rb_treeIiSt4pairIK46: 00000ca0 62 FUNC 本地隐藏 12 _ZNKSt8_Rb_treeIiSt4pairI47: 00000ab2 19 FUNC 本地隐藏 12 _ZNSt8_Rb_treeIiSt4pairIK48: 00002364 0 对象本地隐藏 ABS _GLOBAL_OFFSET_TABLE_49:00000a56 92 FUNC 本地隐藏 12 _ZNSt8_Rb_treeIiSt4pairIK50: 000009ec 30 FUNC 本地隐藏 12 _Z11doSomethingv51: 00000c6e 49 FUNC 本地隐藏 12 _ZNSt8_Rb_treeIiSt4pairIK52:00000a32 35 FUNC 本地隐藏 12 _ZNSt8_Rb_treeIiSt4pairIK53: 000023ac 0 对象本地隐藏 23 __dso_handle54: 00000a0a 19 FUNC 本地隐藏 12 _ZNSt3mapIi1ASt4lessIiESa55:00002268 0 对象本地隐藏 18 __DTOR_END__56: 00000bbc 11 FUNC 本地隐藏 12 _ZNSt8_Rb_treeIiSt4pairIK57: 00000a1e 19 FUNC 本地隐藏 12 _ZNSt3mapIi1ASt4lessIiESa58: 00000d2c 50 FUNC 本地隐藏 12 _ZNSt8_Rb_treeIiSt4pairIK59: 00000aea 85 FUNC 本地隐藏 12 _ZNSt8_Rb_treeIiSt4pairIK60: 000009e7 0 FUNC 本地隐藏 12 __i686.get_pc_thunk.bx61: 00002270 0 对象本地隐藏 ABS _DYNAMIC62: 00000d02 5 功能弱默认 12 _ZNSt4pairIKi1AED1Ev63: 00000c4a 35 功能弱默认 12 _ZNSaISt13_Rb_tree_nodeIS64: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__65:00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses66:00000000 0 FUNC 全局默认值 UND _ZdlPv@@GLIBCXX_3.467:00000df8 0 FUNC 全局默认值 13 _fini68: 00000d6c 35 FUNC 弱默认值 12 _ZNSaISt4pairIKi1AEEC1ISt69:00000dba 5 功能弱默认 12 _ZN9__gnu_cxx13new_alloca70: 00000cde 35 FUNC 弱默认值 12 _ZNSaISt4pairIKi1AEED1Ev71: 00000d5e 5 功能弱默认 12 _ZN9__gnu_cxx13new_alloca72: 00000d90 5 功能弱默认 12 _ZN9__gnu_cxx13new_alloca73: 000023b4 0 NOTYPE 全球默认 ABS __bss_start74: 00000d96 35 功能弱默认 12 _ZN9__gnu_cxx13new_alloca75: 00000bac 5 功能弱默认 12 _ZN9__gnu_cxx13new_alloca76: 000023bc 0 NOTYPE 全球默认 ABS _end77: 000023b4 0 NOTYPE 全球默认 ABS _edata78: 00000ac6 35 功能弱默认 12 _ZNSaISt13_Rb_tree_nodeIS79: 00000000 0 FUNC 全局默认值和 __gxx_personality_v0@@CXX80: 00000000 0 FUNC 全局默认值 UND _Unwind_Resume@@GCC_3.081: 00000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@@GLIBC_2.182:00000d08 35 功能弱默认 12 _ZN9__gnu_cxx13new_alloca83: 000007f4 0 FUNC 全局默认值 10 _init

然后:

符号表 '.dynsym' 包含 23 个条目:Num:值大小类型绑定 Vis Ndx 名称0: 00000000 0 NOTYPE 本地默认值1: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__2:00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses3: 00000000 0 FUNC 全局默认值 UND _ZdlPv@GLIBCXX_3.4 (2)4:00000000 0 FUNC 全局默认值和 __gxx_personality_v0@CXXABI_1.3 (3)5:00000000 0 FUNC 全局默认值 UND _Unwind_Resume@GCC_3.0 (4)6: 00000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@GLIBC_2.1.3 (5)7: 00000d02 5 功能弱默认 12 _ZNSt4pairIKi1AED1Ev8: 00000d6c 35 FUNC 弱默认值 12 _ZNSaISt4pairIKi1AEEC1ISt9: 00000d96 35 功能弱默认 12 _ZN9__gnu_cxx13new_alloca10: 000023bc 0 NOTYPE 全球默认 ABS _end11: 000023b4 0 NOTYPE 全球默认 ABS _edata12:00000d5e 5 功能弱默认 12 _ZN9__gnu_cxx13new_alloca13: 000023b4 0 NOTYPE 全球默认 ABS __bss_start14: 00000bac 5 功能弱默认 12 _ZN9__gnu_cxx13new_alloca15:00000d08 35 功能弱默认 12 _ZN9__gnu_cxx13new_alloca16:000007f4 0 FUNC 全局默认值 10 _init17: 00000c4a 35 功能弱默认 12 _ZNSaISt13_Rb_tree_nodeIS18:00000df8 0 FUNC 全局默认值 13 _fini19:00000dba 5 功能弱默认 12 _ZN9__gnu_cxx13new_alloca20: 00000cde 35 FUNC 弱默认值 12 _ZNSaISt4pairIKi1AEED1Ev21: 00000d90 5 功能弱默认 12 _ZN9__gnu_cxx13new_alloca22: 00000ac6 35 功能弱默认 12 _ZNSaISt13_Rb_tree_nodeIS符号表 '.symtab' 包含 51 个条目:Num:值大小类型绑定 Vis Ndx 名称0: 00000000 0 NOTYPE 本地默认值1: 000000f4 0 部分本地默认值 12: 00000118 0 部分本地默认值 23: 000001c0 0 部分本地默认值 34: 0000022c 0 部分本地默认值 45: 0000039c 0 部分本地默认值 56: 000006b6 0 部分本地默认值 67: 000006e4 0 部分本地默认值 78: 00000754 0 部分本地默认值 89: 0000077c 0 部分本地默认值 910: 000007f4 0 部分本地默认值 1011: 00000824 0 部分本地默认值 1112: 00000930 0 部分本地默认值 1213: 00000df8 0 部分本地默认值 1314: 00000e14 0 部分本地默认值 1415: 00000ef8 0 部分本地默认值 1516: 00001240 0 部分本地默认值 1617: 0000225c 0 部分本地默认值 1718: 00002264 0 部分本地默认值 1819: 0000226c 0 部分本地默认值 1920: 00002270 0 部分本地默认值 2021: 00002358 0 部分本地默认值 2122: 00002364 0 部分本地默认值 2223: 000023ac 0 部分本地默认值 2324: 000023b4 0 部分本地默认值 2425: 00000000 0 部分本地默认值 2526: 00000000 0 文件本地默认 ABS crtstuff.c27: 00000000 0 文件本地默认 ABS crtstuff.c28: 00000000 0 文件本地默认 ABS 测试.cpp29: 00000d02 5 功能弱默认 12 _ZNSt4pairIKi1AED1Ev30: 00000c4a 35 功能弱默认 12 _ZNSaISt13_Rb_tree_nodeIS31: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__32:00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses33: 00000000 0 FUNC 全局默认值 UND _ZdlPv@@GLIBCXX_3.434:00000df8 0 FUNC 全局默认值 13 _fini35: 00000d6c 35 FUNC 弱默认值 12 _ZNSaISt4pairIKi1AEEC1ISt36:00000dba 5 功能弱默认 12 _ZN9__gnu_cxx13new_alloca37: 00000cde 35 功能弱默认 12 _ZNSaISt4pairIKi1AEED1Ev38: 00000d5e 5 功能弱默认 12 _ZN9__gnu_cxx13new_alloca39:00000d90 5 功能弱默认 12 _ZN9__gnu_cxx13new_alloca40: 000023b4 0 NOTYPE 全球默认 ABS __bss_start41: 00000d96 35 功能弱默认 12 _ZN9__gnu_cxx13new_alloca42: 00000bac 5 功能弱默认 12 _ZN9__gnu_cxx13new_alloca43: 000023bc 0 NOTYPE 全球默认 ABS _end44: 000023b4 0 NOTYPE 全球默认 ABS _edata45: 00000ac6 35 功能弱默认 12 _ZNSaISt13_Rb_tree_nodeIS46: 00000000 0 FUNC 全局默认值 UND __gxx_personality_v0@@CXX47:00000000 0 FUNC 全局默认值 UND _Unwind_Resume@@GCC_3.048: 00000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@@GLIBC_2.149: 00000d08 35 功能弱默认 12 _ZN9__gnu_cxx13new_alloca50: 000007f4 0 FUNC 全局默认值 10 _init

另见:

I have a file that contains the following:

#include <map>

class A {};

void doSomething() {
   std::map<int, A> m;
}

When compiled into a shared library with g++, the library contains dynamic symbols for all the methods of std::map<int, A>. Since A is private to this file, there is no possibility that std::map will be instantiated in any other shared library with the same parameters, so I'd like to make the template instantiation hidden (for some of the reasons described in this document).

I thought I should be able to do this by adding an explicit instantiation of the template class and marking it as hidden, like so:

#include <map>

class A {};
template class __attribute__((visibility ("hidden"))) std::map<int, A>;

void doSomething() {
   std::map<int, A> m;
}

However, this has no effect: the symbols are still all exported. I also tried surrounding the entire file with:

#pragma GCC visibility push(hidden)
...
#pragma GCC visibility pop

but this also has no effect on the visibility of the methods of std::map<int, A> (although it does hide doSomething). Similarly, compiling with -fvisibility=hidden has no effect on the visibility of the methods of std::map<int, A>.

The document I linked to above describes the use of export maps to restrict visibility, but that seems very tedious.

Is there a way to do what I want in g++ (other than using export maps)? If so, what is it? If not, is there a good reason why these symbols must always be exported, or is this just a omission in g++?

解决方案

From GCC bug report #36022, which was marked INVALID, Benjamin Kosnik remarked:

[A]n exception class that will be thrown between DSOs must be explicitly marked with default visibility so that the `type_info' nodes will be unified between the DSOs. Thus, the rationale for libstdc++ having namespace std have visibility "default."

Also, looking through the libstdc++ source for std::map (mine is in /usr/include/c++/4.4.4/bits/stl_map.h), it appears that the way libstdc++ enforces default visibility is with the _GLIBCXX_BEGIN_NESTED_NAMESPACE macro that is used at the top of stl_map.h:

# define _GLIBCXX_VISIBILITY_ATTR(V) __attribute__ ((__visibility__ (#V)))
# define _GLIBCXX_BEGIN_NESTED_NAMESPACE(X, Y) _GLIBCXX_BEGIN_NAMESPACE(X)
# define _GLIBCXX_BEGIN_NAMESPACE(X) namespace X _GLIBCXX_VISIBILITY_ATTR(default) {

Therefore your STL implementation is explicitly overriding -fvisibility=hidden and #pragma GCC visibility push(hidden)/#pragma GCC visibility pop.

If you really wanted to force the std::map members to have hidden visibility then I think you could use something like:

// ensure that default visibility is used with any class that is used as an exception type
#include <memory>
#include <new>
#include <stdexcept>

// now include the definition of `std::map` using hidden visibility
#include <bits/c++config.h>
#undef _GLIBCXX_VISIBILITY_ATTR
#define _GLIBCXX_VISIBILITY_ATTR(V) __attribute__ ((__visibility__ ("hidden")))
#include <map>
#undef _GLIBCXX_VISIBILITY_ATTR
#define _GLIBCXX_VISIBILITY_ATTR(V) __attribute__ ((__visibility__ (#V))) // restore `_GLIBCXX_VISIBILITY_ATTR`

Then, the following series of commands will verify that the std::map<int, A> members can be stripped from a shared object:

  1. g++ -c -fPIC -fvisibility=hidden test.cpp
  2. g++ -shared -Wl,-soname,libtest.so.1 -o libtest.so.1.0 test.o
  3. strip -x libtest.so.1.0
  4. readelf -s libtest.so.1.0

Note that before step 3, readelf -s libtest.so.1.0 printed (for me):

Symbol table '.dynsym' contains 23 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 00000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
     2: 00000000     0 NOTYPE  WEAK   DEFAULT  UND _Jv_RegisterClasses
     3: 00000000     0 FUNC    GLOBAL DEFAULT  UND _ZdlPv@GLIBCXX_3.4 (2)
     4: 00000000     0 FUNC    GLOBAL DEFAULT  UND __gxx_personality_v0@CXXABI_1.3 (3)
     5: 00000000     0 FUNC    GLOBAL DEFAULT  UND _Unwind_Resume@GCC_3.0 (4)
     6: 00000000     0 FUNC    WEAK   DEFAULT  UND __cxa_finalize@GLIBC_2.1.3 (5)
     7: 00000d02     5 FUNC    WEAK   DEFAULT   12 _ZNSt4pairIKi1AED1Ev
     8: 00000d6c    35 FUNC    WEAK   DEFAULT   12 _ZNSaISt4pairIKi1AEEC1ISt
     9: 00000d96    35 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    10: 000023bc     0 NOTYPE  GLOBAL DEFAULT  ABS _end
    11: 000023b4     0 NOTYPE  GLOBAL DEFAULT  ABS _edata
    12: 00000d5e     5 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    13: 000023b4     0 NOTYPE  GLOBAL DEFAULT  ABS __bss_start
    14: 00000bac     5 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    15: 00000d08    35 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    16: 000007f4     0 FUNC    GLOBAL DEFAULT   10 _init
    17: 00000c4a    35 FUNC    WEAK   DEFAULT   12 _ZNSaISt13_Rb_tree_nodeIS
    18: 00000df8     0 FUNC    GLOBAL DEFAULT   13 _fini
    19: 00000dba     5 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    20: 00000cde    35 FUNC    WEAK   DEFAULT   12 _ZNSaISt4pairIKi1AEED1Ev
    21: 00000d90     5 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    22: 00000ac6    35 FUNC    WEAK   DEFAULT   12 _ZNSaISt13_Rb_tree_nodeIS

Symbol table '.symtab' contains 84 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 000000f4     0 SECTION LOCAL  DEFAULT    1 
     2: 00000118     0 SECTION LOCAL  DEFAULT    2 
     3: 000001c0     0 SECTION LOCAL  DEFAULT    3 
     4: 0000022c     0 SECTION LOCAL  DEFAULT    4 
     5: 0000039c     0 SECTION LOCAL  DEFAULT    5 
     6: 000006b6     0 SECTION LOCAL  DEFAULT    6 
     7: 000006e4     0 SECTION LOCAL  DEFAULT    7 
     8: 00000754     0 SECTION LOCAL  DEFAULT    8 
     9: 0000077c     0 SECTION LOCAL  DEFAULT    9 
    10: 000007f4     0 SECTION LOCAL  DEFAULT   10 
    11: 00000824     0 SECTION LOCAL  DEFAULT   11 
    12: 00000930     0 SECTION LOCAL  DEFAULT   12 
    13: 00000df8     0 SECTION LOCAL  DEFAULT   13 
    14: 00000e14     0 SECTION LOCAL  DEFAULT   14 
    15: 00000ef8     0 SECTION LOCAL  DEFAULT   15 
    16: 00001240     0 SECTION LOCAL  DEFAULT   16 
    17: 0000225c     0 SECTION LOCAL  DEFAULT   17 
    18: 00002264     0 SECTION LOCAL  DEFAULT   18 
    19: 0000226c     0 SECTION LOCAL  DEFAULT   19 
    20: 00002270     0 SECTION LOCAL  DEFAULT   20 
    21: 00002358     0 SECTION LOCAL  DEFAULT   21 
    22: 00002364     0 SECTION LOCAL  DEFAULT   22 
    23: 000023ac     0 SECTION LOCAL  DEFAULT   23 
    24: 000023b4     0 SECTION LOCAL  DEFAULT   24 
    25: 00000000     0 SECTION LOCAL  DEFAULT   25 
    26: 00000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
    27: 0000225c     0 OBJECT  LOCAL  DEFAULT   17 __CTOR_LIST__
    28: 00002264     0 OBJECT  LOCAL  DEFAULT   18 __DTOR_LIST__
    29: 0000226c     0 OBJECT  LOCAL  DEFAULT   19 __JCR_LIST__
    30: 00000930     0 FUNC    LOCAL  DEFAULT   12 __do_global_dtors_aux
    31: 000023b4     1 OBJECT  LOCAL  DEFAULT   24 completed.5942
    32: 000023b8     4 OBJECT  LOCAL  DEFAULT   24 dtor_idx.5944
    33: 000009b0     0 FUNC    LOCAL  DEFAULT   12 frame_dummy
    34: 00000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
    35: 00002260     0 OBJECT  LOCAL  DEFAULT   17 __CTOR_END__
    36: 0000123c     0 OBJECT  LOCAL  DEFAULT   15 __FRAME_END__
    37: 0000226c     0 OBJECT  LOCAL  DEFAULT   19 __JCR_END__
    38: 00000dc0     0 FUNC    LOCAL  DEFAULT   12 __do_global_ctors_aux
    39: 00000000     0 FILE    LOCAL  DEFAULT  ABS test.cpp
    40: 00000d64     8 FUNC    LOCAL  HIDDEN   12 _ZNKSt8_Rb_treeIiSt4pairI
    41: 000023b0     4 OBJECT  LOCAL  HIDDEN   23 DW.ref.__gxx_personality_
    42: 00000b40    11 FUNC    LOCAL  HIDDEN   12 _ZNSt8_Rb_treeIiSt4pairIK
    43: 00000bc8   129 FUNC    LOCAL  HIDDEN   12 _ZNSt8_Rb_treeIiSt4pairIK
    44: 00000bb1    11 FUNC    LOCAL  HIDDEN   12 _ZNSt8_Rb_treeIiSt4pairIK
    45: 00000b4c    96 FUNC    LOCAL  HIDDEN   12 _ZNSt8_Rb_treeIiSt4pairIK
    46: 00000ca0    62 FUNC    LOCAL  HIDDEN   12 _ZNKSt8_Rb_treeIiSt4pairI
    47: 00000ab2    19 FUNC    LOCAL  HIDDEN   12 _ZNSt8_Rb_treeIiSt4pairIK
    48: 00002364     0 OBJECT  LOCAL  HIDDEN  ABS _GLOBAL_OFFSET_TABLE_
    49: 00000a56    92 FUNC    LOCAL  HIDDEN   12 _ZNSt8_Rb_treeIiSt4pairIK
    50: 000009ec    30 FUNC    LOCAL  HIDDEN   12 _Z11doSomethingv
    51: 00000c6e    49 FUNC    LOCAL  HIDDEN   12 _ZNSt8_Rb_treeIiSt4pairIK
    52: 00000a32    35 FUNC    LOCAL  HIDDEN   12 _ZNSt8_Rb_treeIiSt4pairIK
    53: 000023ac     0 OBJECT  LOCAL  HIDDEN   23 __dso_handle
    54: 00000a0a    19 FUNC    LOCAL  HIDDEN   12 _ZNSt3mapIi1ASt4lessIiESa
    55: 00002268     0 OBJECT  LOCAL  HIDDEN   18 __DTOR_END__
    56: 00000bbc    11 FUNC    LOCAL  HIDDEN   12 _ZNSt8_Rb_treeIiSt4pairIK
    57: 00000a1e    19 FUNC    LOCAL  HIDDEN   12 _ZNSt3mapIi1ASt4lessIiESa
    58: 00000d2c    50 FUNC    LOCAL  HIDDEN   12 _ZNSt8_Rb_treeIiSt4pairIK
    59: 00000aea    85 FUNC    LOCAL  HIDDEN   12 _ZNSt8_Rb_treeIiSt4pairIK
    60: 000009e7     0 FUNC    LOCAL  HIDDEN   12 __i686.get_pc_thunk.bx
    61: 00002270     0 OBJECT  LOCAL  HIDDEN  ABS _DYNAMIC
    62: 00000d02     5 FUNC    WEAK   DEFAULT   12 _ZNSt4pairIKi1AED1Ev
    63: 00000c4a    35 FUNC    WEAK   DEFAULT   12 _ZNSaISt13_Rb_tree_nodeIS
    64: 00000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
    65: 00000000     0 NOTYPE  WEAK   DEFAULT  UND _Jv_RegisterClasses
    66: 00000000     0 FUNC    GLOBAL DEFAULT  UND _ZdlPv@@GLIBCXX_3.4
    67: 00000df8     0 FUNC    GLOBAL DEFAULT   13 _fini
    68: 00000d6c    35 FUNC    WEAK   DEFAULT   12 _ZNSaISt4pairIKi1AEEC1ISt
    69: 00000dba     5 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    70: 00000cde    35 FUNC    WEAK   DEFAULT   12 _ZNSaISt4pairIKi1AEED1Ev
    71: 00000d5e     5 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    72: 00000d90     5 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    73: 000023b4     0 NOTYPE  GLOBAL DEFAULT  ABS __bss_start
    74: 00000d96    35 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    75: 00000bac     5 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    76: 000023bc     0 NOTYPE  GLOBAL DEFAULT  ABS _end
    77: 000023b4     0 NOTYPE  GLOBAL DEFAULT  ABS _edata
    78: 00000ac6    35 FUNC    WEAK   DEFAULT   12 _ZNSaISt13_Rb_tree_nodeIS
    79: 00000000     0 FUNC    GLOBAL DEFAULT  UND __gxx_personality_v0@@CXX
    80: 00000000     0 FUNC    GLOBAL DEFAULT  UND _Unwind_Resume@@GCC_3.0
    81: 00000000     0 FUNC    WEAK   DEFAULT  UND __cxa_finalize@@GLIBC_2.1
    82: 00000d08    35 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    83: 000007f4     0 FUNC    GLOBAL DEFAULT   10 _init

And afterward:

Symbol table '.dynsym' contains 23 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 00000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
     2: 00000000     0 NOTYPE  WEAK   DEFAULT  UND _Jv_RegisterClasses
     3: 00000000     0 FUNC    GLOBAL DEFAULT  UND _ZdlPv@GLIBCXX_3.4 (2)
     4: 00000000     0 FUNC    GLOBAL DEFAULT  UND __gxx_personality_v0@CXXABI_1.3 (3)
     5: 00000000     0 FUNC    GLOBAL DEFAULT  UND _Unwind_Resume@GCC_3.0 (4)
     6: 00000000     0 FUNC    WEAK   DEFAULT  UND __cxa_finalize@GLIBC_2.1.3 (5)
     7: 00000d02     5 FUNC    WEAK   DEFAULT   12 _ZNSt4pairIKi1AED1Ev
     8: 00000d6c    35 FUNC    WEAK   DEFAULT   12 _ZNSaISt4pairIKi1AEEC1ISt
     9: 00000d96    35 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    10: 000023bc     0 NOTYPE  GLOBAL DEFAULT  ABS _end
    11: 000023b4     0 NOTYPE  GLOBAL DEFAULT  ABS _edata
    12: 00000d5e     5 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    13: 000023b4     0 NOTYPE  GLOBAL DEFAULT  ABS __bss_start
    14: 00000bac     5 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    15: 00000d08    35 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    16: 000007f4     0 FUNC    GLOBAL DEFAULT   10 _init
    17: 00000c4a    35 FUNC    WEAK   DEFAULT   12 _ZNSaISt13_Rb_tree_nodeIS
    18: 00000df8     0 FUNC    GLOBAL DEFAULT   13 _fini
    19: 00000dba     5 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    20: 00000cde    35 FUNC    WEAK   DEFAULT   12 _ZNSaISt4pairIKi1AEED1Ev
    21: 00000d90     5 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    22: 00000ac6    35 FUNC    WEAK   DEFAULT   12 _ZNSaISt13_Rb_tree_nodeIS

Symbol table '.symtab' contains 51 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 000000f4     0 SECTION LOCAL  DEFAULT    1 
     2: 00000118     0 SECTION LOCAL  DEFAULT    2 
     3: 000001c0     0 SECTION LOCAL  DEFAULT    3 
     4: 0000022c     0 SECTION LOCAL  DEFAULT    4 
     5: 0000039c     0 SECTION LOCAL  DEFAULT    5 
     6: 000006b6     0 SECTION LOCAL  DEFAULT    6 
     7: 000006e4     0 SECTION LOCAL  DEFAULT    7 
     8: 00000754     0 SECTION LOCAL  DEFAULT    8 
     9: 0000077c     0 SECTION LOCAL  DEFAULT    9 
    10: 000007f4     0 SECTION LOCAL  DEFAULT   10 
    11: 00000824     0 SECTION LOCAL  DEFAULT   11 
    12: 00000930     0 SECTION LOCAL  DEFAULT   12 
    13: 00000df8     0 SECTION LOCAL  DEFAULT   13 
    14: 00000e14     0 SECTION LOCAL  DEFAULT   14 
    15: 00000ef8     0 SECTION LOCAL  DEFAULT   15 
    16: 00001240     0 SECTION LOCAL  DEFAULT   16 
    17: 0000225c     0 SECTION LOCAL  DEFAULT   17 
    18: 00002264     0 SECTION LOCAL  DEFAULT   18 
    19: 0000226c     0 SECTION LOCAL  DEFAULT   19 
    20: 00002270     0 SECTION LOCAL  DEFAULT   20 
    21: 00002358     0 SECTION LOCAL  DEFAULT   21 
    22: 00002364     0 SECTION LOCAL  DEFAULT   22 
    23: 000023ac     0 SECTION LOCAL  DEFAULT   23 
    24: 000023b4     0 SECTION LOCAL  DEFAULT   24 
    25: 00000000     0 SECTION LOCAL  DEFAULT   25 
    26: 00000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
    27: 00000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
    28: 00000000     0 FILE    LOCAL  DEFAULT  ABS test.cpp
    29: 00000d02     5 FUNC    WEAK   DEFAULT   12 _ZNSt4pairIKi1AED1Ev
    30: 00000c4a    35 FUNC    WEAK   DEFAULT   12 _ZNSaISt13_Rb_tree_nodeIS
    31: 00000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
    32: 00000000     0 NOTYPE  WEAK   DEFAULT  UND _Jv_RegisterClasses
    33: 00000000     0 FUNC    GLOBAL DEFAULT  UND _ZdlPv@@GLIBCXX_3.4
    34: 00000df8     0 FUNC    GLOBAL DEFAULT   13 _fini
    35: 00000d6c    35 FUNC    WEAK   DEFAULT   12 _ZNSaISt4pairIKi1AEEC1ISt
    36: 00000dba     5 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    37: 00000cde    35 FUNC    WEAK   DEFAULT   12 _ZNSaISt4pairIKi1AEED1Ev
    38: 00000d5e     5 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    39: 00000d90     5 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    40: 000023b4     0 NOTYPE  GLOBAL DEFAULT  ABS __bss_start
    41: 00000d96    35 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    42: 00000bac     5 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    43: 000023bc     0 NOTYPE  GLOBAL DEFAULT  ABS _end
    44: 000023b4     0 NOTYPE  GLOBAL DEFAULT  ABS _edata
    45: 00000ac6    35 FUNC    WEAK   DEFAULT   12 _ZNSaISt13_Rb_tree_nodeIS
    46: 00000000     0 FUNC    GLOBAL DEFAULT  UND __gxx_personality_v0@@CXX
    47: 00000000     0 FUNC    GLOBAL DEFAULT  UND _Unwind_Resume@@GCC_3.0
    48: 00000000     0 FUNC    WEAK   DEFAULT  UND __cxa_finalize@@GLIBC_2.1
    49: 00000d08    35 FUNC    WEAK   DEFAULT   12 _ZN9__gnu_cxx13new_alloca
    50: 000007f4     0 FUNC    GLOBAL DEFAULT   10 _init

See also:

这篇关于在使用 g++ 创建的共享库中隐藏实例化模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆