port runtc

This commit is contained in:
Ciro Santilli
2018-08-31 13:38:08 +01:00
parent eb3422c1ea
commit 04b878dfa7
2 changed files with 50 additions and 42 deletions

View File

@@ -1462,7 +1462,7 @@ so it is close to the failing `0xbf0000cc`.
`readelf`: `readelf`:
.... ....
./runtc readelf -s "$(./getvar build_dir)/kernel_module-1.0/hello.ko" ./runtc readelf -- -s "$(./getvar build_dir)/kernel_module-1.0/hello.ko"
.... ....
does not give any interesting hits at `cc`, no symbol was placed that far. does not give any interesting hits at `cc`, no symbol was placed that far.
@@ -1535,7 +1535,7 @@ The base address shows on terminal:
Now let's find the offset of `myinit`: Now let's find the offset of `myinit`:
.... ....
./runtc readelf \ ./runtc readelf -- \
-s "$(./getvar build_dir)/kernel_module-1.0/fops.ko" | \ -s "$(./getvar build_dir)/kernel_module-1.0/fops.ko" | \
grep myinit grep myinit
.... ....
@@ -1856,7 +1856,7 @@ Cannot access memory at address 0x10604
We have also double checked the address with: We have also double checked the address with:
.... ....
./runtc -a arm readelf \ ./runtc -a arm readelf -- \
-s "$(./getvar -a arm build_dir)/kernel_module-1.0/fops.ko" | \ -s "$(./getvar -a arm build_dir)/kernel_module-1.0/fops.ko" | \
grep main grep main
.... ....
@@ -2457,7 +2457,7 @@ TODO Can you run arm executables in the aarch64 guest? https://stackoverflow.com
I've tried: I've tried:
.... ....
./runtc -a aarch64 gcc|cg -static ~/test/hello_world.c -o data/9p/a.out ./runtc -a aarch64 gcc -- -static ~/test/hello_world.c -o data/9p/a.out
./run -a A -F '/mnt/9p/a.out' ./run -a A -F '/mnt/9p/a.out'
.... ....
@@ -3325,7 +3325,7 @@ vermagic: 4.17.0 SMP mod_unload modversions
Module information is stored in a special `.modinfo` section of the ELF file: Module information is stored in a special `.modinfo` section of the ELF file:
.... ....
./runtc readelf -SW "$(./getvar target_dir)/module_info.ko" ./runtc readelf -- -SW "$(./getvar target_dir)/module_info.ko"
.... ....
contains: contains:
@@ -3337,7 +3337,7 @@ contains:
and: and:
.... ....
./runtc readelf -x .modinfo "$(./getvar build_dir)/module_info.ko" ./runtc readelf -- -x .modinfo "$(./getvar build_dir)/module_info.ko"
.... ....
gives: gives:
@@ -3554,7 +3554,7 @@ as explained at: https://stackoverflow.com/questions/8545931/using-gdb-to-conver
The exact same thing can be done post mortem with: The exact same thing can be done post mortem with:
.... ....
./runtc gdb \ ./runtc gdb -- \
-batch \ -batch \
-ex 'info line *(myinit+0x1d)' \ -ex 'info line *(myinit+0x1d)' \
"$(./getvar build_dir)/kernel_module-1.0/panic.ko" \ "$(./getvar build_dir)/kernel_module-1.0/panic.ko" \
@@ -4884,7 +4884,7 @@ Meaning of the flags:
* `vaddr`: first virtual address of a page the belongs to the process. Notably: * `vaddr`: first virtual address of a page the belongs to the process. Notably:
+ +
.... ....
./runtc readelf -l "$(./getvar build_dir)/kernel_module-1.0/user/virt_to_phys_test.out" ./runtc readelf -- -l "$(./getvar build_dir)/kernel_module-1.0/user/virt_to_phys_test.out"
.... ....
+ +
contains: contains:
@@ -5256,7 +5256,7 @@ Notes:
It can be found from: It can be found from:
+ +
.... ....
./runtc readelf -e "$(./getvar vmlinux)" | grep Entry ./runtc readelf -- -e "$(./getvar vmlinux)" | grep Entry
.... ....
+ +
TODO confirm further. If I try to break there with: TODO confirm further. If I try to break there with:
@@ -6747,7 +6747,7 @@ The reason this is cool, is that `ls` is not statically compiled, but since we h
In other words, much cooler than: In other words, much cooler than:
.... ....
./runtc -a arm gcc -static ./kernel_module/user/hello.c ./runtc -a arm gcc -- -static ./kernel_module/user/hello.c
qemu-arm a.out qemu-arm a.out
.... ....
@@ -6798,9 +6798,9 @@ First we try some `-static` sanity checks.
Works and prints `hello`: Works and prints `hello`:
.... ....
./runtc -a x86_64 gcc -static -o x86_64.out ./kernel_module/user/hello.c ./runtc -a x86_64 gcc -- -static -o x86_64.out ./kernel_module/user/hello.c
./runtc -a arm gcc -static -o arm.out ./kernel_module/user/hello.c ./runtc -a arm gcc -- -static -o arm.out ./kernel_module/user/hello.c
./runtc -a aarch64 gcc -static -o aarch64.out ./kernel_module/user/hello.c ./runtc -a aarch64 gcc -- -static -o aarch64.out ./kernel_module/user/hello.c
"$(./getvar -a x86_64 -g exec)" ./gem5/gem5/configs/example/se.py -c ./x86_64.out "$(./getvar -a x86_64 -g exec)" ./gem5/gem5/configs/example/se.py -c ./x86_64.out
"$(./getvar -a arm -g exec)" ./gem5/gem5/configs/example/se.py -c ./arm.out "$(./getvar -a arm -g exec)" ./gem5/gem5/configs/example/se.py -c ./arm.out
"$(./getvar -a aarch64 -g exec)" ./gem5/gem5/configs/example/se.py -c ./aarch64.out "$(./getvar -a aarch64 -g exec)" ./gem5/gem5/configs/example/se.py -c ./aarch64.out
@@ -9556,16 +9556,6 @@ Otherwise, it becomes very difficult to keep everything working across path refa
|`-q` |QEMU | |`-q` |QEMU |
|=== |===
==== runtc
The link:runtc[] helper script runs a Tool Chain executable built by Buildroot.
For example, to run `readelf -h` for the `arm` architecture, use:
....
./runtc -a arm readelf -h
....
=== CONTRIBUTING === CONTRIBUTING
==== Testing ==== Testing

