什么是Linux实用程序来管理C ++符号名? [英] What is Linux utility to mangle a C++ symbol name?

查看:251
本文介绍了什么是Linux实用程序来管理C ++符号名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 c ++ filt 命令解开一个符号,什么工具做相反的操作符号名称?



如果我想在一个受损的C ++函数名称上调用 dlsym(),这将非常有用。我不想硬编码代码中的名称,因为它可能随时间变化,由于新的编译器版本或新的编译器品牌被使用或目前,由于编译多个平台。



有没有一种编程方式来获取代表C ++函数在运行时的字符串,使代码是编译器独立的?一种可能做到这一点的方法是在编译时调用一个实用程序,为所使用的编译器执行名称调整,并将适当的受损的C ++符号名插入 dlsym()使用。



这里是最接近解决方案我'这是通过使用固定的C样式名称来间接到C ++符号来实现的,C ++符号是在库中定义的,你希望 dlsym()

你可以得到你想要什么通过查看符号表
的.so你正在看:别人回答这已经
返回共享库符号表



但是,如果有太多符号...不工作。

这是一个疯狂的想法。注意!



一个潜在的解决方案是:


  1. create一个包含一个名字的文件:你想要的名字:void myfunction(){}


  2. 编译该文件(使用-fPIC和-shared它是一个动态库)


  3. 迭代通过符号(应该只有一个想要加其他常规垃圾,你可以过滤)。迭代符号是笨拙的,但你可以这样做:
    返回共享库符号表


  4. dlclose()释放它(从符号中删除存根)

    b $ b
  5. 使用dlopen打开所需的文件


基本上,从你的代码,它会创建
a。你可以看看,得到唯一的值,然后卸载.so
,所以你可以加载你想要的一个。



这很疯狂。


I have c++filt command to demangle a symbol, what is the tool to do the opposite and mangle a symbol name?

This would be useful if I were to want to call dlsym() on a mangled C++ function name. I'd rather not hard code the name mangling in the code since it could change over time due to new complier versions or new compiler brands being used or at present due to compiling for multiple platforms.

Is there a programatic way to get the string that represents a C++ function at runtime so that the code is compiler independent? One way to possibly do this would be to call a utility at compile time that performs the name mangling for the compiler being used and inserts the appropriate mangled C++ symbol name into a string for dlsym() to use.

Here is the closest to a solution I've found on this site which is accomplished by using a fixed C style name to indirect to C++ symbols that are defined in the library you wish to dlsym(), but if you do not have control over what that library provides, this is not an option.

解决方案

You may be able to get what you want by looking at the symbol table of the .so you are looking at: Someone else answered this already Returning a shared library symbol table.

However, if there are too many symbols ... that may not work.
So here's a crazy idea. Caveat emptor!

A potential solution is to:

  1. create a file with a stub with exactly one name: the name you want: void myfunction() { }

  2. compile that file (with -fPIC and -shared so it's a dynamic library)

  3. call dlopen/dlsym on that particular file

  4. Iterate through the symbols (there should just be only the one want plus other regular junk you can filter). Iterating through the symbols is clumsy, but you can do it: Returning a shared library symbol table

  5. dlclose() to free it up (lose the stub out of your symbols)

  6. Open the file you want with dlopen

Basically, you would invoke the compiler from your code, it would create a .so you could look at, get the only value out, then unload that .so so you could load in the one you want.

It's crazy.

这篇关于什么是Linux实用程序来管理C ++符号名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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