gpt4 book ai didi

c - “asm”操作数具有不可能的约束

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

我试图在 Arch linux 上编译 xen 并收到以下错误:

src/stacks.c:342:5: error: 'asm' operand has impossible constraints
asm volatile(
^

这是导致错误的方法的代码:

void
run_thread(void (*func)(void*), void *data)
{
ASSERT32FLAT();
if (! CONFIG_THREADS || ! ThreadControl)
goto fail;
struct thread_info *thread;
thread = memalign_tmphigh(THREADSTACKSIZE, THREADSTACKSIZE);
if (!thread)
goto fail;

dprintf(DEBUG_thread, "/%08x\\ Start thread\n", (u32)thread);
thread->stackpos = (void*)thread + THREADSTACKSIZE;
struct thread_info *cur = getCurThread();
hlist_add_after(&thread->node, &cur->node);
asm volatile(
// Start thread
" pushl $1f\n" // store return pc
" pushl %%ebp\n" // backup %ebp
" movl %%esp, (%%edx)\n" // cur->stackpos = %esp
" movl (%%ebx), %%esp\n" // %esp = thread->stackpos
" calll *%%ecx\n" // Call func

// End thread
" movl %%ebx, %%eax\n" // %eax = thread
" movl 4(%%ebx), %%ebx\n" // %ebx = thread->node.next
" movl (%5), %%esp\n" // %esp = MainThread.stackpos
" calll %4\n" // call __end_thread(thread)
" movl -4(%%ebx), %%esp\n" // %esp = next->stackpos
" popl %%ebp\n" // restore %ebp
" retl\n" // restore pc
"1:\n"
: "+a"(data), "+c"(func), "+b"(thread), "+d"(cur)
: "m"(*(u8*)__end_thread), "m"(MainThread)
: "esi", "edi", "cc", "memory");
return;

fail:
func(data);
}

我不确定发生了什么。有懂行的大神帮忙看一下,看看这里有没有什么明显的问题?

更新:

你可以通过做两件事来修复这个错误:

  1. 将 COMMONCFLAGS += $(call cc-option,$(CC),-fstack-check=no,) 添加到 seabios makefile 中(如果您从 git AUR 构建 xen,则位置应为 xen/src/xen -4.5.1/tools/firmware/seabios-dir-remote/Makefile)

  2. 转到 stacks.c 并将 movl (%5), %%esp 更改为 movl %5, %%esp

最佳答案

直接原因可能是您没有直接或间接通过优化开关启用-fomit-frame-pointer。因此,编译器用完了寄存器,因为 eaxebxecxedx 用于参数,esiedi 是 clobber,ebp 是帧指针。因此,解决方案是确保启用此选项。

显然是 this code is part of SeaBIOS(感谢 Michael Petch 找到它)。 __end_thread 只是一个函数,而不是人们期望从那个施法魔法中得到的函数指针。因此,我认为这个构造的重点是解决任何最终的名称重整。不幸的是,它为此牺牲了一个寄存器。如果您知道您的环境不会破坏函数名称,您可以使用这个更简单的版本,它不需要额外的寄存器,并且在调试版本中也应该使用帧指针编译得很好:

asm volatile(
// Start thread
" pushl $1f\n" // store return pc
" pushl %%ebp\n" // backup %ebp
" movl %%esp, (%%edx)\n" // cur->stackpos = %esp
" movl (%%ebx), %%esp\n" // %esp = thread->stackpos
" calll *%%ecx\n" // Call func

// End thread
" movl %%ebx, %%eax\n" // %eax = thread
" movl 4(%%ebx), %%ebx\n" // %ebx = thread->node.next
" movl (%4), %%esp\n" // %esp = MainThread.stackpos
" call __end_thread\n" // call __end_thread(thread)
" movl -4(%%ebx), %%esp\n" // %esp = next->stackpos
" popl %%ebp\n" // restore %ebp
" retl\n" // restore pc
"1:\n"
: "+a"(data), "+c"(func), "+b"(thread), "+d"(cur)
: "m"(MainThread)
: "esi", "edi", "cc", "memory");

关于c - “asm”操作数具有不可能的约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33888868/

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