yaobinwen / Linux-Lab

How to create a home lab to study Linux kernal and C/C++ libraries (and possibly everything else).
GNU General Public License v3.0
0 stars 0 forks source link

Learn how to modify the system call `open(2)` #4

Open yaobinwen opened 1 year ago

yaobinwen commented 1 year ago

Description

The ultimate purpose of learning how to modify the system call open(2) is to study its source code so I can figure out under what situation does open(2) return a specific error code.

TODO

yaobinwen commented 1 year ago

Update (2022-12-23)

I modified the code to add my system call hicall but building it ran into make: *** [debian/rules.d/4-checks.mk:4: abi-check-generic] Error 1. See the build log jammy-kernel-build.zip

yaobinwen commented 1 year ago

Update (2022-12-25)

yaobinwen commented 1 year ago

Update (2022-12-26)

Regarding the ABI check failures: Previously, after I modified the code and re-built the kernel, I ran into the following error:

Debug: abi-check-generic
II: abi-check arguments:
$flavour: {generic}
$prev_abinum: {57}
$abinum: {57}
$prev_abidir: {/lab/ubuntu-kernel-jammy/debian.master/abi/amd64}
$abidir: {/lab/ubuntu-kernel-jammy/debian.master/__abi.current/amd64}
$skipabi: {}
II: Checking ABI for generic...
    Reading symbols/modules to ignore...read 0 symbols/modules.
    Reading new symbols (57)...read 26297 symbols.
    Reading old symbols (57)...read 26288 symbols.
II: Checking for missing symbols in new ABI...
    MISS : iscsi_conn_queue_work
    MISS : dynamic_debug_exec_queries
    found 2 missing symbols
EE: Symbols gone missing (what did you do!?!)

Last night, I cleaned up everything and rebuilt the kernel code. The rebuilding succeeded but I noticed there were still missing symbols, but were treated as warnings instead of errors:

Debug: abi-check-generic
II: Checking ABI for generic...
II: Different ABI's, running in no-fail mode
    Reading symbols/modules to ignore...read 0 symbols/modules.
    Reading new symbols (57)...read 26297 symbols.
    Reading old symbols (56)...read 26288 symbols.
II: Checking for missing symbols in new ABI...
    MISS : iscsi_conn_queue_work
    MISS : dynamic_debug_exec_queries
    found 2 missing symbols
WW: Symbols gone missing (what did you do!?!)
II: Checking for new symbols in new ABI...

By trying to run debian/scripts/abi-check directly, I noticed the missing symbols are treated as errors when the previous ABI number and the current ABI number are the same, like 57 vs 57. In my rebuilding, the previous ABI number was 56 and the current ABI number was 57, so the missing symbols were treated as warnings.

This seems to suggest that I should bump the changelog version. But I'm using the version linux (5.15.0-57.63) jammy. Because I'm changing the source code, I think I should bump the source version 5.15.0 to maybe 5.15.1 and change the Debian version 57.63 to 0.0.

If I changed changelog version to 5.15.1-0.0, running LANG=C fakeroot debian/rules binary would encounter the following error:

# Add the tools.
install -d /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.1-0/usr/lib
install -d /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.1-0/usr/lib/linux-tools-5.15.1-0
install -m755 /lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/usb/usbip/bin/sbin/usbip \
    /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.1-0/usr/lib/linux-tools-5.15.1-0
install -m755 /lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/usb/usbip/bin/sbin/usbipd \
    /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.1-0/usr/lib/linux-tools-5.15.1-0
install -m755 /lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/power/acpi/acpidbg \
    /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.1-0/usr/lib/linux-tools-5.15.1-0
install -m755 /lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/power/cpupower/cpupower \
    /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.1-0/usr/lib/linux-tools-5.15.1-0
# Install only the full versioned libcpupower.so.5.15.1-0, not
# the usual symlinks to it.
install -m644 /lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/power/cpupower/libcpupower.so.5.15.1-0 \
    /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.1-0/usr/lib/
install: cannot stat '/lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/power/cpupower/libcpupower.so.5.15.1-0': No such file or directory
make: *** [debian/rules.d/2-binary-arch.mk:770: install-perarch] Error 1

The directory content was:

