CHERIoT-Platform / llvm-project

Fork of LLVM adding CHERIoT, based on the CHERI LLVM fork
4 stars 6 forks source link

segfault compiling opentitan #30

Closed sleffler closed 5 months ago

sleffler commented 5 months ago

While building opentitan w/ changes to support cheriot the compiler segfaulted and left the attached[*] artifacts for debug. I tried running creduce_crash_testcase.py but it failed w/ a missing python dep.

Target: riscv32-unknown-unknown-elf                                                                                                                                                                                                      
Thread model: posix                                                                                                                                                                                                                      
InstalledDir: /proc/self/cwd/external/cheri_llvm_files/cheriot-tools/bin                                                                                                                                                                 

The toolchain was built with this:

$(TOOLCHAIN_CHERIOT_BIN): | toolchain_cheriot_src $(TOOLCHAIN_CHERIOT_BUILD_DIR)
  cmake -B $(TOOLCHAIN_CHERIOT_BUILD_DIR) \
    -DCMAKE_INSTALL_PREFIX=$(TOOLCHAIN_CHERIOT_OUT_DIR) \
    -DCMAKE_BUILD_TYPE=Release \
    -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;libc" \
    -DLLVM_ENABLE_UNWIND_TABLES=NO \
    -DLLVM_TARGETS_TO_BUILD=RISCV \
    -DLLVM_DISTRIBUTION_COMPONENTS="clang;clangd;lld;llvm-ar;llvm-objdump" \
    -G Ninja \
    $(TOOLCHAIN_CHERIOT_SRC_DIR)/llvm
  cmake --build $(TOOLCHAIN_CHERIOT_BUILD_DIR) --target install-distribution
  cmake --build $(TOOLCHAIN_CHERIOT_BUILD_DIR) --target install-clang-resource-headers

OpenTitan code base is found here and here (but likely not super useful w/o pending changes)

[*] Can't seem to attach the tgz with the .sh and .c; please contact me for them.

sleffler commented 5 months ago

This appears to be directly related to weak symbol refs. If I eliminate the weak symbols the compiler does not fault.

davidchisnall commented 5 months ago

Can you attach the preprocessed source and the command line that triggers the crash? Clang tries to dump the preprocessed source when it crashes, but if that fails then adding -E to the compile command that crashes will emit it instead of crashing.

davidchisnall commented 5 months ago

dif_spi_host-bf4412.c.txt

