How to use the optimized pass of clang?

I want to see the impact of each optimization pass on the performance of the programs compiled by Clang. So I chose CoreMark as the test program. The compilation rules in Makefile are modified as follows:

$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
        $(CC) -emit-llvm  $(CFLAGS) -c  $< -o $@.bc
        opt $@.bc  -sroa  -o $@1.bc
        llc -march=riscv32 -filetype=obj $@1.bc -o $@

$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
        $(CC) $(OBJECTS) $(LDFLAGS) -o $@
        $(SZ) $@

Although it can be successfully compiled into an executable program, the program cannot run correctly.Can you tell me whether the problem is that the Makefile is not written correctly or that pass cannot be used alone?

My guess would be opt is using a nonsense datalayout string and thus thinks pointers are the wrong size. Pass whatever $(CC) -emit-llvm $(CFLAGS) -x c -S -o - /dev/null | grep datalayout prints via opt --data-layout=... and see if that helps.

Though I’ll note that looking at individual optimisation passes may not be particularly insightful, as many of them rely on others to have already run (e.g. if you haven’t run SROA or mem2reg then InstCombine will be pretty useless).