| 1 |
# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
|
| 4 |
# Makefile used to generate tests/resources/crashme* |
| 5 |
|
| 6 |
.PHONY: all cores clean |
| 7 |
|
| 8 |
.DELETE_ON_ERROR: |
| 9 |
|
| 10 |
EXECUTABLES := crashme crashme_pie crashme_static crashme_static_pie |
| 11 |
CORES := $(addsuffix .core, $(EXECUTABLES)) $(addsuffix _no_headers.core, $(EXECUTABLES)) |
| 12 |
BINARIES := crashme.so $(EXECUTABLES) crashme.dwz crashme.so.dwz crashme.alt |
| 13 |
ZSTD_BINARIES := $(addsuffix .zst, $(BINARIES)) |
| 14 |
ZSTD_CORES := $(addsuffix .zst, $(CORES)) |
| 15 |
|
| 16 |
all: $(BINARIES) cores $(ZSTD_BINARIES) $(ZSTD_CORES) |
| 17 |
|
| 18 |
clean: |
| 19 |
rm -f $(BINARIES) $(CORES) $(ZSTD_BINARIES) $(ZSTD_CORES) |
| 20 |
|
| 21 |
crashme.so: crashme.c common.c |
| 22 |
gcc -g -Os -fpic -shared $^ -o $@ |
| 23 |
|
| 24 |
crashme: main.c common.c crashme.so |
| 25 |
gcc -g -Os -fno-pie -no-pie $(filter-out crashme.so,$^) -o $@ -L . -l:crashme.so -Wl,-rpath,$(CURDIR) |
| 26 |
|
| 27 |
crashme_pie: main.c common.c crashme.so |
| 28 |
gcc -g -Os -fpie -pie $(filter-out crashme.so,$^) -o $@ -L . -l:crashme.so -Wl,-rpath,$(CURDIR) |
| 29 |
|
| 30 |
crashme_static: main.c common.c crashme.c |
| 31 |
musl-gcc -g -Os -fno-pie -static $^ -o $@ |
| 32 |
|
| 33 |
crashme_static_pie: main.c common.c crashme.c |
| 34 |
musl-gcc -g -Os -fpie -static-pie $^ -o $@ |
| 35 |
|
| 36 |
crashme.dwz crashme.so.dwz crashme.alt &: crashme crashme.so |
| 37 |
cp crashme crashme.dwz |
| 38 |
cp crashme.so crashme.so.dwz |
| 39 |
dwz -m crashme.alt -r crashme.dwz crashme.so.dwz |
| 40 |
|
| 41 |
cores: $(CORES) |
| 42 |
|
| 43 |
.NOTPARALLEL: cores |
| 44 |
|
| 45 |
define CORE_COMMAND |
| 46 |
flock /proc/sys/kernel/core_pattern sh -e -c '\ |
| 47 |
ulimit -c unlimited; \ |
| 48 |
echo "$$COREDUMP_FILTER" > /proc/$$$$/coredump_filter; \ |
| 49 |
old_pattern=$$(cat /proc/sys/kernel/core_pattern); \ |
| 50 |
restore_core_pattern() { \ |
| 51 |
echo "$$old_pattern" > /proc/sys/kernel/core_pattern; \ |
| 52 |
}; \ |
| 53 |
trap restore_core_pattern EXIT; \ |
| 54 |
echo "$$PWD/core.%p" > /proc/sys/kernel/core_pattern; \ |
| 55 |
su "$$SUDO_USER" -c "env -i sh -l -c \"exec ./$<\" & wait; mv core.\$$! $@"' |
| 56 |
endef |
| 57 |
|
| 58 |
%.core: % |
| 59 |
sudo env COREDUMP_FILTER=0x33 $(CORE_COMMAND) |
| 60 |
|
| 61 |
%_no_headers.core: % |
| 62 |
sudo env COREDUMP_FILTER=0x23 $(CORE_COMMAND) |
| 63 |
|
| 64 |
%.zst: % |
| 65 |
zstd -19 $< -o $@ |