56
runtc
View File

@@ -1,19 +1,37 @@
#!/usr/bin/env bash #!/usr/bin/env python3
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
while getopts "h${common_getopts_flags}" OPT; do import glob
case "$OPT" in import os
h) import subprocess
echo "https://github.com/cirosantilli/linux-kernel-module-cheat#runtc" 2>&1 import sys
exit
;; import common
?)
common_getopts_case "$OPT" parser = common.get_argparse(argparse_args={
;; 'description':'''Run a Buildroot ToolChain tool like readelf or objdump.
esac
done For example, to run `readelf -h` for the `arm` architecture, use:
shift "$(($OPTIND - 1))"
tool="$1" ....
shift ./%(prog)s -a arm readelf -- -h
common_setup ....
"${common_buildroot_out_dir}/host/bin/"*-buildroot-*"${tool}" "$@"
exit "$?" Get the list of available tools with:
....
ls "$(./getvar -a arm host_bin_dir)"
....
'''
})
parser.add_argument('tool', help='Which tool to run.')
parser.add_argument(
'extra_args',
default=[],
help='Extra arguments for the tool.',
metavar='extra-args',
nargs='*'
)
args = common.setup(parser)
paths = glob.glob(os.path.join(common.host_bin_dir, '*-buildroot-*-{}'.format(args.tool)))
assert len(paths) == 1
sys.exit(subprocess.Popen(paths + args.extra_args).wait())