CTSRD-CHERI / clang

DO NOT USE. Use llvm-project instead
Other
9 stars 8 forks source link

Crash when using __cheri_cast #160

Closed arichardson closed 6 years ago

arichardson commented 6 years ago

Migrated from CTSRD-CHERI/llvm#252:

While hacking on libcheri locally, adding new use of __cheri_cast:

===> lib/libcheri (obj,all,install)
/home/rnw24/sdk256/sdk/bin/clang -g -integrated-as --target=cheri-unknown-freebsd  -msoft-float --sysroot=/home/rnw24/obj/mips.mips64/home/rnw24/git/cheribsd/tmp -Wno-deprecated-declarations -ftls-model=local-exec -g -ftls-model=initial-exec -O -pipe -I/home/rnw24/git/cheribsd/lib/libcheri -I/home/rnw24/git/cheribsd/lib/libcheri/mips64 -mllvm -mxmxgot -I/home/rnw24/git/cheribsd/lib/libcheri/../libc/include  -I/home/rnw24/git/cheribsd/lib/libcheri/../libc/locale -G0 -EB -mabi=64 -msoft-float    -MD  -MF.depend.cheri_ccall.o -MTcheri_ccall.o -std=gnu99 -Wsystem-headers -Wall -Wno-format-y2k -W -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wunused-parameter -Wcast-align -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -Wold-style-definition -Wno-pointer-sign -Wmissing-variable-declarations -Wthread-safety -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable  -Qunused-arguments  -c /home/rnw24/git/cheribsd/lib/libcheri/cheri_ccall.c  -o cheri_ccall.o
fatal error: error in backend: Cannot select: 0x80606c6e8: iFATPTR = bitcast
      0x80606cb60
  0x80606cb60: i64,ch = CopyFromReg 0x806325438, Register:i64 %vreg1
    0x8060686e8: i64 = Register %vreg1
In function: cheri_sandbox_make_sealed_invoke_object
clang-5.0: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 5.0.0 (https://github.com/CTSRD-CHERI/clang 93e490fea128c0d86b8b46c1b87a2771dc6d48c5) (http://github.com/CTSRD-CHERI/llvm 70b462defcb7cce1a3994008b2459916d92e1c4c)
Target: cheri-unknown-freebsd
Thread model: posix
InstalledDir: /home/rnw24/sdk256/sdk/bin
clang-5.0: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script.
clang-5.0: note: diagnostic msg: 
********************

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

********************
*** Error code 70

Stop.

cheri_ccall-aeeaf9.sh: https://gist.github.com/rwatson/2a00269b563ba539f14267283eea8739

cheri_ccall-aeeaf9.c: https://gist.github.com/rwatson/4e9ccabfb8cdfdb9cd37b4468dd1998c

arichardson commented 6 years ago

Reduced test case:

// RUN: %cheri_cc1 -emit-obj -mrelocation-model pic -pic-level 2 -mthread-model posix -target-abi n64 -mllvm -mips-ssection-threshold=0 -sys-header-deps -O2 -std=gnu99 -fconst-strings -ftls-model=initial-exec -fcolor-diagnostics -vectorize-loops -vectorize-slp -cheri-linker -mllvm -mxmxgot -x c -o - -O0 -emit-llvm %s
struct a;
b(struct a *);
b(__capability struct a *c) {}
arichardson commented 6 years ago

Is there a function in that file declared with a pointer parameter and defined with __capability qualified parameter?

arichardson commented 6 years ago

cheri_ccall.h:

struct cheri_object cheri_sandbox_make_sealed_invoke_object(
                struct sandbox_object *sbop);
struct cheri_object cheri_sandbox_make_sealed_rtld_object(
                struct sandbox_object *sbop);

cheri_ccall.c:

struct cheri_object
cheri_sandbox_make_sealed_invoke_object(
    __capability struct sandbox_object *sbop)
{
...
}

struct cheri_object
cheri_sandbox_make_sealed_rtld_object(
    __capability struct sandbox_object *sbop)
{
...
}
rwatson commented 6 years ago

Yes -- fixed in my local checkout and about to rebuild with that fixed.

khilangudka commented 6 years ago

Fixed in 80c3585410e1ddf6c0d2c934db058544c5e15616.