From 507fafb0ade28b483f2e5d2b94bcf8a303303fb9 Mon Sep 17 00:00:00 2001 From: "rick.chan" Date: Tue, 13 Apr 2021 09:43:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AC=94=E8=AE=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: rick.chan --- .../Applications/Objdump/Objdump_基本使用.md | 6 +++ .../Applications/Readelf/Readelf_基本使用.md | 6 +++ .../Standard/GCC/GCC_库导出符号控制.md | 39 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 Software/Applications/Objdump/Objdump_基本使用.md create mode 100644 Software/Applications/Readelf/Readelf_基本使用.md create mode 100644 Software/Development/Standard/GCC/GCC_库导出符号控制.md diff --git a/Software/Applications/Objdump/Objdump_基本使用.md b/Software/Applications/Objdump/Objdump_基本使用.md new file mode 100644 index 0000000..909cc4e --- /dev/null +++ b/Software/Applications/Objdump/Objdump_基本使用.md @@ -0,0 +1,6 @@ +# Objdump 基本使用 + +```bash +# 查看共享库符号表 +objdump -tT +``` diff --git a/Software/Applications/Readelf/Readelf_基本使用.md b/Software/Applications/Readelf/Readelf_基本使用.md new file mode 100644 index 0000000..9935d48 --- /dev/null +++ b/Software/Applications/Readelf/Readelf_基本使用.md @@ -0,0 +1,6 @@ +# Readelf 基本使用 + +```bash +# 查看共享库符号表 +readelf -s +``` diff --git a/Software/Development/Standard/GCC/GCC_库导出符号控制.md b/Software/Development/Standard/GCC/GCC_库导出符号控制.md new file mode 100644 index 0000000..560d2f8 --- /dev/null +++ b/Software/Development/Standard/GCC/GCC_库导出符号控制.md @@ -0,0 +1,39 @@ +# GCC 库导出符号控制 + +GCC 编译库的时候默认导出所有符号。可通过指定以下参数选择默认的导出方案: + +```bash +-fvisibility=default|internal|hidden|protected +``` + +如果设置成了 hidden,那么,可在函数前增加 + +```cpp +__attribute__ ((visibility("default"))) +``` + +属性使其外部可见,或指定其属性。如: + +```cpp +/** + * @file example.c + */ +void func0(void) +{ + ... +} + +__attribute__ ((visibility("default"))) +void func1(void) +{ + ... +} +``` + +然后: + +```bash +gcc -shared -o libexample.so -fvisibility=hidden example.c +``` + +则 void func1(void) 将被导出,而 void func0(void) 会被隐藏。