Skip to content

Commit 75b9451

Browse files
authored
Merge pull request #5 from retrage/parameterized-build
build: Introduce Parameterize Build
2 parents 4f3965a + 3696a48 commit 75b9451

File tree

5 files changed

+56
-21
lines changed

5 files changed

+56
-21
lines changed

.github/workflows/build.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,25 @@ jobs:
1919
DEBIAN_FRONTEND=noninteractive sudo apt update -y
2020
DEBIAN_FRONTEND=noninteractive sudo apt install -y build-essential gcc-aarch64-linux-gnu clang-format
2121
- name: Build
22+
env:
23+
CC: aarch64-linux-gnu-gcc
24+
FULL_CONTEXT: 0
25+
SYSCALL_RECORD: 0
2226
run: |
23-
CC=aarch64-linux-gnu-gcc make
24-
CC=aarch64-linux-gnu-gcc make -C apps/basic
27+
make clean
28+
make -C apps/basic clean
29+
make
30+
make -C apps/basic
31+
- name: Build
32+
env:
33+
CC: aarch64-linux-gnu-gcc
34+
FULL_CONTEXT: 1
35+
SYSCALL_RECORD: 1
36+
run: |
37+
make clean
38+
make -C apps/basic clean
39+
make
40+
make -C apps/basic
2541
- name: Format
2642
run: |
2743
make fmt

Makefile

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
1+
#!/usr/bin/env make
2+
# SPDX-License-Identifier: Apache-2.0
3+
# Copyright (C) 2025 Akira Moroo
4+
15
PROGS = libsvchook.so
26

3-
CC ?= gcc
47
CLANG_FORMAT ?= clang-format
58

69
CLEANFILES = $(PROGS) *.o *.d
710

8-
SRCDIR ?= ./
9-
10-
NO_MAN=
11-
CFLAGS = -O3 -pipe
11+
CFLAGS = -O3
12+
CFLAGS += -pipe
1213
CFLAGS += -g
13-
CFLAGS += -DMINIMAL_CONTEXT
14-
CFLAGS += -Werror -Wall -Wunused-function
14+
CFLAGS += -Werror
15+
CFLAGS += -Wall
16+
CFLAGS += -Wunused-function
1517
CFLAGS += -Wextra
1618
CFLAGS += -fPIC
1719

18-
LDFLAGS += -shared -rdynamic -ldl
20+
ifeq ($(FULL_CONTEXT), 1)
21+
CFLAGS += -DFULL_CONTEXT
22+
endif
23+
24+
ifeq ($(SYSCALL_RECORD), 1)
25+
CFLAGS += -DSUPPLEMENTAL__SYSCALL_RECORD
26+
endif
27+
28+
LDFLAGS += -shared
29+
LDFLAGS += -rdynamic
30+
LDFLAGS += -ldl
1931

2032
C_SRCS = main.c
2133
OBJS = $(C_SRCS:.c=.o)

apps/basic/Makefile

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
#!/usr/bin/env make
2+
# SPDX-License-Identifier: Apache-2.0
3+
# Copyright (C) 2025 Akira Moroo
4+
15
PROGS = libsvchook_basic.so
26

3-
CC ?= gcc
47
CLANG_FORMAT ?= clang-format
58

69
CLEANFILES = $(PROGS) *.o *.d
710

8-
SRCDIR ?= ./
9-
10-
NO_MAN=
11-
CFLAGS = -O3 -pipe
12-
CFLAGS += -Werror -Wall -Wunused-function
11+
CFLAGS = -O3
12+
CFLAGS += -pipe
13+
CFLAGS += -Werror
14+
CFLAGS += -Wall
15+
CFLAGS += -Wunused-function
1316
CFLAGS += -Wextra
1417
CFLAGS += -fPIC
1518

@@ -18,7 +21,6 @@ LDFLAGS += -shared
1821
C_SRCS = main.c
1922
OBJS = $(C_SRCS:.c=.o)
2023

21-
.PHONY: all
2224
all: $(PROGS)
2325

2426
$(PROGS): $(OBJS)
@@ -29,3 +31,5 @@ clean:
2931

3032
fmt:
3133
$(CLANG_FORMAT) -i $(C_SRCS)
34+
35+
.PHONY: all clean fmt

apps/basic/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (C) 2025 Akira Moroo
3+
14
#include <stdio.h>
25

36
typedef long (*syscall_fn_t)(long, long, long, long, long, long, long, long);

main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
// Copyright (C) 2024 Akira Moroo
2+
// Copyright (C) 2024-2025 Akira Moroo
33

44
#ifndef _GNU_SOURCE
55
#define _GNU_SOURCE
@@ -52,8 +52,7 @@ extern long enter_syscall(int64_t, int64_t, int64_t, int64_t, int64_t, int64_t,
5252
int64_t, int64_t);
5353
extern void asm_syscall_hook(void);
5454

55-
#ifdef MINIMAL_CONTEXT
56-
/* MINIMAL_CONTEXT will improve performance */
55+
#ifndef FULL_CONTEXT
5756
#define CONTEXT_SIZE 64
5857
// clang-format off
5958
#define __OP_CONTEXT(op, reg) \
@@ -64,6 +63,7 @@ extern void asm_syscall_hook(void);
6463
// clang-format on
6564
#else
6665
#define CONTEXT_SIZE 256
66+
/* FULL_CONTEXT saves all registers, but may decrease the performance. */
6767
// clang-format off
6868
#define __OP_CONTEXT(op, reg) \
6969
#op " xzr, x1, [" #reg ",#0] \n\t" \
@@ -83,7 +83,7 @@ extern void asm_syscall_hook(void);
8383
#op " x28, x29, [" #reg ",#224] \n\t" \
8484
#op " x30, xzr, [" #reg ",#240] \n\t"
8585
// clang-format on
86-
#endif /* !MINIMAL_CONTEXT */
86+
#endif /* FULL_CONTEXT */
8787

8888
#define SAVE_CONTEXT(reg) __OP_CONTEXT(stp, reg)
8989
#define RESTORE_CONTEXT(reg) __OP_CONTEXT(ldp, reg)

0 commit comments

Comments
 (0)