File: Makefile

package info (click to toggle)
drgn 0.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 7,852 kB
  • sloc: python: 74,992; ansic: 54,589; awk: 423; makefile: 351; sh: 99
file content (65 lines) | stat: -rw-r--r-- 1,991 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: LGPL-2.1-or-later

# Makefile used to generate tests/resources/crashme*

.PHONY: all cores clean

.DELETE_ON_ERROR:

EXECUTABLES := crashme crashme_pie crashme_static crashme_static_pie
CORES := $(addsuffix .core, $(EXECUTABLES)) $(addsuffix _no_headers.core, $(EXECUTABLES))
BINARIES := crashme.so $(EXECUTABLES) crashme.dwz crashme.so.dwz crashme.alt
ZSTD_BINARIES := $(addsuffix .zst, $(BINARIES))
ZSTD_CORES := $(addsuffix .zst, $(CORES))

all: $(BINARIES) cores $(ZSTD_BINARIES) $(ZSTD_CORES)

clean:
	rm -f $(BINARIES) $(CORES) $(ZSTD_BINARIES) $(ZSTD_CORES)

crashme.so: crashme.c common.c
	gcc -g -Os -fpic -shared $^ -o $@

crashme: main.c common.c crashme.so
	gcc -g -Os -fno-pie -no-pie $(filter-out crashme.so,$^) -o $@ -L . -l:crashme.so -Wl,-rpath,$(CURDIR)

crashme_pie: main.c common.c crashme.so
	gcc -g -Os -fpie -pie $(filter-out crashme.so,$^) -o $@ -L . -l:crashme.so -Wl,-rpath,$(CURDIR)

crashme_static: main.c common.c crashme.c
	musl-gcc -g -Os -fno-pie -static $^ -o $@

crashme_static_pie: main.c common.c crashme.c
	musl-gcc -g -Os -fpie -static-pie $^ -o $@

crashme.dwz crashme.so.dwz crashme.alt &: crashme crashme.so
	cp crashme crashme.dwz
	cp crashme.so crashme.so.dwz
	dwz -m crashme.alt -r crashme.dwz crashme.so.dwz

cores: $(CORES)

.NOTPARALLEL: cores

define CORE_COMMAND
flock /proc/sys/kernel/core_pattern sh -e -c '\
ulimit -c unlimited; \
echo "$$COREDUMP_FILTER" > /proc/$$$$/coredump_filter; \
old_pattern=$$(cat /proc/sys/kernel/core_pattern); \
restore_core_pattern() { \
	echo "$$old_pattern" > /proc/sys/kernel/core_pattern; \
}; \
trap restore_core_pattern EXIT; \
echo "$$PWD/core.%p" > /proc/sys/kernel/core_pattern; \
su "$$SUDO_USER" -c "env -i sh -l -c \"exec ./$<\" & wait; mv core.\$$! $@"'
endef

%.core: %
	sudo env COREDUMP_FILTER=0x33 $(CORE_COMMAND)

%_no_headers.core: %
	sudo env COREDUMP_FILTER=0x23 $(CORE_COMMAND)

%.zst: %
	zstd -19 $< -o $@