Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

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

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR50292
Status NEW
Importance P enhancement
Reported by Ian Kronquist (iankronquist@gmail.com)
Reported on 2021-05-10 20:40:55 -0700
Last modified on 2021-05-10 20:56:11 -0700
Version 11.0
Hardware PC Windows NT
CC llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

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.

Quuxplusone 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