hello,
While I am trying to execute a simple bubble sort program in c as provided as an example in the arm development studio IDE, I am facing 3 errors like as shown below: (Target and source must be capability)
/bubblesort.c:45:37: error: invalid target type 'uint32_t *' (aka 'unsigned int *') for __cheri_tocap: target must be a capability seq_t sequence = (__cheri_tocap seq_t)malloc(sizeof(uint32_t) * SEQ_LEN);
../bubblesort.c:57:33: error: invalid source type 'uint32_t *' (aka 'unsigned int *') for __cheri_fromcap: source must be a capability free((__cheri_fromcap void*)sequence);
/bubblesort.c:70:6: error: conflicting types for 'print'void print (seq_t __cheri_input sequence, int size) {
N.B: I am using LLVM 13.0.0 with Morello support.
Like before, this code builds fine on Compiler Explorer (latest Morello LLVM):
https://cheri-compiler-explorer.cl.cam.ac.uk/z/5Ys3Pz
I suspect you are not actually enabling Morello, causing cheri.h to #define __capability to nothing. Make sure to pass -march=morello to Clang.
-march=morello
Many thanks, Kevin, by introducing this the above error got removed however it introduced another error which failed to identify few functions as denoted by this below:
ld.lld: error: undefined symbol: malloc >>> referenced by bubblesort_cam.c:123 >>> bubblesort_cam.o:(main) ld.lld: error: undefined symbol: time >>> referenced by bubblesort_cam.c:141 >>> bubblesort_cam.o:(main) >>> referenced by bubblesort_cam.c:141 >>> bubblesort_cam.o:(populate) ld.lld: error: undefined symbol: srand >>> referenced by bubblesort_cam.c:141 >>> bubblesort_cam.o:(main) >>> referenced by bubblesort_cam.c:141 >>> bubblesort_cam.o:(populate) ld.lld: error: undefined symbol: rand >>> referenced by bubblesort_cam.c:144 >>> bubblesort_cam.o:(main) >>> referenced by bubblesort_cam.c:144 >>> bubblesort_cam.o:(main) >>> referenced by bubblesort_cam.c:144 >>> bubblesort_cam.o:(main) >>> referenced 13 more times ld.lld: error: undefined symbol: free >>> referenced by bubblesort_cam.c:135 >>> bubblesort_cam.o:(main)
Sorry for the delay. It appears that the instructions do not link in libc, as LLD is directly used to link. I wonder if linking with Clang and simply specifying the base address instead of a linker script wouldn't be sufficient. That is, replace the call to ld.lld with:
<absolute path of toolchain>/bin/clang -target aarch64-none-elf -o helloworld helloworld.o -Wl,--image-base,0xe0000000
This links fine for me, but I haven't actually tested it. Let me know if it works for you, and if so I'll make sure to get the instructions updated.
Hello Kevin,
Many thanks for the help. I have enclosed the compilation script below which I am following after making the amendments you suggested. Can you please have a look if it makes sense. However, during compilation I am getting the linking error:
ld.lld: error: bubblesort_cam.o: cannot link object files with different EF_AARCH64_CHERI_PURECAPclang: error: ld.lld command failed with exit code 1 (use -v to see invocation)
# COMPILATION SCRIPT # Script based on instructions from: # https://git.morello-project.org/morello/docs/-/blob/morello/release-1.6/standalone-baremetal-readme.rst # First argument = program name (must match basename of .c file) PROGRAM_NAME=$1 PWD=`pwd` TOOLCHAIN=/opt/llvm-project-releases-morello-baremetal-release-1.6 ################################################ # COMPILE PROGRAM #new technique $TOOLCHAIN/bin/clang -target aarch64-none-elf -march=morello+c64 -mabi=purecap -c $PROGRAM_NAME.c -o $PROGRAM_NAME.o -O3 -g $TOOLCHAIN/bin/clang -target aarch64-none-elf -o $PROGRAM_NAME $PROGRAM_NAME.o -Wl,--image-base,0xe0000000 $TOOLCHAIN/bin/llvm-objcopy -O binary $PROGRAM_NAME.elf $PROGRAM_NAME ################################################ # OUTPUT OBJDUMP (disassembly) $TOOLCHAIN/bin/llvm-objdump -sSD $PROGRAM_NAME.elf > $PROGRAM_NAME.objdump
Hi Sanu, almost there :) Your example is not purecap, it is hybrid, since you use capabilities explicitly. You should keep just -march=morello (and no -mabi) in the compiler flags, like before.
Many thanks, Kevin for helping me to reach almost the end I believe. It compiled and created the object file in line number 23 and 24 of the compilation script. However, at line 25 I think it's not able to generate and hence identify the corresponding elf and hence it is throwing the error shown below: I have enclosed the compilation script also.
/opt/llvm-project-releases-morello-baremetal-release-1.6/bin/llvm-objcopy: error: 'bubblesort.elf': No such file or directory
# COMPILATION SCRIPT # Script based on instructions from: # https://git.morello-project.org/morello/docs/-/blob/morello/release-1.6/standalone-baremetal-readme.rst # First argument = program name (must match basename of .c file) PROGRAM_NAME=$1 PWD=`pwd` TOOLCHAIN=/opt/llvm-project-releases-morello-baremetal-release-1.6 ################################################ # COMPILE PROGRAM #new technique $TOOLCHAIN/bin/clang -target aarch64-none-elf -march=morello -c $PROGRAM_NAME.c -o $PROGRAM_NAME.o -O3 -g $TOOLCHAIN/bin/clang -target aarch64-none-elf -o $PROGRAM_NAME $PROGRAM_NAME.o -Wl,--image-base,0xe0000000 $TOOLCHAIN/bin/llvm-objcopy -O binary $PROGRAM_NAME.elf $PROGRAM_NAME # #
llvm-objcopy takes the input as first argument, and optionally the output as second argument (see the man page). Looks like they're swapped.
Many thanks, Kevin. What I noticed is that in line number 24 as compared to my previous code instead of $PROGRAM_NAME, if I replace it with $PROGRAM_NAME.elf after -o, there itself the elf is getting generated. However, is there are any need to run line 25 to generate the elf then..with the llvm-objcopy? Or what is the purpose of executing line 25 please?
# COMPILATION SCRIPT # Script based on instructions from: # https://git.morello-project.org/morello/docs/-/blob/morello/release-1.6/standalone-baremetal-readme.rst # First argument = program name (must match basename of .c file) PROGRAM_NAME=$1 PWD=`pwd` TOOLCHAIN=/opt/llvm-project-releases-morello-baremetal-release-1.6 ################################################ # COMPILE PROGRAM #new technique $TOOLCHAIN/bin/clang -target aarch64-none-elf -march=morello -c $PROGRAM_NAME.c -o $PROGRAM_NAME.o -O3 -g $TOOLCHAIN/bin/clang -target aarch64-none-elf -o $PROGRAM_NAME.elf $PROGRAM_NAME.o -Wl,--image-base,0xe0000000 #$TOOLCHAIN/bin/llvm-objcopy -O binary $PROGRAM_NAME.elf $PROGRAM_NAME # #
Your new version is correct. Using llvm-objcopy is required to generate a raw binary that can be used as non-secure payload, as suggested in the instructions. You cannot directly use an ELF executable as payload.
Many thanks, Kevin for the information. Once I apply the script to generate the elf as shown in line no 25 (script shown below), the elf is generating but I am not sure once I try to view the elf file by right-clicking and viewing through the elf content editor it displays that it is not a valid elf file.
# COMPILATION SCRIPT # Script based on instructions from: # https://git.morello-project.org/morello/docs/-/blob/morello/release-1.6/standalone-baremetal-readme.rst # First argument = program name (must match basename of .c file) PROGRAM_NAME=$1 PWD=`pwd` TOOLCHAIN=/opt/llvm-project-releases-morello-baremetal-release-1.6 ################################################ # COMPILE PROGRAM #new technique $TOOLCHAIN/bin/clang -target aarch64-none-elf -march=morello -c $PROGRAM_NAME.c -o $PROGRAM_NAME.o -O3 -g $TOOLCHAIN/bin/clang -target aarch64-none-elf -o $PROGRAM_NAME $PROGRAM_NAME.o -Wl,--image-base,0xe0000000 $TOOLCHAIN/bin/llvm-objcopy -O binary $PROGRAM_NAME $PROGRAM_NAME.elf # #
ok so is this version correct? changed line 24 with $PROGRAM_NAME.elf after -o and in line 25 used $PROGRAM_NAME.elf as first argument instead of the second as shown below.
_
# COMPILATION SCRIPT # Script based on instructions from: # https://git.morello-project.org/morello/docs/-/blob/morello/release-1.6/standalone-baremetal-readme.rst # First argument = program name (must match basename of .c file) PROGRAM_NAME=$1 PWD=`pwd` TOOLCHAIN=/opt/llvm-project-releases-morello-baremetal-release-1.6 ################################################ # COMPILE PROGRAM #new technique $TOOLCHAIN/bin/clang -target aarch64-none-elf -march=morello -c $PROGRAM_NAME.c -o $PROGRAM_NAME.o -O3 -g $TOOLCHAIN/bin/clang -target aarch64-none-elf -o $PROGRAM_NAME.elf $PROGRAM_NAME.o -Wl,--image-base,0xe0000000 $TOOLCHAIN/bin/llvm-objcopy -O binary $PROGRAM_NAME.elf $PROGRAM_NAME # #