故意破坏功能名称的效用? [英] utility to intentionally mangle function names?

查看:65
本文介绍了故意破坏功能名称的效用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的C程序,其中包含全局变量和函数

名称遍布(即前面没有静态声明)。

现在我想公开用户'提供他们自己的共享

对象/ dll代码的能力,这将与我的大丑程序链接。

问题:命名碰撞。


如果我的程序有:


void common_function_name(void)

{

....

}


现在调用者有类似的功能,他们会收到链接错误。


我真正想做的是mangle所有我的名字

故意,一旦我构建了我的代码,除了那些少数函数

这些是合法的入口点,回到我的代码中,调用者

将需要。


考虑将我的所有代码包装在命名空间中并用C ++编译
但这似乎不可行现在我已经尝试过了(很多错误)。

另一种方法是进行一堆代码转换,这对于b
风险很高。


想法?

I''ve got a pretty large C program with global variables and function
names strewn about (i.e. no "static" declarations in front of them).
Now I want to expose the ability for user''s to supply their own shared
object / dll code which will link with my large ugly program.
Problem: naming collisions.

If my program has:

void common_function_name (void)
{
....
}

and now the caller has a similar function, they will get a link error.

What I really would like to do is "mangle" all of my names
intentionally, once I''ve built my code, except for those few functions
that are legitimate entry points back into my code that the caller
will need.

Thought about wrapping all my code in a namespace and compiling in C++
but this doesn''t appear feasible now that I''ve tried it (many errors).
The other method would be to do a bunch of code conversion, which is
highly risky.

Thoughts?

推荐答案

2004年4月7日07:41:45 -0700, ef *** @ goldengate.com (Eric)写道:
On 7 Apr 2004 07:41:45 -0700, ef***@goldengate.com (Eric) wrote:
我有一个非常大的C程序全局变量和函数名称散布(即在它们前面没有静态声明)。
现在我想公开用户'提供自己的共享的能力将链接机智的对象/ DLL代码我的大丑程序。
问题:命名冲突。

如果我的程序有:

void common_function_name(void)
{
...
}
现在调用者有类似的功能,他们会收到链接错误。

我真正想做的是轧染QUOT;所有我的名字
故意,一旦我构建了我的代码,除了那些很少的函数,这些函数是我的代码中的合法入口点,调用者将需要它。


而不是mangle他们,为什么不让他们静止?如果你可以为了捣乱来识别它们,那么它肯定会更容易吗

它是正确的。
考虑包装所有我的代码在命名空间中并用C ++编译
但是现在我已经尝试过了(很多错误),这似乎不可行。
另一种方法是进行一堆代码转换,这是非常危险的。

想法?
I''ve got a pretty large C program with global variables and function
names strewn about (i.e. no "static" declarations in front of them).
Now I want to expose the ability for user''s to supply their own shared
object / dll code which will link with my large ugly program.
Problem: naming collisions.

If my program has:

void common_function_name (void)
{
...
}

and now the caller has a similar function, they will get a link error.

What I really would like to do is "mangle" all of my names
intentionally, once I''ve built my code, except for those few functions
that are legitimate entry points back into my code that the caller
will need.
Rather than "mangle" them, why not make them static? If you can
identify them for the purpose of "mangling", surely it''s easier to do
it right.
Thought about wrapping all my code in a namespace and compiling in C++
but this doesn''t appear feasible now that I''ve tried it (many errors).
The other method would be to do a bunch of code conversion, which is
highly risky.

Thoughts?




-

Al Balmer
Balmer Consulting
re ************************@att.net


Eric写道:

我有一个非常大的C程序,其中包含全局变量和函数名称(即前面没有静态声明)。现在我想公开用户'提供他们自己的共享
对象/ dll代码的能力,这将与我的大丑程序链接。
问题:namin g碰撞。

如果我的程序有:

void common_function_name(void)
{
...
}

现在调用者有类似的功能,他们会收到链接错误。

