栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

剥离linux共享库

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

剥离linux共享库

因此,我们目前的解决方案如下:

测试文件

#include <cmath>#include <vector>#include <typeinfo>struct private_struct{    float f;};float private_function(float f){    return std::abs(f);}void other_private_function(){    std::vector<private_struct> f(1);}extern "C" void __attribute__ ((visibility ("default"))) public_function2(){    other_private_function();}extern "C" float __attribute__ ((visibility ("default"))) public_function1(float f){    return private_function(f);}

出口版本

LIBTEST {global:    public*;local:    *;};

用编译

g++ -shared test.cpp -o libtest.so -fvisibility=hidden -fvisibility-inlines-hidden -s -Wl,--version-script=exports.version

00000000 A LIBTEST         w _Jv_RegisterClasses         U _Unwind_Resume         U std::__throw_bad_alloc()         U operator delete(void*)         U operator new(unsigned int)         w __cxa_finalize         w __gmon_start__         U __gxx_personality_v0000005db T public_function100000676 T public_function2

这与我们正在寻找的相当接近。但是有一些陷阱:

  • 我们必须确保在内部代码中不使用“ exported”前缀(在这个简单示例中为“ public”,但显然在我们的情况下更有用)。
  • 许多符号名称仍最终出现在字符串表中,该字符串表似乎取决于RTTI,-fno-rtti在我的简单测试中使它们消失了,但这是一个相当核心的解决方案。

我很高兴接受任何人提出的更好的解决方案!



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/412357.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号