Replies: 6 comments 11 replies
-
关于gcc和clang的差异,我个人的看法是: 从代码位置、内容能否改变两点来看,除了内核vmlinux和module这类场景,用户态程序的代码为了能够内存共享一般是不改变内容的,no-pic/no-pie也不改变位置,似乎没有got才能解决问题必要,使用pcala足矣。而pic/pie由于位置也会变化,又因代码只读,故要在可变的got中实施fixup。 那么从这个角度看,是不是clang的实现更合理一些?如果是这样的话,内核的问题建议编译模块加 -fPIC 参数? |
Beta Was this translation helpful? Give feedback.
-
RISCV: https://github.com/gcc-mirror/gcc/blob/4169033178f22ff31f2aba186d441bdfeca0e674/gcc/config/riscv/riscv.cc#L803 RISCV限制 |
Beta Was this translation helpful? Give feedback.
-
感谢提供的相关链接,我大概、应该是看明白这里和copy relocation之间的关系了。 这样的话,llvm最好也是像gcc那样对 |
Beta Was this translation helpful? Give feedback.
-
更新一下进展: clang也有类似gcc的 diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
index fb0fada43197..c31a62521e6b 100644
--- a/arch/loongarch/Makefile
+++ b/arch/loongarch/Makefile
@@ -68,6 +68,8 @@ LDFLAGS_vmlinux += -static -n -nostdlib
ifdef CONFIG_AS_HAS_EXPLICIT_RELOCS
cflags-y += $(call cc-option,-mexplicit-relocs)
KBUILD_CFLAGS_KERNEL += $(call cc-option,-mdirect-extern-access)
+KBUILD_AFLAGS_MODULE += $(call cc-option,-fno-direct-access-external-data)
+KBUILD_CFLAGS_MODULE += $(call cc-option,-fno-direct-access-external-data)
KBUILD_AFLAGS_MODULE += $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
else |
Beta Was this translation helpful? Give feedback.
-
clang code-model=large 与 gcc code-model=extreme 不一致的地方: 代码: #ifdef __clang__
extern __attribute__((model("large"))) __typeof__(int) pcpu;
#else
extern __attribute__((model("extreme"))) __typeof__(int) pcpu;
#endif
int fun(void)
{
return pcpu;
} GCC: gcc -O2 -c -o t.o t.c
llvm-objdump -r t.o
Clang: clang -target loongarch64 -O2 -c -o t.o a.c -fno-direct-access-external-data
llvm-objdump -r t.o
差异是访问自己链接单元的GOT是否使用64位模式。从GCC的 |
Beta Was this translation helpful? Give feedback.
-
ClangBuiltLinux/linux#1884 was resolved a while ago, closing. 🎉 |
Beta Was this translation helpful? Give feedback.
-
使用clang编译内横模块除了已知的percpu变量访问问题,还发现了一个新的模块访问vmlinux的
extern
全局变量问题。这两个问题都是因为默认mcmodel下地址编码能力不够导致。extern
全局变量访问问题仅在clang上存在,下面说一下原因。比如对于如下代码:
gcc和clang生成的访问方式不同:
当前上游内核模块编译参数是 no-pic 且 no-pie 的,在访问
extern
全局变量时,gcc采用got方式,而clang采用pcala方式。后者的地址编码能力不足以从模块空间访问到vmlinux空间。Beta Was this translation helpful? Give feedback.
All reactions