-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_module.sh
More file actions
executable file
·52 lines (37 loc) · 1.23 KB
/
build_module.sh
File metadata and controls
executable file
·52 lines (37 loc) · 1.23 KB
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
#!/bin/bash
set -e
MODULE_NAME="$1"
TARGET="$2"
MODULE_BUILD_DIR="$3"
BUILD_DIR="$4"
LD_COMMAND="$5"
if [ -z "$MODULE_NAME" ] || [ -z "$TARGET" ] || [ -z "$MODULE_BUILD_DIR" ]; then
echo "Usage: $0 <module_name> <target> <module_build_dir> <build_dir> <ld_command>"
exit 1
fi
BUILD_DIR="${BUILD_DIR:=target}"
LD_COMMAND="${LD_COMMAND:=ld}"
lib_path="${MODULE_BUILD_DIR}/lib${MODULE_NAME}.rlib"
if [ ! -f "$lib_path" ]; then
echo "Error: Library not found: $lib_path"
exit 1
fi
lib_path_abs="$(cd "$(dirname "$lib_path")" && pwd)/$(basename "$lib_path")"
output_ko="${BUILD_DIR}/${MODULE_NAME}/${MODULE_NAME}.ko"
mkdir -p "$(dirname "$output_ko")"
echo "Linking kernel module $MODULE_NAME..."
echo "Linking --whole-archive $lib_path to $output_ko"
# no-pie: Position Independent Executable is not supported in kernel modules
LD_FLAGS="--strip-debug --build-id=none --gc-sections -no-pie"
$LD_COMMAND -r -T linker.ld -o "$output_ko" --whole-archive $lib_path_abs $LD_FLAGS
if [ $? -ne 0 ]; then
echo "Failed to create kernel module for $MODULE_NAME"
exit 1
fi
if [ -f "$output_ko" ]; then
echo "Successfully created kernel module: $output_ko"
else
echo "Error: Kernel module file was not created"
exit 1
fi
exit 0