When clang is invoked on an assembly file, I expect it to be compatible with gcc and binutils as.
When using Intel syntax, clang does not properly assemble the x86 long jump instruction, used to reload the code segment descriptor. This happens in .code16 and .code32 mode.
Here is an example that will assemble with gcc and binutils as, but not with clang:
ian@iankhome:~/k2$ cat bug.S
.intel_syntax noprefix
.code16
.text
.global _start
_start:
jmp 0:.canonicalized_ip
.canonicalized_ip:
jmp 0x18:.protected
.code32
.protected:
jmp 0x28,.long_mode
.long_mode:
ian@iankhome:~/k2$ clang-11 -c bug.S
bug.S:7:7: error: unexpected token in argument list
jmp 0:.canonicalized_ip
^
bug.S:9:10: error: unexpected token in argument list
jmp 0x18:.protected
^
bug.S:12:5: error: invalid operand for instruction
jmp 0x28,.long_mode
^
ian@iankhome:~/k2$ gcc -c bug.S
ian@iankhome:~/k2$ as -c bug.S
ian@iankhome:~/k2$ clang-11 --version
Ubuntu clang version 11.0.0-2~ubuntu20.04.1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
ian@iankhome:~/k2$ as --version
GNU assembler (GNU Binutils for Ubuntu) 2.34
Copyright (C) 2020 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
ian@iankhome:~/k2$ gcc --version
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Adding the clang command line flags -masm=intel doesn't change clang's behavior.
When clang is invoked on an assembly file, I expect it to be compatible with gcc and binutils as.
When using Intel syntax, clang does not properly assemble the x86 long jump instruction, used to reload the code segment descriptor. This happens in .code16 and .code32 mode.
Here is an example that will assemble with gcc and binutils as, but not with clang:
Adding the clang command line flags -masm=intel doesn't change clang's behavior.