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

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

问题描述

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

我已经使用了 __属性__((visibility(hidden)))每个一些C ++类的code>属性这个文档。我也已经定义了小助手C函数作为文件本地(静态)等。



然而,当我运行 strings 即使在编译为Release配置的情况下,仍然可以看到我的表面隐藏类的名称,它们的方法名称,甚至包含文件本地函数的名称,好。



我已经添加了 -fvisibility = hidden 甚至 -fno-rtti 到gcc标志。虽然这减少了一些字符串,但类名,方法名和静态函数名仍然以简单或不可读的形式存在。

有没有一种可靠的方法让编译器构建这些东西,而不用将所有内部字符串的字符串名称发送到二进制文件中? (b)为了澄清:我在询问关于内部命名的混淆,以及与文字输出绑定需求相关的问题。无论这些符号是否正式导出,我都会对通过 strings 命令可见的所有内部工作感到不安。)



谢谢。

解决方案

隐藏内部名称需要几个简单的Xcode构建设置,修改源代码或更改构建产品的类型。


  1. 通过执行单对象预链接消除模块之间所需的任何内部符号。将名为执行单对象预链接的Xcode构建设置设置为是(GENERATE_MASTER_OBJECT_FILE = YES)。这会使ld以-r标志运行。

  2. 确保设置Strip Style设置为Non-global symbols(STRIP_STYLE = non-global) ,这会将-x传递给ld。

  3. 如果启用了后处理(这不是默认设置),则仅在静态库上执行清废操作。将Xcode构建设置部署后处理设置为是。 (DEPLOYMENT_POSTPROCESSING = YES)。另外,请确保使用单独的栏设置为是(并非总是默认值)(SEPARATE_STRIP = YES)。

  4. 如果除了局部符号,的全局符号,您可以在Xcode构建设置Additional strip flags下为strip命令提供附加选项。例如。我通常使用strip-R somefile选项来提供一个文件,其中包含我想从全局符号表中删除的附加符号列表。


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).

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.

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.

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.

(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.)

Thanks.

解决方案

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. Eliminate any internal symbols required between modules by performing a single-object prelink. Set the Xcode build setting named "Perform Single-Object Prelink" to Yes (GENERATE_MASTER_OBJECT_FILE=YES). This causes ld to be run with the "-r" flag.
  2. Make sure that the setting "Strip Style" is set to "Non-global symbols" (STRIP_STYLE=non-global), this passes "-x" to ld.
  3. Stripping is only actually performed on static libraries if post-processing is enabled (and this is not the default). Set Xcode build setting "Deployment Postprocessing" to yes. (DEPLOYMENT_POSTPROCESSING=YES). Also make sure that "Use separate strip" is set to Yes (not always the default) (SEPARATE_STRIP=YES).
  4. If, in addition to local symbols, if you need to remove some of the global symbols you can supply additional options to the strip command, under the Xcode build setting "Additional strip flags". E.g. I commonly use the strip "-R somefile" option to provide a file with an additional list of symbols which I want removed from the global symbol table.

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

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