arm64: Work around broken GCC 4.9 handling of "S" constraint
authorMarc Zyngier <maz@kernel.org>
Thu, 17 Dec 2020 11:11:35 +0000 (11:11 +0000)
committerCatalin Marinas <catalin.marinas@arm.com>
Thu, 17 Dec 2020 11:46:20 +0000 (11:46 +0000)
commit9fd339a45be5c06e239d45a042eab9d25de87882
treea5c3d1eb0e47cc2f099fe072688fb93e83fb818f
parent31f80a4e9603c3d1668bc3a1401d49321d547d54
arm64: Work around broken GCC 4.9 handling of "S" constraint

GCC 4.9 seems to have a problem with the "S" asm constraint
when the symbol lives in the same compilation unit, and pretends
the constraint is impossible:

$ cat x.c
void *foo(void)
{
static int x;
int *addr;
asm("adrp %0, %1" : "=r" (addr) : "S" (&x));
return addr;
}

$ ~/Work/gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux/bin/aarch64-linux-gnu-gcc -S -x c -O2 x.c
x.c: In function ‘foo’:
x.c:5:2: error: impossible constraint in ‘asm’
  asm("adrp %0, %1" : "=r" (addr) : "S" (&x));
  ^

Boo. Following revisions of the compiler work just fine, though.

We can fallback to the "i" constraint for GCC version prior to 5.0,
which *seems* to do the right thing. Hopefully we will be able to
remove this at some point, but in the meantime this gets us going.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20201217111135.1536658-1-maz@kernel.org
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/include/asm/kvm_asm.h