init
This commit is contained in:
4
.gitattributes
vendored
Normal file
4
.gitattributes
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
arm/bin/gdbserver filter=lfs diff=lfs merge=lfs -text
|
||||
arm/bin/gdbserver_debug filter=lfs diff=lfs merge=lfs -text
|
||||
arm/bin/strace filter=lfs diff=lfs merge=lfs -text
|
||||
arm/bin/strace_debug filter=lfs diff=lfs merge=lfs -text
|
||||
12
README.md
Normal file
12
README.md
Normal file
@ -0,0 +1,12 @@
|
||||
# Static Build artifacts for common tools
|
||||
|
||||
See [arm/bin](arm/bin) for the artifacts. Note that the tripple is `arm-linux-gnueabihf`. (Although I don't believe [glibc](https://en.wikipedia.org/wiki/Glibc) is actually used since it's a static build)
|
||||
|
||||
See the build instructions for cross-compilation in the corresponding markdown files.
|
||||
|
||||
- [strace](strace.md)
|
||||
- [gdbserver](gdbserver.md)
|
||||
|
||||
## Toolchains
|
||||
|
||||
[arm-linux-gnueabihf-linaro-bin](https://aur.archlinux.org/packages/arm-linux-gnueabihf-linaro-bin) from [snapshots.linaro.org/gnu-toolchain](https://snapshots.linaro.org/gnu-toolchain/14.0-2023.06-1/)
|
||||
BIN
arm/bin/gdbserver
LFS
Executable file
BIN
arm/bin/gdbserver
LFS
Executable file
Binary file not shown.
BIN
arm/bin/gdbserver_debug
LFS
Executable file
BIN
arm/bin/gdbserver_debug
LFS
Executable file
Binary file not shown.
BIN
arm/bin/strace
LFS
Executable file
BIN
arm/bin/strace
LFS
Executable file
Binary file not shown.
90
arm/bin/strace-log-merge
Executable file
90
arm/bin/strace-log-merge
Executable file
@ -0,0 +1,90 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# This script processes strace -ff -tt output. It merges the contents of all
|
||||
# STRACE_LOG.PID files and sorts them, printing result on the standard output.
|
||||
#
|
||||
# Copyright (c) 2012-2024 The strace developers.
|
||||
#
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
show_usage()
|
||||
{
|
||||
cat <<__EOF__
|
||||
Usage: ${0##*/} STRACE_LOG
|
||||
|
||||
Finds all STRACE_LOG.PID files, adds PID prefix to every line,
|
||||
then combines and sorts them, and prints result to standard output.
|
||||
|
||||
It is assumed that STRACE_LOGs were produced by strace with -tt[t]
|
||||
option which prints timestamps (otherwise sorting won't do any good).
|
||||
__EOF__
|
||||
}
|
||||
|
||||
dd='\([0-9][0-9]\)'
|
||||
ds='\([0-9][0-9]*\)'
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
show_usage >&2
|
||||
exit 1
|
||||
elif [ "$1" = '--help' ] || [ "$1" = '-h' ]; then
|
||||
show_usage
|
||||
exit 0
|
||||
fi
|
||||
|
||||
logfile=$1
|
||||
|
||||
iterate_logfiles()
|
||||
{
|
||||
local file suffix
|
||||
|
||||
for file in "$logfile".*; do
|
||||
[ -f "$file" ] || continue
|
||||
suffix=${file#"$logfile".}
|
||||
[ "$suffix" -gt 0 ] 2> /dev/null ||
|
||||
continue
|
||||
"$@" "$suffix" "$file"
|
||||
done
|
||||
}
|
||||
|
||||
max_suffix_length=0
|
||||
process_suffix()
|
||||
{
|
||||
local suffix len
|
||||
suffix="$1"; shift
|
||||
|
||||
len=${#suffix}
|
||||
if [ $len -gt $max_suffix_length ]; then
|
||||
max_suffix_length=$len
|
||||
fi
|
||||
}
|
||||
|
||||
process_logfile()
|
||||
{
|
||||
local suffix file pid
|
||||
suffix="$1"; shift
|
||||
file="$1"; shift
|
||||
|
||||
pid=$(printf "%-*s" $max_suffix_length $suffix)
|
||||
# Some strace logs have last line which is not '\n' terminated,
|
||||
# so add extra newline to every file.
|
||||
# Empty lines are removed later.
|
||||
sed -n "s/^\($dd:\)\?\($dd:\)\?\($ds\.\)\?$ds /\2\4\6\7 $pid \0/p" < "$file"
|
||||
echo
|
||||
}
|
||||
|
||||
iterate_logfiles process_suffix
|
||||
|
||||
[ $max_suffix_length -gt 0 ] || {
|
||||
echo >&2 "${0##*/}: $logfile: strace output not found"
|
||||
exit 1
|
||||
}
|
||||
|
||||
iterate_logfiles process_logfile |
|
||||
sort -s -n -k1,1 |
|
||||
sed -n 's/^[0-9][0-9]* //p' |
|
||||
grep -v '^$'
|
||||
|
||||
rc=$?
|
||||
[ $rc -eq 1 ] &&
|
||||
echo >&2 "${0##*/}: $logfile.* files do not look like log files produced by 'strace -tt'"
|
||||
exit $rc
|
||||
BIN
arm/bin/strace_debug
LFS
Executable file
BIN
arm/bin/strace_debug
LFS
Executable file
Binary file not shown.
126
arm/share/man/man1/strace-log-merge.1
Normal file
126
arm/share/man/man1/strace-log-merge.1
Normal file
@ -0,0 +1,126 @@
|
||||
.\" Copyright (c) 2017 The strace developers.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
.\"
|
||||
.\" Required option.
|
||||
.de OR
|
||||
. ie \\n(.$-1 \
|
||||
. RI "\fB\\$1\fP" "\ \\$2"
|
||||
. el \
|
||||
. BR "\\$1"
|
||||
..
|
||||
.\"
|
||||
.TH STRACE-LOG-MERGE 1 "2022-01-01" "strace 6.13.0.37.b6c94"
|
||||
.\"
|
||||
.SH NAME
|
||||
strace-log-merge \- merge strace \-ff \-tt output
|
||||
.\"
|
||||
.SH SYNOPSIS
|
||||
.SY strace\-log\-merge
|
||||
.IR STRACE_LOG
|
||||
.YS
|
||||
.SY strace\-log\-merge
|
||||
.OR \-\-help
|
||||
.YS
|
||||
.\"
|
||||
.SH DESCRIPTION
|
||||
.B strace\-log\-merge
|
||||
merges the output of
|
||||
.B strace \-ff \-tt[t]
|
||||
command, prepending PID to each line and sorting the result using time stamp as
|
||||
a key.
|
||||
.\"
|
||||
.SH OPTIONS
|
||||
.\"
|
||||
.TP
|
||||
.B \-\-help
|
||||
Show program usage and exit.
|
||||
.TP
|
||||
.I STRACE_LOG
|
||||
Output file name prefix of files produced by a
|
||||
.B strace -ff -tt[t]
|
||||
command.
|
||||
.SH EXIT STATUS
|
||||
.TP
|
||||
.B 0
|
||||
Success
|
||||
.TP
|
||||
.B Non-zero
|
||||
Error occurred: either no argument specified (in that case a usage is printed),
|
||||
or something went wrong during the processing of
|
||||
.IR STRACE_LOG ".*"
|
||||
files.
|
||||
.\"
|
||||
.SH USAGE EXAMPLE
|
||||
.sp
|
||||
.nf
|
||||
.ft CW
|
||||
$ strace -o sleepy -ff -tt -e trace=execve,nanosleep \\
|
||||
sh -c 'sleep 0.1 & sleep 0.2 & sleep 0.3'
|
||||
$ strace-log-merge sleepy | fold -w 72 -s
|
||||
13475 21:13:52.040837 execve("/bin/sh", ["sh", "-c", "sleep 0.1 & sleep
|
||||
0.2 & sleep 0."...], 0x7ffde54b2450 /* 33 vars */) = 0
|
||||
13478 21:13:52.044050 execve("/bin/sleep", ["sleep", "0.3"],
|
||||
0x5631be4f87a8 /* 33 vars */) = 0
|
||||
13476 21:13:52.044269 execve("/bin/sleep", ["sleep", "0.1"],
|
||||
0x5631be4f87a8 /* 33 vars */) = 0
|
||||
13477 21:13:52.044389 execve("/bin/sleep", ["sleep", "0.2"],
|
||||
0x5631be4f87a8 /* 33 vars */) = 0
|
||||
13478 21:13:52.046207 nanosleep({tv_sec=0, tv_nsec=300000000}, NULL) = 0
|
||||
13476 21:13:52.046303 nanosleep({tv_sec=0, tv_nsec=100000000}, NULL) = 0
|
||||
13477 21:13:52.046318 nanosleep({tv_sec=0, tv_nsec=200000000}, NULL) = 0
|
||||
13476 21:13:52.146852 +++ exited with 0 +++
|
||||
13475 21:13:52.146942 --- SIGCHLD {si_signo=SIGCHLD,
|
||||
si_code=CLD_EXITED, si_pid=13476, si_uid=1000, si_status=0, si_utime=0,
|
||||
si_stime=0} ---
|
||||
13477 21:13:52.247782 +++ exited with 0 +++
|
||||
13475 21:13:52.247885 --- SIGCHLD {si_signo=SIGCHLD,
|
||||
si_code=CLD_EXITED, si_pid=13477, si_uid=1000, si_status=0, si_utime=0,
|
||||
si_stime=0} ---
|
||||
13478 21:13:52.347680 +++ exited with 0 +++
|
||||
13475 21:13:52.347786 --- SIGCHLD {si_signo=SIGCHLD,
|
||||
si_code=CLD_EXITED, si_pid=13478, si_uid=1000, si_status=0, si_utime=0,
|
||||
si_stime=0} ---
|
||||
13475 21:13:52.348069 +++ exited with 0 +++
|
||||
.ft R
|
||||
.fi
|
||||
.sp
|
||||
.\"
|
||||
.SH NOTES
|
||||
.I strace-log-merge
|
||||
does not work well with
|
||||
.B strace
|
||||
logs generated by
|
||||
.B strace -tt
|
||||
invocation that pass midnight, as those lack the information required
|
||||
for the proper sorting.
|
||||
Employing the
|
||||
.B -ttt
|
||||
option in the respective
|
||||
.B strace
|
||||
invocation should solve the problem.
|
||||
.\"
|
||||
.SH BUGS
|
||||
.I strace-log-merge
|
||||
does not perform any checks whether the files specified are in the correct
|
||||
format and implies that only files from a single
|
||||
.I strace
|
||||
session match
|
||||
.IR STRACE_LOG ".*"
|
||||
glob pattern.
|
||||
.\"
|
||||
.SH HISTORY
|
||||
The initial version of
|
||||
.I strace-log-merge
|
||||
was written by Denys Vlasenko in 2012.
|
||||
.\"
|
||||
.SH REPORTING BUGS
|
||||
Problems with
|
||||
.B strace-log-merge
|
||||
should be reported to the
|
||||
.B strace
|
||||
mailing list at <strace\-devel@lists.strace.io>.
|
||||
.\"
|
||||
.SH "SEE ALSO"
|
||||
.BR strace (1)
|
||||
2095
arm/share/man/man1/strace.1
Normal file
2095
arm/share/man/man1/strace.1
Normal file
File diff suppressed because it is too large
Load Diff
230
gdbserver.md
Normal file
230
gdbserver.md
Normal file
@ -0,0 +1,230 @@
|
||||
# Building GDB Server for ARM Linux (Static Linking)
|
||||
|
||||
> [!NOTE]
|
||||
> This guide is generated by LLM. Please verify the correctness of the steps before using them.
|
||||
|
||||
This document outlines the process for cross-compiling GDB Server for ARM Linux (arm-linux-gnueabihf) with static linking.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Linux development environment
|
||||
- ARM cross-compiler toolchain (in this case at `/opt/gcc-arm-linux-guneabihf`)
|
||||
- GDB source code (version 14.2 used in this example)
|
||||
- zsh shell (recommended to avoid issues with PowerShell)
|
||||
|
||||
## Build Script
|
||||
|
||||
Here's a reproducible build script that automates the entire process:
|
||||
|
||||
```bash
|
||||
#!/bin/zsh
|
||||
|
||||
# Exit on error
|
||||
set -e
|
||||
|
||||
# Configuration variables
|
||||
GDB_VERSION="14.2"
|
||||
GDB_SOURCE_DIR="/home/crosstyan/third-party/gdb-${GDB_VERSION}"
|
||||
TOOLCHAIN_PREFIX="/opt/gcc-arm-linux-guneabihf"
|
||||
TARGET="arm-linux-gnueabihf"
|
||||
INSTALL_PREFIX="/home/crosstyan/Image/rootfs"
|
||||
|
||||
# Ensure we're in zsh
|
||||
if [ -z "$ZSH_VERSION" ]; then
|
||||
echo "This script must be run in zsh shell!"
|
||||
echo "Please run: zsh $0"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Navigate to GDB source directory
|
||||
cd $GDB_SOURCE_DIR
|
||||
|
||||
# Clean any previous build artifacts
|
||||
echo "Cleaning previous build artifacts..."
|
||||
make distclean || true
|
||||
|
||||
# Configure GDB for cross-compilation with static linking
|
||||
echo "Configuring GDB for cross-compilation..."
|
||||
./configure \
|
||||
--target=$TARGET \
|
||||
--host=$TARGET \
|
||||
--build=x86_64-linux-gnu \
|
||||
--prefix=$INSTALL_PREFIX \
|
||||
--disable-werror \
|
||||
--enable-gdbserver=yes \
|
||||
--disable-gdb \
|
||||
--disable-binutils \
|
||||
--disable-gas \
|
||||
--disable-ld \
|
||||
--disable-gold \
|
||||
--disable-gprof \
|
||||
LDFLAGS='-static' \
|
||||
CC=$TOOLCHAIN_PREFIX/bin/$TARGET-gcc \
|
||||
CXX=$TOOLCHAIN_PREFIX/bin/$TARGET-g++ \
|
||||
AR=$TOOLCHAIN_PREFIX/bin/$TARGET-ar \
|
||||
RANLIB=$TOOLCHAIN_PREFIX/bin/$TARGET-ranlib \
|
||||
CFLAGS="-O2"
|
||||
|
||||
# Build only the gdbserver component
|
||||
echo "Building gdbserver..."
|
||||
make -j$(nproc) all-gdbserver
|
||||
|
||||
# Verify the built binary
|
||||
echo "Verifying the built binary..."
|
||||
file gdbserver/gdbserver
|
||||
readelf -h gdbserver/gdbserver
|
||||
|
||||
# Install gdbserver (optional)
|
||||
# make install-gdbserver
|
||||
|
||||
echo "Build completed successfully!"
|
||||
echo "The statically linked gdbserver binary is located at: $GDB_SOURCE_DIR/gdbserver/gdbserver"
|
||||
```
|
||||
|
||||
## Manual Build Process
|
||||
|
||||
If you prefer to build manually, follow these steps:
|
||||
|
||||
1. **Ensure you're using zsh shell**:
|
||||
```bash
|
||||
zsh
|
||||
```
|
||||
|
||||
2. **Navigate to the GDB source directory**:
|
||||
```bash
|
||||
cd /home/crosstyan/third-party/gdb-14.2
|
||||
```
|
||||
|
||||
3. **Clean any previous build artifacts**:
|
||||
```bash
|
||||
make distclean
|
||||
```
|
||||
|
||||
4. **Configure GDB for cross-compilation with static linking**:
|
||||
```bash
|
||||
./configure \
|
||||
--target=arm-linux-gnueabihf \
|
||||
--host=arm-linux-gnueabihf \
|
||||
--build=x86_64-linux-gnu \
|
||||
--prefix=/home/crosstyan/Image/rootfs \
|
||||
--disable-werror \
|
||||
--enable-gdbserver=yes \
|
||||
--disable-gdb \
|
||||
--disable-binutils \
|
||||
--disable-gas \
|
||||
--disable-ld \
|
||||
--disable-gold \
|
||||
--disable-gprof \
|
||||
LDFLAGS='-static' \
|
||||
CC=/opt/gcc-arm-linux-guneabihf/bin/arm-linux-gnueabihf-gcc \
|
||||
CXX=/opt/gcc-arm-linux-guneabihf/bin/arm-linux-gnueabihf-g++ \
|
||||
AR=/opt/gcc-arm-linux-guneabihf/bin/arm-linux-gnueabihf-ar \
|
||||
RANLIB=/opt/gcc-arm-linux-guneabihf/bin/arm-linux-gnueabihf-ranlib \
|
||||
CFLAGS="-O2"
|
||||
```
|
||||
|
||||
5. **Build only the gdbserver component**:
|
||||
```bash
|
||||
make -j$(nproc) all-gdbserver
|
||||
```
|
||||
|
||||
6. **Verify the built binary**:
|
||||
```bash
|
||||
file gdbserver/gdbserver
|
||||
readelf -h gdbserver/gdbserver
|
||||
```
|
||||
|
||||
## Configuration Options Explained
|
||||
|
||||
- `--target=arm-linux-gnueabihf`: Specifies the target architecture
|
||||
- `--host=arm-linux-gnueabihf`: Specifies the host architecture (same as target for cross-compilation)
|
||||
- `--build=x86_64-linux-gnu`: Specifies the build system architecture
|
||||
- `--prefix=/home/crosstyan/Image/rootfs`: Installation directory
|
||||
- `--disable-werror`: Prevents warnings from being treated as errors
|
||||
- `--enable-gdbserver=yes`: Enables building gdbserver
|
||||
- `--disable-gdb`, `--disable-binutils`, etc.: Disables building other components
|
||||
- `LDFLAGS='-static'`: Forces static linking
|
||||
- `CC=...`, `CXX=...`: Specifies the cross-compiler
|
||||
- `AR=...`, `RANLIB=...`: Specifies the cross-toolchain utilities
|
||||
- `CFLAGS="-O2"`: Optimization level
|
||||
|
||||
## Verification
|
||||
|
||||
After building, you can verify the binary with:
|
||||
|
||||
```bash
|
||||
file gdbserver/gdbserver
|
||||
```
|
||||
|
||||
Expected output:
|
||||
```
|
||||
gdbserver/gdbserver: ELF 32-bit LSB executable, ARM, EABI5 version 1 (GNU/Linux), statically linked, BuildID[sha1]=613dd203a0dff4326f6bd325222a6d882afd6168, for GNU/Linux 3.2.0, with debug_info, not stripped
|
||||
```
|
||||
|
||||
And check the ELF header:
|
||||
```bash
|
||||
readelf -h gdbserver/gdbserver
|
||||
```
|
||||
|
||||
Look for:
|
||||
```
|
||||
Machine: ARM
|
||||
Flags: 0x5000400, Version5 EABI, hard-float ABI
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- The build process requires the dependencies to be built in the correct order (handled automatically by the Makefile)
|
||||
- There may be warnings during the linking process about certain glibc functions in statically linked binaries
|
||||
- The resulting binary is statically linked but some functions may still require shared libraries at runtime
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- If you encounter "file format not recognized" errors, ensure you're using the correct cross-toolchain
|
||||
- If the build fails with missing dependencies, check that all required libraries are installed
|
||||
|
||||
## Strip
|
||||
|
||||
```bash
|
||||
/opt/gcc-arm-linux-guneabihf/bin/arm-linux-gnueabihf-strip <your-binary>
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
> [!NOTE]
|
||||
> This part is a human artifact. No LLM involved.
|
||||
|
||||
You might need to add
|
||||
|
||||
```c
|
||||
#ifndef __NR_sigreturn
|
||||
#define __NR_SYSCALL_BASE 0
|
||||
#define __NR_sigreturn (__NR_SYSCALL_BASE+119)
|
||||
#endif
|
||||
```
|
||||
|
||||
to `gdbserver/linux-arm-low.cc` if you encounter the following error:
|
||||
|
||||
```text
|
||||
In file included from ./../gdbsupport/array-view.h:24,
|
||||
from ./../gdbsupport/common-utils.h:27,
|
||||
from ./../gdbsupport/common-defs.h:208,
|
||||
from server.h:22,
|
||||
from linux-arm-low.cc:19:
|
||||
linux-arm-low.cc: In function ‘CORE_ADDR arm_sigreturn_next_pc(regcache*, int, int*)’:
|
||||
linux-arm-low.cc:890:29: error: ‘__NR_sigreturn’ was not declared in this scope; did you mean ‘sigreturn’?
|
||||
890 | gdb_assert (svc_number == __NR_sigreturn || svc_number == __NR_rt_sigreturn);
|
||||
| ^~~~~~~~~~~~~~
|
||||
./../gdbsupport/gdb_assert.h:35:13: note: in definition of macro ‘gdb_assert’
|
||||
35 | ((void) ((expr) ? 0 : \
|
||||
| ^~~~
|
||||
linux-arm-low.cc: In function ‘CORE_ADDR get_next_pcs_syscall_next_pc(arm_get_next_pcs*)’:
|
||||
linux-arm-low.cc:944:21: error: ‘__NR_sigreturn’ was not declared in this scope; did you mean ‘sigreturn’?
|
||||
944 | if (svc_number == __NR_sigreturn || svc_number == __NR_rt_sigreturn)
|
||||
| ^~~~~~~~~~~~~~
|
||||
| sigreturn
|
||||
make: *** [Makefile:546: linux-arm-low.o] Error 1
|
||||
make: *** Waiting for unfinished jobs....
|
||||
```
|
||||
|
||||
See also [asm/unistd.h](https://android.googlesource.com/kernel/msm/+/android-msm-flo-3.4-kitkat-mr0/arch/arm/include/asm/unistd.h#147) from Android source code.
|
||||
12
strace.md
Normal file
12
strace.md
Normal file
@ -0,0 +1,12 @@
|
||||
# strace
|
||||
|
||||
```bash
|
||||
./configure --target=arm-linux-gnueabihf \
|
||||
--host=arm-linux-gnueabihf \
|
||||
--build=x86_64-linux-gnu \
|
||||
--prefix=/home/crosstyan/Image/rootfs \
|
||||
LDFLAGS='-static -pthread' \
|
||||
CC=/opt/gcc-arm-linux-guneabihf/bin/arm-linux-gnueabihf-gcc \
|
||||
CXX=/opt/gcc-arm-linux-guneabihf/bin/arm-linux-gnueabihf-g++
|
||||
CFLAGS="-O2"
|
||||
```
|
||||
Reference in New Issue
Block a user