vagrant@ywen-linux-lab:/lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/power/cpupower$ ls -l
total 416
drwxr-xr-x 1 vagrant vagrant   4096 Dec 12 01:22 bench
-rwxrwxr-x 1 vagrant vagrant 294408 Dec 25 20:10 cpupower
-rw-r--r-- 1 vagrant vagrant   3503 Dec 12 01:22 cpupower-completion.sh
drwxr-xr-x 1 vagrant vagrant   4096 Dec 12 01:22 debug
drwxr-xr-x 1 vagrant vagrant   4096 Dec 25 20:10 lib
lrwxrwxrwx 1 vagrant vagrant     20 Dec 25 20:10 libcpupower.so -> libcpupower.so.0.0.1
-rwxrwxr-x 1 vagrant vagrant  81768 Dec 25 20:10 libcpupower.so.0.0.1
lrwxrwxrwx 1 vagrant vagrant     20 Dec 25 20:10 libcpupower.so.5.15.0-57 -> libcpupower.so.0.0.1
-rw-r--r-- 1 vagrant vagrant  10665 Dec 12 01:22 Makefile
drwxr-xr-x 1 vagrant vagrant   4096 Dec 12 01:22 man
drwxr-xr-x 1 vagrant vagrant   4096 Dec 25 20:10 po
-rw-r--r-- 1 vagrant vagrant   1517 Dec 12 01:22 README
-rw-r--r-- 1 vagrant vagrant   1024 Dec 12 01:22 ToDo
drwxr-xr-x 1 vagrant vagrant   4096 Dec 25 20:10 utils
vagrant@ywen-linux-lab:/lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/power/cpupower$

When I changed changelog version to 5.15.0-58.0, I still ran into the similar error:

# Add the tools.
install -d /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.0-58/usr/lib
install -d /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.0-58/usr/lib/linux-tools-5.15.0-58
install -m755 /lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/usb/usbip/bin/sbin/usbip \
    /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.0-58/usr/lib/linux-tools-5.15.0-58
install -m755 /lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/usb/usbip/bin/sbin/usbipd \
    /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.0-58/usr/lib/linux-tools-5.15.0-58
install -m755 /lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/power/acpi/acpidbg \
    /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.0-58/usr/lib/linux-tools-5.15.0-58
install -m755 /lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/power/cpupower/cpupower \
    /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.0-58/usr/lib/linux-tools-5.15.0-58
# Install only the full versioned libcpupower.so.5.15.0-58, not
# the usual symlinks to it.
install -m644 /lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/power/cpupower/libcpupower.so.5.15.0-58 \
    /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.0-58/usr/lib/
install: cannot stat '/lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/power/cpupower/libcpupower.so.5.15.0-58': No such file or directory
make: *** [debian/rules.d/2-binary-arch.mk:770: install-perarch] Error 1

When I changed changelog version to 5.15.0-57.63+hicall, I still ran into the similar error:

II: Checking ABI for generic...
    Reading symbols/modules to ignore...read 0 symbols/modules.
    Reading new symbols (57)...read 26297 symbols.
    Reading old symbols (57)...read 26288 symbols.
II: Checking for missing symbols in new ABI...
    MISS : iscsi_conn_queue_work
    MISS : dynamic_debug_exec_queries
    found 2 missing symbols
EE: Symbols gone missing (what did you do!?!)
yaobinwen commented 1 year ago

Update (2022-12-28)

I followed the development cycle to bump changelog version (hopefully) in the appropriate way, but I still ran into the following build error:

# Add the tools.
install -d /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.0-58/usr/lib
install -d /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.0-58/usr/lib/linux-tools-5.15.0-58
install -m755 /lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/usb/usbip/bin/sbin/usbip \
    /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.0-58/usr/lib/linux-tools-5.15.0-58
install -m755 /lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/usb/usbip/bin/sbin/usbipd \
    /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.0-58/usr/lib/linux-tools-5.15.0-58
install -m755 /lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/power/acpi/acpidbg \
    /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.0-58/usr/lib/linux-tools-5.15.0-58
install -m755 /lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/power/cpupower/cpupower \
    /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.0-58/usr/lib/linux-tools-5.15.0-58
# Install only the full versioned libcpupower.so.5.15.0-58, not
# the usual symlinks to it.
install -m644 /lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/power/cpupower/libcpupower.so.5.15.0-58 \
    /lab/ubuntu-kernel-jammy/debian/linux-tools-5.15.0-58/usr/lib/
install: cannot stat '/lab/ubuntu-kernel-jammy/debian/build/tools-perarch/tools/power/cpupower/libcpupower.so.5.15.0-58': No such file or directory
make: *** [debian/rules.d/2-binary-arch.mk:770: install-perarch] Error 1