llvm / llvm-project

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

ARM assembler calculates indeterminate value for immediate expression with addresses #37002

Open andreyv opened 6 years ago

andreyv commented 6 years ago
Bugzilla Link 37654
Version 6.0
OS Linux

Extended Description

Assembling the following source:

.text
.thumb
subs r0, #(.-.+1)

with clang -fintegrated-as -target armv7-none-linux-androideabi16 -c x.s produces, for example,

00000000 <.text>:
   0:   38cb        subs    r0, #203    ; 0xcb

where the immediate value varies with each run.

This seems to affect any expression with addresses, e.g., (.-.), (.-.L0) etc. The +1 is there just for non-zero expected output.

clang --version:

clang version 6.0.0 (tags/RELEASE_600/final)
andreyv commented 5 years ago

Still reproducible with clang version 9.0.0 (tags/RELEASE_900/final).

Looks like only adds and subs are affected, and only the variants which set condition flags. This also reproduces the issue:

adds r0, #(.-.)

But all these are good:

.byte .-.
adds r0, #1
add r0, #(.-.)
ands r0, #(.-.)
movs r0, #(.-.)
rsbs r0, r0, #(.-.)

Another bad sample:

adds r0, #.

generates a random immediate without any relocations.