I learned that assembly code doesn’t depend on the OS. For verification, I generate the assembly code of the following code snippet (named test.c
) under windows and try assembling it under WSL.
int add(int a, int b){
return a+b;
}
After I run gcc test.c -S
under windows, the file test.s
is generated as
.file "test.c"
.text
.globl add
.def add; .scl 2; .type 32; .endef
.seh_proc add
add:
pushq %rbp
.seh_pushreg %rbp
movq %rsp, %rbp
.seh_setframe %rbp, 0
.seh_endprologue
movl %ecx, 16(%rbp)
movl %edx, 24(%rbp)
movl 16(%rbp), %edx
movl 24(%rbp), %eax
addl %edx, %eax
popq %rbp
ret
.seh_endproc
.ident "GCC: (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) 11.2.0"
If gcc test.s -c
is run under windows, the object file test.o
is generated without any error. However, if gcc test.s -c
is run under WSL, the following errors are reported.
test.s: Assembler messages:
test.s:4: Error: unknown pseudo-op: `.def'
test.s:4: Error: unknown pseudo-op: `.scl'
test.s:4: Error: Missing symbol name in directive
test.s:4: Error: unrecognized symbol type "32"
test.s:4: Error: unknown pseudo-op: `.endef'
test.s:5: Error: unknown pseudo-op: `.seh_proc'
test.s:8: Error: unknown pseudo-op: `.seh_pushreg'
test.s:10: Error: unknown pseudo-op: `.seh_setframe'
test.s:11: Error: unknown pseudo-op: `.seh_endprologue'
test.s:19: Error: unknown pseudo-op: `.seh_endproc'
Similarly, if I run gcc test.c -S
under WSL, the generated file test.s
can only be assembled under WSL.
I want to know the reason of it, and how to fix the reported errors.
hiiragi4000 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.