c - 使用 -static -nostdlib 时如何设置 __thread?
问题描述
我怀疑问题是我需要设置fs
寄存器。我只是想知道什么是正确的方法?我对如何确定线程局部变量(.tbbs?)的大小一无所知。我知道我可以在编译后使用 readelf 手动检查,但我假设该解决方案不涉及解析 elf 文件。
我有时会像这样编译二进制文件,所以我要阅读的程序集更少。需要 clang 和 gcc 的解决方案
gcc -O2 -fno-stack-protector -static -nostdlib -Wl,--build-id=none -Wl,--nmagic -fno-asynchronous-unwind-tables tiny.c ; objcopy --remove-section .comment a.out a.out ; 剥离 ./a.out
来源
//gcc -static -nostdlib tiny.c && ./a.out
static inline void my_exit(int errcode) {
register int rax __asm__ ("eax") = 60;
register int rdi __asm__ ("edi") = errcode;
__asm__ __volatile__ (
"syscall"
: "+r" (rax)
: "r" (rdi)
: "cc", "memory"
);
}
__thread int counter;
int _start()
{
counter++; //Comment this out or remove `__thread` and this runs fine
my_exit(1);
return 0;
}
解决方案
推荐阅读
- html - 防止内容在带有隐式行的网格中自动居中
- python - 类型错误:不可散列类型:“列表”
- r - 仅使用 Rscript 的 mclapply sendmaster 错误
- infragistics - 卸载基础设施的问题
- c# - 未找到依赖项清单中指定的程序集
- java - Apache Ignite:节点尚未连接到拓扑
- c# - 实体框架 6 相关实体,其中 datetime 子句不转换为 SQL
- excel - 运行时错误 438:对象不支持 ... 用于工作簿上的 Debug.Print
- mysql - `字段列表`中的未知列“某事”,出了什么问题?
- c - 无法在函数调用中更改动态分配的数组值