Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

as 汇编器 bug? #156

Open
yetist opened this issue May 29, 2022 · 7 comments
Open

as 汇编器 bug? #156

yetist opened this issue May 29, 2022 · 7 comments

Comments

@yetist
Copy link

yetist commented May 29, 2022

以下汇编代码使用as会报错:

.equ EXIT_SUCCESS, 0
.equ STDOUT, 1
.equ SYS_exit, 93
.equ SYS_write, 64

.section .rodata
msg:
    .string "hello, world!\n"
    len = . - msg

.text
    .globl  _start
_start:
    li.w        $a2, $len          # 必须将 $len 写为 0xf
    la.local    $a1, msg
    li.w        $a0, $STDOUT       # 必须将 $STDOUT 写为 1
    li.w        $a7, $SYS_exit     # 必须将 $SYS_exit 写为 64
    syscall     0x0

    li.w        $a0, $EXIT_SUCCESS  # 必须将 $EXIT_SUCCESS 写为 0
    li.w        $a7, $SYS_exit      # 必须将 SYS_exit 写为 93
    syscall     0x0

报错输出如下:

$ as -o hello.o hello.S
hello.S: Assembler messages:
hello.S:14: 错误:no match insn: li.w   $a2,$len
hello.S:16: 错误:no match insn: li.w   $a0,$STDOUT
hello.S:17: 错误:no match insn: li.w   $a7,$SYS_exit
hello.S:20: 错误:no match insn: li.w   $a0,$EXIT_SUCCESS
hello.S:21: 错误:no match insn: li.w   $a7,$SYS_exit

只有按代码中的注释,修改如下,才可通过编译:

$ cat hello.S 
.section .rodata
msg:
    .string "hello, world!\n"
    len = . - msg

.text
    .globl  _start
_start:
    li.w        $a2, 0xf
    la.local    $a1, msg
    li.w        $a0, 1
    li.w        $a7, 64
    syscall     0x0

    li.w        $a0, 0
    li.w        $a7, 93
    syscall     0x0
$ as -o hello.o hello.S
$ ld -o hello hello.o
$ ./hello 
hello, world!

应该是 as 汇编器不支持 .equ 伪指令,同时也不支持使用 len 来计算字符串长度吧?

@xen0n
Copy link

xen0n commented May 29, 2022

看上去更像是 $ 符号被无条件认作寄存器前缀,然后后接的字符串不能被解析为寄存器,而导致的指令模板不匹配吧

@yetist
Copy link
Author

yetist commented May 30, 2022

看上去更像是 $ 符号被无条件认作寄存器前缀,然后后接的字符串不能被解析为寄存器,而导致的指令模板不匹配吧

感觉你的分析更准确

@Calring
Copy link

Calring commented Aug 15, 2022

this PR LoongArch: gas: add support using variable for li.w/d #215 has fixed this.

@yetist
Copy link
Author

yetist commented Sep 14, 2022

commit 7ec2492 实现是有bug的。

@yetist
Copy link
Author

yetist commented Sep 15, 2022

测试用例:

$ cat a.c
#define PACKAGE_NAME ""
#define PACKAGE_TARNAME ""
#define PACKAGE_VERSION ""
#define PACKAGE_STRING ""
#define PACKAGE_BUGREPORT ""
#define PACKAGE_URL ""
/* end confdefs.h.  */
#include <stdio.h>
int
main ()
{
FILE *f = fopen ("conftest.out", "w");
 return ferror (f) || fclose (f) != 0;

  ;
  return 0;
}

出错信息:

/tmp/ccR4Csf7.s: Assembler messages:
/tmp/ccR4Csf7.s:42: Error: illegal operand: .L4

@Calring
Copy link

Calring commented Sep 15, 2022

我这边没有复现出这个问题,可以贴详细一点吗,包括编译参数,编译器版本等.

@yetist
Copy link
Author

yetist commented Feb 23, 2023

看一下附件汇编,貌似是类似问题。

我这里报错如下:

loongarch64.S:263: Error: no match insn: st.d   $s7,$s8,domain_field_caml_young_ptr
loongarch64.S:263: Error: no match insn: st.d   $s1,$s8,domain_field_caml_exn_handler
loongarch64.S:263: Error: no match insn: ld.d   $t0,$s8,domain_field_caml_gc_regs_buckets
loongarch64.S:263: Error: no match insn: st.d   $t1,$s8,domain_field_caml_gc_regs_buckets
loongarch64.S:263: Error: no match insn: st.d   $t0,$s8,domain_field_caml_gc_regs
...

loongarch64.s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants