llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.41k stars 11.74k forks source link

Clang assembler does not recognize long jumps for x86 intel assembly #49636

Open llvmbot opened 3 years ago

llvmbot commented 3 years ago
Bugzilla Link 50292
Version 11.0
OS Windows NT
Reporter LLVM Bugzilla Contributor
CC @zygoloid

Extended Description

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.

llvmbot commented 3 years ago

All, How hard would it be to fix this? If it's relatively simple I might be able to pitch in.

Thanks, Ian Kronquist

iankronquist commented 2 years ago

See also https://github.com/llvm/llvm-project/issues/46048