Skip to content

Commit

Permalink
fixes #8 - add checking for libstackusage arch compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Dec 11, 2021
1 parent ce3543a commit 8a99b07
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ stack with a dummy data pattern. It also registers a callback routine to be
called upon thread termination. In the callback routine the amount of remaining
dummy pattern in the stack is checked, in order to determine the stack usage.

Interception is only possible when stackusage is built for the same
architecture as the program being analyzed. Stackusage tries to determine if
there is a mismatch, if encountered it will output a warning like this:

warning: libstackusage.so architecture (ELF 64-bit) does not appear
to match <PROG> architecture (ELF 32-bit), analysis may fail.

To solve this, simply compile stackusage for the appropriate architecture, for
example by adding `-m32` to CMAKE_C_FLAGS in CMakeLists.txt, example:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -g -m32 \

License
=======
Stackusage is distributed under the BSD 3-Clause license. See LICENSE file.
Expand Down
27 changes: 24 additions & 3 deletions src/stackusage
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright (C) 2015-2020 Kristofer Berggren
# Copyright (C) 2015-2021 Kristofer Berggren
# All rights reserved.
#
# stackusage is distributed under the BSD 3-Clause license, see LICENSE for details.
Expand Down Expand Up @@ -43,15 +43,33 @@ showusage()

showversion()
{
echo "stackusage v1.14"
echo "stackusage v1.15"
echo ""
echo "Copyright (C) 2015-2020 Kristofer Berggren"
echo "Copyright (C) 2015-2021 Kristofer Berggren"
echo ""
echo "stackusage is distributed under the BSD 3-Clause license."
echo ""
echo "Written by Kristofer Berggren"
}

check_arch_compat()
{
LIBPATH="${1}"
PRGPATH="$(which ${2})"
if [[ "${PRGPATH}" != "" ]]; then
PRGARCH=$(file -b ${PRGPATH} | awk '{print $1 " " $2}')
LIBARCH=$(file -b ${LIBPATH} | awk '{print $1 " " $2}')
PRGBITS=$(file -b ${PRGPATH} | awk '{print $2}' | awk -F'-' '{print $1}')
LIBBITS=$(file -b ${LIBPATH} | awk '{print $2}' | awk -F'-' '{print $1}')
if [[ "${PRGBITS}" =~ ^(32|64)$ ]] && [[ "${LIBBITS}" =~ ^(32|64)$ ]] && \
[[ "${PRGARCH}" != "${LIBARCH}" ]]; then
echo "warning: $(basename ${LIBPATH}) architecture (${LIBARCH}) does not appear"
echo "to match ${PRGPATH} architecture (${PRGARCH}), analysis may fail."
echo "see https://github.com/d99kris/stackusage#technical-details"
fi
fi
}

if [ "${1}" == "--help" ] ; then
showusage
exit 0
Expand Down Expand Up @@ -155,6 +173,9 @@ while [ "${LIBPATHS[CNT]}" != "" ]; do
LIBPATH="${LIBPATHS[CNT]}"
if [ -e "${LIBPATH}" ]; then

# Check if libstackusage is compatible with program to analyze
check_arch_compat "${LIBPATH}" "${1}"

# Run program
if [ "${DEBUG}" == "0" ]; then
SU_FILE="${TMPLOG}${OUTFILE}" \
Expand Down
4 changes: 2 additions & 2 deletions src/stackusage.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
.TH STACKUSAGE "1" "August 2021" "stackusage v1.14" "User Commands"
.TH STACKUSAGE "1" "December 2021" "stackusage v1.15" "User Commands"
.SH NAME
stackusage \- measure stack usage in applications
.SH SYNOPSIS
Expand Down Expand Up @@ -57,6 +57,6 @@ Written by Kristofer Berggren
.SH "REPORTING BUGS"
Report bugs at https://github.com/d99kris/stackusage
.SH COPYRIGHT
Copyright \(co 2015\-2020 Kristofer Berggren
Copyright \(co 2015\-2021 Kristofer Berggren
.PP
stackusage is distributed under the BSD 3\-Clause license.

0 comments on commit 8a99b07

Please sign in to comment.