diff --git a/.gitignore b/.gitignore index 6245cc2..5b77a52 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ *.o -a.out \ No newline at end of file +a.out + +# Directories +output/ diff --git a/02-segfault/Makefile b/02-segfault/Makefile new file mode 100644 index 0000000..499ef08 --- /dev/null +++ b/02-segfault/Makefile @@ -0,0 +1,73 @@ +#******************************************************************************* +# xxx Co., Ltd. All Right Reserved. +# Author : yegaoyang@hikvision.com.cn +# Version : V1.0.0 202x.xx.xx +# Description : +# Note : +#******************************************************************************* + +#******************************************************************************* +# Target name +#******************************************************************************* +TARGET_NAME = test_segfault + +#******************************************************************************* +# Source and oject files +#******************************************************************************* +OBJS := segfault.o + +#******************************************************************************* +# Path information +#******************************************************************************* +LOCAL_DIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) + +# Subdirectory +# Output +OUTPUT_DIR := $(LOCAL_DIR)/output +INSTALL_DIR ?= $(LOCAL_DIR)/__install +#$(info Output directoty : $(OUTPUT_DIR)) +#$(info Install directoty: $(INSTALL_DIR)) + +#******************************************************************************* +# Compile configure +#******************************************************************************* + +# Toolchain +CROSS_COMPILE ?= /home/gaoyang3513/Source/06-SG20x/02-Projects/SDK_SG200x_DuoS/host-tools/gcc/riscv64-linux-musl-x86_64/bin/riscv64-unknown-linux-musl- + +CC := $(CROSS_COMPILE)gcc +LD := $(CROSS_COMPILE)ld +AR := $(CROSS_COMPILE)ar +STRIP := $(CROSS_COMPILE)strip + +# Falgs +CFLAGS := -Wall -O2 -DUSER_API -g +LDFLAGS := -static +ARFLAGS := + +#******************************************************************************* +# Variables +#******************************************************************************* +MULTI_CORES ?= $(shell grep -c ^processor /proc/cpuinfo) + +#******************************************************************************* +# Targets +#******************************************************************************* +# Specify suffix names and pseudo-targets +.SUFFIXES: .c,.o +.PHONY: all clean checkenv $(TARGET_NAME) + +all: checkenv $(TARGET_NAME) + +clean: + @rm -rf $(OBJS) $(TARGET_NAME) + +checkenv: + @mkdir -p $(OUTPUT_DIR) + +$(TARGET_NAME):$(OBJS) + @$(CC) -o $(OUTPUT_DIR)/$@ $^ $(LDFLAGS) + @chmod +x $(OUTPUT_DIR)/$@ + +%.o:%.c + @$(CC) -o $@ -c $< $(CFLAGS) diff --git a/02-segfault/segfault.c b/02-segfault/segfault.c new file mode 100644 index 0000000..6605266 --- /dev/null +++ b/02-segfault/segfault.c @@ -0,0 +1,7 @@ +#include + +int main() { + int *ptr = NULL; // 初始化一个指向NULL的指针 + *ptr = 1; // 尝试写入NULL指针引用的地址,这将导致段错误 + return 0; +} \ No newline at end of file