gpt4 book ai didi

编译 linux 0.0.1 => 错误 : ‘asm’ operand has impossible constraints __asm__ ("cld\n"

转载 作者:太空宇宙 更新时间:2023-11-04 12:28:43 24 4
gpt4 key购买 nike

我正尝试在我的 64 位英特尔机器上从源代码编译 linux 内核 0.0.1。只是为了填写引导和主要内容,我必须修改所有 makefile 以获得 32 位编译。

所以,这是 make 的输出:

In file included from traps.c:7:0:
../include/string.h:128:22: warning: conflicting types for built-in function ‘strchr’
extern inline char * strchr(const char * s,char c)
^
../include/string.h:145:22: warning: conflicting types for built-in function ‘strrchr’
extern inline char * strrchr(const char * s,char c)
^
../include/string.h:379:22: warning: conflicting types for built-in function ‘memchr’
extern inline void * memchr(const void * cs,char c,int count)
^
../include/string.h:395:22: warning: conflicting types for built-in function ‘memset’
extern inline void * memset(void * s,char c,int count)
^
In file included from traps.c:11:0:
../include/linux/kernel.h:5:1: warning: function return types not compatible due to ‘volatile’
volatile void panic(const char * str);
^
../include/linux/kernel.h:5:1: warning: function return types not compatible due to ‘volatile’
../include/linux/kernel.h:5:1: warning: function return types not compatible due to ‘volatile’
In file included from traps.c:7:0:
../include/string.h: In function ‘strcpy’:
../include/string.h:29:1: error: ‘asm’ operand has impossible constraints
__asm__("cld\n"
^
Makefile:24: set di istruzioni per l'obiettivo "traps.o" non riuscito

string.h部分代码如下:

extern inline char * strcpy(char * dest,const char *src)
{
__asm__("cld\n"
"1:\tlodsb\n\t"
"stosb\n\t"
"testb %%al,%%al\n\t"
"jne 1b"
::"S" (src),"D" (dest):"si","di","ax");
return dest;
}

我不知道为什么原始代码无法编译。到现在我已经成功编译:boot 和 init subdir。

非常感谢

最佳答案

我认为问题在于寄存器破坏列表与输入重叠。

"S" 代表寄存器 esi"D" 代表寄存器 edi ;但是 clobber 列表包含 "si""di",它们是这些寄存器的低 16 位部分。也许旧的 GCC 版本忽略了这一点,但新版本不允许重叠。

来自docs here :

Clobber descriptions may not in any way overlap with an input or output operand.

解决方法,将它们从列表中移除即可:

...
::"S" (src),"D" (dest) :"ax", "cc");

顺便说一句,我还向 "cc" 添加了 clobber,因为该程序集修改了 e 标志。

关于编译 linux 0.0.1 => 错误 : ‘asm’ operand has impossible constraints __asm__ ("cld\n",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43898963/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com