Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AArch64] Crash when compiling global register variable __asm__("x15") without -ffixed-x15 #76426

Closed
arakawamasahiro-fj opened this issue Dec 27, 2023 · 2 comments · Fixed by #94271 or #117419

Comments

@arakawamasahiro-fj
Copy link
Contributor

clang in AArch64 environment, fatal error at compile time.
If a global register variable associated with the register x15 is defined in the program and referenced in the program, a fatal error occurs at compile time when -ffixed-x15 is not specified.
When -ffixed-x15 is specified, it can be compiled.
Though failing to compile without -ffixed-x15 may be intentional, it should not be a fatal error.
Here is the program and compilation log:

[program]

register int i1 __asm__("x15");

int foo(int i) {
  return i1;
}
int main() {
  return 0;
}

[compile log]

$ clang test_x15.c
fatal error: error in backend: Invalid register name "x15".
clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 18.0.0 (https://github.com/llvm/llvm-project.git fe846bc9bd164ed89cef1caefb681e0aee3d4dec)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /work/home/marakawa/bin
clang: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/test_x15-659ab1.c
clang: note: diagnostic msg: /tmp/test_x15-659ab1.sh
clang: note: diagnostic msg:

********************
$

[test_x15-659ab1.c]

# 1 "<built-in>"
# 1 "test_x15.c"
register int i1 __asm__("x15");

int foo(int i) {
  return i1;
}
int main() {
  return 0;
}

[test_x15-659ab1.sh]

# Crash reproducer for clang version 18.0.0 (https://github.com/llvm/llvm-project.git fe846bc9bd164ed89cef1caefb681e0aee3d4dec)
# Driver args: "test_x15.c"
# Original command:  "/work/home/marakawa/LLVM/llvm-project/installs/release/bin/clang-18" "-cc1" "-triple" "aarch64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-dumpdir" "a-" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "test_x15.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=non-leaf" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8a" "-target-abi" "aapcs" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/work/home/marakawa/test/local_test/1179_fatal" "-fcoverage-compilation-dir=/work/home/marakawa/test/local_test/1179_fatal" "-resource-dir" "/work/home/marakawa/LLVM/llvm-project/installs/release/lib/clang/18" "-internal-isystem" "/work/home/marakawa/LLVM/llvm-project/installs/release/lib/clang/18/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/../../../../aarch64-redhat-linux/include" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-ferror-limit" "19" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fcolor-diagnostics" "-target-feature" "+outline-atomics" "-target-feature" "-fmv" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "/tmp/test_x15-518c67.o" "-x" "c" "test_x15.c"
 "/work/home/marakawa/LLVM/llvm-project/installs/release/bin/clang-18" "-cc1" "-triple" "aarch64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-dumpdir" "a-" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "test_x15.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=non-leaf" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8a" "-target-abi" "aapcs" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/work/home/marakawa/test/local_test/1179_fatal" "-fcoverage-compilation-dir=/work/home/marakawa/test/local_test/1179_fatal" "-ferror-limit" "19" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fcolor-diagnostics" "-target-feature" "+outline-atomics" "-target-feature" "-fmv" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c" "test_x15-659ab1.c"
@llvmbot
Copy link
Member

llvmbot commented Dec 27, 2023

@llvm/issue-subscribers-backend-aarch64

Author: Masahiro ARAKAWA (arakawamasahiro-fj)

clang in AArch64 environment, fatal error at compile time. If a global register variable associated with the register x15 is defined in the program and referenced in the program, a fatal error occurs at compile time when -ffixed-x15 is not specified. When -ffixed-x15 is specified, it can be compiled. Though failing to compile without -ffixed-x15 may be intentional, it should not be a fatal error. Here is the program and compilation log:

[program]

register int i1 __asm__("x15");

int foo(int i) {
  return i1;
}
int main() {
  return 0;
}

[compile log]

$ clang test_x15.c
fatal error: error in backend: Invalid register name "x15".
clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 18.0.0 (https://github.com/llvm/llvm-project.git fe846bc9bd164ed89cef1caefb681e0aee3d4dec)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /work/home/marakawa/bin
clang: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/test_x15-659ab1.c
clang: note: diagnostic msg: /tmp/test_x15-659ab1.sh
clang: note: diagnostic msg:

********************
$

[test_x15-659ab1.c]

# 1 "&lt;built-in&gt;"
# 1 "test_x15.c"
register int i1 __asm__("x15");

int foo(int i) {
  return i1;
}
int main() {
  return 0;
}

[test_x15-659ab1.sh]

# Crash reproducer for clang version 18.0.0 (https://github.com/llvm/llvm-project.git fe846bc9bd164ed89cef1caefb681e0aee3d4dec)
# Driver args: "test_x15.c"
# Original command:  "/work/home/marakawa/LLVM/llvm-project/installs/release/bin/clang-18" "-cc1" "-triple" "aarch64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-dumpdir" "a-" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "test_x15.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=non-leaf" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8a" "-target-abi" "aapcs" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/work/home/marakawa/test/local_test/1179_fatal" "-fcoverage-compilation-dir=/work/home/marakawa/test/local_test/1179_fatal" "-resource-dir" "/work/home/marakawa/LLVM/llvm-project/installs/release/lib/clang/18" "-internal-isystem" "/work/home/marakawa/LLVM/llvm-project/installs/release/lib/clang/18/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/../../../../aarch64-redhat-linux/include" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-ferror-limit" "19" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fcolor-diagnostics" "-target-feature" "+outline-atomics" "-target-feature" "-fmv" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "/tmp/test_x15-518c67.o" "-x" "c" "test_x15.c"
 "/work/home/marakawa/LLVM/llvm-project/installs/release/bin/clang-18" "-cc1" "-triple" "aarch64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-dumpdir" "a-" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "test_x15.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=non-leaf" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8a" "-target-abi" "aapcs" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/work/home/marakawa/test/local_test/1179_fatal" "-fcoverage-compilation-dir=/work/home/marakawa/test/local_test/1179_fatal" "-ferror-limit" "19" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fcolor-diagnostics" "-target-feature" "+outline-atomics" "-target-feature" "-fmv" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c" "test_x15-659ab1.c"

@kawashima-fj
Copy link
Member

I took a look a bit.

Stack trace: https://godbolt.org/z/dY7h77KKr
Failed at llvm::AArch64TargetLowering::getRegisterByName.

Rejecting a __asm__("x15") global register variable without -ffixed-x15 seems intentional.

Clang has checks to validate the register name. Especially, there is a check to validate the register name used for global register variables. X86 overrides the validateGlobalRegisterVariable function and can emit a appropriate error message but AArch64 doesn't. If AArch64 also overrides the function and validates correctly, a user can see a appropriate error message ("register '%0' unsuitable for global register variables on this target"). However, we may not be able to see the -ffixed-x15 flag in this function.

Just FYI, GCC shows a warning message (warning: call-clobbered register used for global register variable) but does not make it an error.

@DanielKristofKiss DanielKristofKiss self-assigned this Jun 3, 2024
DanielKristofKiss added a commit to DanielKristofKiss/llvm-project that referenced this issue Jun 3, 2024
DanielKristofKiss added a commit to DanielKristofKiss/llvm-project that referenced this issue Jun 11, 2024
igorkudrin added a commit that referenced this issue Dec 6, 2024
…117419)

Fixes #76426, #109778 (for AArch64)

The previous patch for this issue, #94271, generated an error message if
a register and a global variable did not have the same size. This patch
checks if the register is reserved.
igorkudrin added a commit that referenced this issue Dec 7, 2024
…s used (#117419)

Relanding the patch with a fix for a test failure on build bots that do
not build LLVM for AArch64.

Fixes #76426, #109778 (for AArch64)

The previous patch for this issue, #94271, generated an error message if
a register and a global variable did not have the same size. This patch
checks if the register is reserved.
broxigarchen pushed a commit to broxigarchen/llvm-project that referenced this issue Dec 10, 2024
…lvm#117419)

Fixes llvm#76426, llvm#109778 (for AArch64)

The previous patch for this issue, llvm#94271, generated an error message if
a register and a global variable did not have the same size. This patch
checks if the register is reserved.
broxigarchen pushed a commit to broxigarchen/llvm-project that referenced this issue Dec 10, 2024
…s used (llvm#117419)

Relanding the patch with a fix for a test failure on build bots that do
not build LLVM for AArch64.

Fixes llvm#76426, llvm#109778 (for AArch64)

The previous patch for this issue, llvm#94271, generated an error message if
a register and a global variable did not have the same size. This patch
checks if the register is reserved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment