访问 x86_64 asm 中的 _Thread_local 变量时出现问题
我目前正在从事一个涉及 asm x86_64 和检测代码的项目。我通过 GIMPLE 插入 asm 代码,它允许我按名称访问变量并减少它。例如:sub $%d,special_counter\n\t
。现在的问题是,我需要使这个项目成为多线程,每个线程都需要这个变量之一(它们不能是同一个变量,因为它是每个线程的计数器),不仅如此,我只知道该代码在哪个线程上将在编译阶段之后运行。
我当前的方法涉及指令 _Thread_local 并尝试使用 sub $%d,special_counter@tlsgd(%rip)\n\t 但出现此错误: 创建共享对象时,不能使用针对 \.text' 的重定位 R_X86_64_32S;使用 -fPIC 重新编译,我使用 -fPIC 标志。
那么您对如何解决这个问题有什么建议吗? (我通过编写一个使用 _Thread_local
变量的较小程序并检查生成的 asm 代码获得了 @tlsgd(%rip)
)
如果您对如何进行任何其他想法这个问题的处理方法也受到欢迎。
I my currently working on a project that involves asm x86_64 and instrumenting code. I insert asm code thru GIMPLE that allow me to access a variable by name and decrease it. For example: sub $%d, special_counter\n\t
. Now the problem is that I need to make this project multithreaded and each thread needs one of this variables (they cannot be the same variable as it is a counter for each thread), not only that but I only know on what thread that code is going to run after the compilation phase.
My current approach involves the directive _Thread_local and trying to use sub $%d, special_counter@tlsgd(%rip)\n\t
but I get this error:relocation R_X86_64_32S against \.text' cannot be used when making a shared object; recompile with -fPIC
and I’m using the -fPIC flag.
So do you have any suggestions on how to fix this? (I got the @tlsgd(%rip)
from writing a smaller program that uses a _Thread_local
variable and examining the asm code produced)
If you have any other idea on how to approach this problem it is also welcomed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论