从共享库中删除嵌入的源文件名 [英] Remove embedded source filenames from shared libraries
问题描述
当我从源文件secret.cc构建共享库mylib.so时,生成的共享对象包含源文件名:
do_global_ctors_aux^@secret.cc ^ @ __ DTOR_END ...
但我不想泄露该文件的名称secret.cc)给我的图书馆的用户。有没有办法从共享对象中剥离文件名信息,或者防止它被插入到第一个位置?
很简单:不要让编译器从一开始就知道源文件名。取代
g ++ -std = c ++ 11 -O3 -Wall -c my_source.cc -o my_source.o
执行此操作:
< pre class =lang-none prettyprint-override>
cat my_source.cc | g ++ -std = c ++ 11 -O3 -Wall -c -x c ++ - -o my_source.o
请注意,你需要明确提供 -x c ++
,错误消息显然不会包含文件名,还有一个额外的警告:当你的源包含相对包含,即,包括在引号( #includefoo.hpp
)中,而不是尖括号( #include< foo.hpp>
),这些将不再工作,因为编译器不能引用该文件的目录,它只是看到一个字节流从管道。
When I build a shared library "mylib.so" from a source file "secret.cc", the resulting shared object contains the source filename:
... do_global_ctors_aux^@secret.cc^@__DTOR_END ...
But I don't want to divulge the name of that file ("secret.cc") to the users of my library. Is there a way to strip the filename information from the shared object, or to prevent it from being inserted in the first place?
It's quite simple: Don't let the compiler know the source's filename from the very beginning. Instead of
g++ -std=c++11 -O3 -Wall -c my_source.cc -o my_source.o
do this:
cat my_source.cc | g++ -std=c++11 -O3 -Wall -c -x c++ - -o my_source.o
Note that you need to provide -x c++
explicitly, the error messages obviously won't contain the filename anymore and there is one additional caveat: When your sources contain relative includes, i.e., includes in quotes (#include "foo.hpp"
) instead of angle brackets (#include <foo.hpp>
), those will no longer work as the compiler can't refer to the file's directory, it just sees a byte-stream from a pipe.
这篇关于从共享库中删除嵌入的源文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!