访问 x86_64 asm 中的 _Thread_local 变量时出现问题

发布于 2025-01-16 15:28:51 字数 518 浏览 5 评论 0原文

我目前正在从事一个涉及 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文