Sentry Native for MIPS Linux

2 minute read

Prerequisite

export PATH=/usr/local/ingenic/mips-linux-gnu-ingenic-gcc7.2.0-uclibc-ng.1.0.42-fp64-r5.1.6/bin:$PATH

curl

wget -c https://curl.se/download/curl-8.6.0.tar.xz

./configure --host=mips-linux-uclibc --prefix=/usr/local/ingenic/mips-linux-gnu-ingenic-gcc7.2.0-uclibc-ng.1.0.42-fp64-r5.1.6 --disable-manual --disable-ntlm-wb --with-random=/dev/urandom --disable-curldebug --disable-libcurl-option --disable-ldap --disable-ldaps --enable-threaded-resolver --without-ssl --without-libpsl --disable-static
make && sudo make install

cmake

wget -c https://github.com/Kitware/CMake/releases/download/v3.28.3/cmake-3.28.3.tar.gz

./configure --prefix=/usr/local/ingenic/mips-linux-gnu-ingenic-gcc7.2.0-uclibc-ng.1.0.42-fp64-r5.1.6
make && sudo make install

zlib

wget -c https://www.zlib.net/zlib-1.3.1.tar.xz
CHOST=mips-linux-uclibc ./configure --prefix=/usr/local/ingenic/mips-linux-gnu-ingenic-gcc7.2.0-uclibc-ng.1.0.42-fp64-r5.1.6/mips-linux-uclibc/libc/usr
make && sudo make install

Build sentry-native for mips

git clone https://github.com/getsentry/sentry-native
cd sentry-native
git checkout 0.7.0
git submodule update --init --recursive

cmake -B build -DCMAKE_C_COMPILER=mips-linux-uclibc-gcc
cmake --build build --parallel
cmake --install build --prefix install

exa --tree install
install
├── bin
│  └── crashpad_handler
├── include
│  └── sentry.h
└── lib
   ├── cmake
   │  └── sentry
   │     ├── sentry-config-version.cmake
   │     ├── sentry-config.cmake
   │     ├── sentry-targets-relwithdebinfo.cmake
   │     ├── sentry-targets.cmake
   │     ├── sentry_crashpad-targets-relwithdebinfo.cmake
   │     └── sentry_crashpad-targets.cmake
   └── libsentry.so

scp install/bin/crashpad_handler root@192.168.1.81:/usr/bin/
scp install/lib/libsentry.so root@192.168.1.81:/usr/lib/

Upload Source Bundles

export SENTRY_ORG=sentry
export SENTRY_PROJECT=helloworld
export SENTRY_AUTH_TOKEN=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
sentry-cli debug-files upload --include-sources build/sentry_example
> Found 1 debug information file
> Resolved source code for 1 debug information file
> Prepared debug information files for upload
> Uploading completed in 0.205s
> Uploaded 2 missing debug information files
> File upload complete:

  UPLOADED 4e413f9a-f39b-2f34-2d11-77333ad98b46 (sentry_example; mips sources)
  UPLOADED 4e413f9a-f39b-2f34-2d11-77333ad98b46 (sentry_example; mips executable)

Sentry example

# cd /data/usr/bin
# SENTRY_DSN=http://f1e3d59bc01b1e5b0c88a95410a2dd43@192.168.1.89:9000/2 sentry_example stdout capture-event capture-exception crash
[728:728:19700101,091712.961715:ERROR process_memory_linux.cc:50] pread64: Input/output error (5)
[728:728:19700101,091712.962436:WARNING process_reader_linux.cc:146] no stack mapping
[728:728:19700101,091712.963509:ERROR file_io_posix.cc:145] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[728:728:19700101,091712.963651:ERROR file_io_posix.cc:145] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
Segmentation fault

The crash was reported to sentry, but lacks of stacktrace.

Troubleshooting

warning: libcurl.so.4, needed by libsentry.so, not found

[100%] Linking C executable sentry_example
/usr/local/ingenic/mips-linux-gnu-ingenic-gcc7.2.0-uclibc-ng.1.0.42-fp64-r5.1.6/bin/../lib/gcc/mips-linux-uclibc/7.2.0/../../../../mips-linux-uclibc/bin/ld: warning: libcurl.so.4, needed by libsentry.so, not found (try using -rpath or -rpath-link)
libsentry.so: undefined reference to `curl_easy_getinfo'
libsentry.so: undefined reference to `curl_easy_setopt'
libsentry.so: undefined reference to `curl_global_cleanup'
libsentry.so: undefined reference to `curl_easy_reset'
libsentry.so: undefined reference to `curl_easy_init'
libsentry.so: undefined reference to `curl_slist_append'
libsentry.so: undefined reference to `curl_slist_free_all'
libsentry.so: undefined reference to `curl_easy_perform'
libsentry.so: undefined reference to `curl_easy_cleanup'
libsentry.so: undefined reference to `curl_version_info'
libsentry.so: undefined reference to `curl_global_init'
libsentry.so: undefined reference to `curl_easy_strerror'
collect2: error: ld returned 1 exit status

Workaround: Add rpath to build/CMakeFiles/sentry_example.dir/link.txt

-Wl,-rpath,/usr/local/ingenic/mips-linux-gnu-ingenic-gcc7.2.0-uclibc-ng.1.0.42-fp64-r5.1.6/lib /usr/local/ingenic/mips-linux-gnu-ingenic-gcc7.2.0-uclibc-ng.1.0.42-fp64-r5.1.6/lib/libcurl.so

cmake --build build --parallel

pread64: Input/output error

# cd /data/usr/bin

# SENTRY_DSN=http://f1e3d59bc01b1e5b0c88a95410a2dd43@192.168.1.89:9000/2 sentry
_example log stdout capture-event capture-exception crash
[sentry] INFO using database path "/data/usr/bin/.sentry-native"
[sentry] DEBUG starting backend
[sentry] DEBUG starting crashpad backend with handler "/data/usr/bin/crashpad_handler"
[sentry] DEBUG using minidump URL "http://192.168.1.89:9000/api/2/minidump/?sentry_client=sentry.native/0.7.0&sentry_key=f1e3d59bc01b1e5b0c88a95410a2dd43"
[sentry] INFO started crashpad client handler
[sentry] DEBUG processing and pruning old runs
[sentry] INFO flushing session and queue before crashpad handler
[sentry] INFO handing control over to crashpad
[714:714:19700101,083947.320347:ERROR process_memory_linux.cc:50] pread64: Input/output error (5)
[714:714:19700101,083947.321090:WARNING process_reader_linux.cc:146] no stack mapping
[714:714:19700101,083947.322165:ERROR file_io_posix.cc:145] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[714:714:19700101,083947.322307:ERROR file_io_posix.cc:145] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
Segmentation fault