我真正想做的是mangle。所有我的名字
故意,一旦我构建了我的代码,除了那些很少的函数,这些函数是我的代码中的合法入口点,调用者将需要它。
但是现在我已经尝试过了(很多错误),这似乎不可行。
另一种方法会做一堆代码转换,这是非常冒险的。

想法?

I''ve got a pretty large C program with global variables and function
names strewn about (i.e. no "static" declarations in front of them).
Now I want to expose the ability for user''s to supply their own shared
object / dll code which will link with my large ugly program.
Problem: naming collisions.

If my program has:

void common_function_name (void)
{
...
}

and now the caller has a similar function, they will get a link error.

What I really would like to do is "mangle" all of my names
intentionally, once I''ve built my code, except for those few functions
that are legitimate entry points back into my code that the caller
will need.

Thought about wrapping all my code in a namespace and compiling in C++
but this doesn''t appear feasible now that I''ve tried it (many errors).
The other method would be to do a bunch of code conversion, which is
highly risky.

Thoughts?




首先想到:我希望你现在已经了解了批发命名空间污染的缺点

.


再想一想:收集所有令人反感的名字

(使用ad-hoc工具 - 一个好的起点可能是通过

检查你的可执行文件的符号表,如果它有一个)

然后自己构建amangle.h头文件:


#define common_function_name mangled_function_name

#define common_variable_name mangled_variable_name

...


#include每个源文件开头的这个标题,

重新编译,并清理(少数,希望)问题。


第三个想法:上述方法的成功取决于你能否梦想破坏名字的能力,没有其他人愿意发明。这是一个非常高标准的创意,

甚至可能会产生之前不存在的问题。

你真正需要做的是减少问题的大小

(你不能完全消除它)隐藏你的名字你首先不需要输出
。 C方式

这样做是为了坚持使用'静态''和

用于收集有问题的符号的相同的临时方法

formangle.h也可以作为帮助找到所有

正确的静态网站。或者,您的平台

可能提供非C隐藏外部链接符号的方法,通常在链接库之后为
;请参考你的文档。


第四个想法:确实没有100%可靠的标准

C这个问题的解决方案,即使代码是从
最初是对名称空间的最小侵扰。


-
Er ********* @sun.com


In< b7 **** **********************@posting.google.com> ef***@goldengate.com (Eric)写道:
In <b7**************************@posting.google.com > ef***@goldengate.com (Eric) writes:
我已经得到了一个非常大的C程序,其中包含全局变量和函数名称(即在它们前面没有静态声明)。
现在我想公开用户提供的能力他们自己的共享
对象/ dll代码将与我的大丑程序链接。
问题:命名冲突。

如果我的程序有:

void common_function_name(void)
{
...
}
现在调用者有类似的功能,他们会收到链接错误。

我真正想要做的是mangle。所有我的名字
故意,一旦我构建了我的代码,除了那些很少的函数,这些函数是我的代码中的合法入口点,调用者将需要它。

考虑将我的所有代码包装在命名空间中并用C ++进行编译
但是现在我已经尝试过了(很多错误),这似乎不可行。
I''ve got a pretty large C program with global variables and function
names strewn about (i.e. no "static" declarations in front of them).
Now I want to expose the ability for user''s to supply their own shared
object / dll code which will link with my large ugly program.
Problem: naming collisions.

If my program has:

void common_function_name (void)
{
...
}

and now the caller has a similar function, they will get a link error.

What I really would like to do is "mangle" all of my names
intentionally, once I''ve built my code, except for those few functions
that are legitimate entry points back into my code that the caller
will need.

Thought about wrapping all my code in a namespace and compiling in C++
but this doesn''t appear feasible now that I''ve tried it (many errors).




这是正确的想法,你只需要在C中实现它。通过在所有内部标识符前加前缀<创建你的

自己的名称空间你选择的
,精心挑选,以避免与其他

程序做同样事情的可能冲突。列出所有需要b $ b b的标识符。围绕非交互式文本的简单脚本

编辑器应该可以解决您的问题。


Dan

-

Dan Pop

DESY Zeuthen,RZ集团

电子邮件: Da *****@ifh.de


这篇关于故意破坏功能名称的效用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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