Xcode构建的静态库中的符号隐藏 [英] Symbol hiding in static libraries built with Xcode

查看:445
本文介绍了Xcode构建的静态库中的符号隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚是否可以构建一个静态库来隐藏其所有内部对象和函数等,除了我要导出的接口之外.我正在尝试使用Xcode(gcc 4.2).

I'm trying to figure out whether I can build a static library that hides all of its internal objects and functions, etc, except for the interfaces I want to export. I'm experimenting with Xcode (gcc 4.2).

我已经在__attribute__((visibility("hidden")))属性. rel ="noreferrer">本文档.我还定义了一些小的辅助C函数,例如它们是文件本地的(静态的)等.

I've used the __attribute__((visibility("hidden"))) attribute on some C++ classes per this documentation. I've also defined little helper C functions as being file-local (static), etc.

但是,当我在生成的.a库文件上运行strings时,即使在Release配置中进行编译,我仍然可以看到表面上隐藏的类的名称,以及它们的方法名,甚至是文件名-本地功能也遍布其中.

However, when I run strings on the resulting .a library file, even when compiled in Release configuration, I still see the names of my ostensibly-hidden classes, with their method names, and even the names of file-local functions strewn around in there as well.

我已经将-fvisibility=hidden甚至-fno-rtti添加到了gcc标志中.尽管这减少了一些字符串,但类名,方法名和静态函数名仍然以纯净或整齐但可读的形式存在.

I've added the -fvisibility=hidden and even -fno-rtti to the gcc flags. While this reduces some of the strings, the class names, method names, and static functions names are all still in there in plain or mangled-but-readable form.

是否有一种可靠的方法来使编译器构建此东西而无需将所有内部东西的字符串名称发送到二进制文件中?不需要任何外部客户端进行链接.

Is there a reliable way to get the compiler to build this stuff without having the string names of all the internal stuff emitted into the binary? It shouldn't be necessary to have for any external clients linking in.

(为了澄清:我问的是内部命名的混淆,而不是字面意义上的导出绑定需求.我不敢保证所有内部工作都可以通过strings命令看到,无论这些符号是正式导出还是正式导出.不是.

(To clarify: I'm asking about obfuscation of internal naming, versus literal export binding needs. I'm disconcerted that all the internal workings are visible via the strings command, regardless of whether these symbols are formally exported or not.)

谢谢.

推荐答案

隐藏内部名称需要一些简单的Xcode构建设置,通常不需要修改源或更改构建产品的类型.

Hiding internal names requires a few simple Xcode build settings, and it is not generally necessary to modify source or change the type of the built product.

  1. 通过执行单对象预链接消除模块之间所需的任何内部符号.将名为"Perform Single-Object Prelink"的Xcode构建设置设置为Yes(GENERATE_MASTER_OBJECT_FILE = YES).这将导致ld以"-r"标志运行.
  2. 确保将条带样式"设置设置为非全局符号"(STRIP_STYLE =非全局符号),这会将"-x"传递给ld.
  3. 仅在启用了后处理的情况下才对静态库执行剥离(这不是默认设置).将Xcode构建设置部署后处理"设置为是". (DEPLOYMENT_POSTPROCESSING =是).还要确保将使用单独的条带"设置为是"(并非始终是默认值)(SEPARATE_STRIP = YES).
  4. 如果除局部符号外,如果您需要删除某些全局符号,则可以在Xcode构建设置其他剥离标志"下为strip命令提供其他选项.例如.我通常使用带状"-R somefile"选项为文件提供一个附加的符号列表,该列表我要从全局符号表中删除.

这篇关于Xcode构建的静态库中的符号隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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