# Crash reproducer for clang version 13.0.0 (https://github.com/CHERIoT-Platform/llvm-project d9aec906237445b49cbcd135058422aae519eb95)
# Driver args: "-MD" "-MF" "bazel-out/k8-fastbuild/bin/external/lowrisc_opentitan/sw/device/lib/dif/_objs/spi_host/dif_spi_host.d" "-frandom-seed=bazel-out/k8-fastbuild/bin/external/lowrisc_opentitan/sw/device/lib/dif/_objs/spi_host/dif_spi_host.o" "-D" "BAZEL_CURRENT_REPOSITORY=\"lowrisc_opentitan\"" "-iquote" "external/lowrisc_opentitan" "-iquote" "bazel-out/k8-fastbuild/bin/external/lowrisc_opentitan" "-I" "bazel-out/k8-fastbuild/bin/external/lowrisc_opentitan/hw/ip/spi_host/data" "-nostdinc" "-isystem" "external/cheri_llvm_files/cheriot-tools/lib/clang/13.0.0/include" "-isystem" "external/cheri_llvm_files/cheriot-tools/riscv32-unknown-elf/include" "-march=rv32imcxcheri" "-mcpu=cheriot" "-mabi=cheriot" "-mcmodel=medium" "-mlittle-endian" "--target=riscv32-unknown-elf" "-mxcheri-rvc" "-mrelax" "-Werror=date-time" "-ffunction-sections" "-fdata-sections" "-Os" "-g" "-ffreestanding" "-fno-common" "-std=gnu11" "-c" "external/lowrisc_opentitan/sw/device/lib/dif/dif_spi_host.c" "-o" "bazel-out/k8-fastbuild/bin/external/lowrisc_opentitan/sw/device/lib/dif/_objs/spi_host/dif_spi_host.o"
# Original command:  "/usr/local/google/home/sleffler/.cache/bazel/_bazel_sleffler/5976c4ae1c91f7ea1c68ea9183862c32/external/cheri_llvm_files/cheriot-tools/bin/clang-13" "-cc1" "-triple" "riscv32-unknown-unknown-elf" "-emit-obj" "--mrelax-relocations" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "dif_spi_host.c" "-mrelocation-model" "static" "-mframe-pointer=none" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-fno-verbose-asm" "-mconstructor-aliases" "-ffreestanding" "-nostdsysteminc" "-mcmodel=medium" "-target-cpu" "cheriot" "-target-feature" "+m" "-target-feature" "+c" "-target-feature" "+xcheri" "-target-feature" "-64bit" "-target-feature" "+relax" "-target-feature" "-save-restore" "-target-feature" "+xcheri-rvc" "-target-abi" "cheriot" "-msmall-data-limit" "8" "-debug-info-kind=constructor" "-dwarf-version=4" "-debugger-tuning=gdb" "-ffunction-sections" "-fdata-sections" "-fcoverage-compilation-dir=/proc/self/cwd" "-nostdsysteminc" "-nobuiltininc" "-resource-dir" "/usr/local/google/home/sleffler/.cache/bazel/_bazel_sleffler/5976c4ae1c91f7ea1c68ea9183862c32/external/cheri_llvm_files/cheriot-tools/lib/clang/13.0.0" "-dependency-file" "bazel-out/k8-fastbuild/bin/external/lowrisc_opentitan/sw/device/lib/dif/_objs/spi_host/dif_spi_host.d" "-MT" "bazel-out/k8-fastbuild/bin/external/lowrisc_opentitan/sw/device/lib/dif/_objs/spi_host/dif_spi_host.o" "-sys-header-deps" "-iquote" "external/lowrisc_opentitan" "-iquote" "bazel-out/k8-fastbuild/bin/external/lowrisc_opentitan" "-isystem" "external/cheri_llvm_files/cheriot-tools/lib/clang/13.0.0/include" "-isystem" "external/cheri_llvm_files/cheriot-tools/riscv32-unknown-elf/include" "-D" "BAZEL_CURRENT_REPOSITORY=\"lowrisc_opentitan\"" "-I" "bazel-out/k8-fastbuild/bin/external/lowrisc_opentitan/hw/ip/spi_host/data" "-Os" "-Werror=date-time" "-std=gnu11" "-fdebug-compilation-dir=/proc/self/cwd" "-ferror-limit" "19" "-fno-signed-char" "-fgnuc-version=4.2.1" "-vectorize-loops" "-vectorize-slp" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "bazel-out/k8-fastbuild/bin/external/lowrisc_opentitan/sw/device/lib/dif/_objs/spi_host/dif_spi_host.o" "-x" "c" "external/lowrisc_opentitan/sw/device/lib/dif/dif_spi_host.c"
 "/usr/local/google/home/sleffler/.cache/bazel/_bazel_sleffler/5976c4ae1c91f7ea1c68ea9183862c32/external/cheri_llvm_files/cheriot-tools/bin/clang-13" "-cc1" "-triple" "riscv32-unknown-unknown-elf" "-emit-obj" "--mrelax-relocations" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "dif_spi_host.c" "-mrelocation-model" "static" "-mframe-pointer=none" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-fno-verbose-asm" "-mconstructor-aliases" "-ffreestanding" "-nostdsysteminc" "-mcmodel=medium" "-target-cpu" "cheriot" "-target-feature" "+m" "-target-feature" "+c" "-target-feature" "+xcheri" "-target-feature" "-64bit" "-target-feature" "+relax" "-target-feature" "-save-restore" "-target-feature" "+xcheri-rvc" "-target-abi" "cheriot" "-msmall-data-limit" "8" "-debug-info-kind=constructor" "-dwarf-version=4" "-debugger-tuning=gdb" "-ffunction-sections" "-fdata-sections" "-fcoverage-compilation-dir=/proc/self/cwd" "-nostdsysteminc" "-nobuiltininc" "-sys-header-deps" "-D" "BAZEL_CURRENT_REPOSITORY=\"lowrisc_opentitan\"" "-Os" "-Werror=date-time" "-std=gnu11" "-fdebug-compilation-dir=/proc/self/cwd" "-ferror-limit" "19" "-fno-signed-char" "-fgnuc-version=4.2.1" "-vectorize-loops" "-vectorize-slp" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c" "dif_spi_host-bf4412.c"
davidchisnall commented 5 months ago

The crash is in lowering the following GlobalAddress node as a callee:

t25: iFATPTR64 = GlobalAddress<i32 (%struct.dif_spi_host addrspace(200)*, i8 addrspace(200)*, i16) addrspace(200)* @spi_host_fifo_write_alias> 0, external/lowrisc_opentitan/sw/device/lib/dif/dif_spi_host.c:341:7 @[ external/lowrisc_opentitan/sw/device/lib/dif/dif_spi_host.c:385:30 ]

The global that this wraps is:

@spi_host_fifo_write_alias = weak dso_local alias i32 (%struct.dif_spi_host addrspace(200)*, i8 addrspace(200)*, i16), i32 (%struct.dif_spi_host addrspace(200)*, i8 addrspace(200)*, i16) addrspace(200)* @dif_spi_host_fifo_write

We are missing a case in the back end for handling calling GlobalAliases.