Skip to content

Commit 8a99b07

Browse files
committed
fixes #8 - add checking for libstackusage arch compatibility
1 parent ce3543a commit 8a99b07

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ stack with a dummy data pattern. It also registers a callback routine to be
123123
called upon thread termination. In the callback routine the amount of remaining
124124
dummy pattern in the stack is checked, in order to determine the stack usage.
125125

126+
Interception is only possible when stackusage is built for the same
127+
architecture as the program being analyzed. Stackusage tries to determine if
128+
there is a mismatch, if encountered it will output a warning like this:
129+
130+
warning: libstackusage.so architecture (ELF 64-bit) does not appear
131+
to match <PROG> architecture (ELF 32-bit), analysis may fail.
132+
133+
To solve this, simply compile stackusage for the appropriate architecture, for
134+
example by adding `-m32` to CMAKE_C_FLAGS in CMakeLists.txt, example:
135+
136+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -g -m32 \
137+
126138
License
127139
=======
128140
Stackusage is distributed under the BSD 3-Clause license. See LICENSE file.

src/stackusage

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

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

4444
showversion()
4545
{
46-
echo "stackusage v1.14"
46+
echo "stackusage v1.15"
4747
echo ""
48-
echo "Copyright (C) 2015-2020 Kristofer Berggren"
48+
echo "Copyright (C) 2015-2021 Kristofer Berggren"
4949
echo ""
5050
echo "stackusage is distributed under the BSD 3-Clause license."
5151
echo ""
5252
echo "Written by Kristofer Berggren"
5353
}
5454

55+
check_arch_compat()
56+
{
57+
LIBPATH="${1}"
58+
PRGPATH="$(which ${2})"
59+
if [[ "${PRGPATH}" != "" ]]; then
60+
PRGARCH=$(file -b ${PRGPATH} | awk '{print $1 " " $2}')
61+
LIBARCH=$(file -b ${LIBPATH} | awk '{print $1 " " $2}')
62+
PRGBITS=$(file -b ${PRGPATH} | awk '{print $2}' | awk -F'-' '{print $1}')
63+
LIBBITS=$(file -b ${LIBPATH} | awk '{print $2}' | awk -F'-' '{print $1}')
64+
if [[ "${PRGBITS}" =~ ^(32|64)$ ]] && [[ "${LIBBITS}" =~ ^(32|64)$ ]] && \
65+
[[ "${PRGARCH}" != "${LIBARCH}" ]]; then
66+
echo "warning: $(basename ${LIBPATH}) architecture (${LIBARCH}) does not appear"
67+
echo "to match ${PRGPATH} architecture (${PRGARCH}), analysis may fail."
68+
echo "see https://github.com/d99kris/stackusage#technical-details"
69+
fi
70+
fi
71+
}
72+
5573
if [ "${1}" == "--help" ] ; then
5674
showusage
5775
exit 0
@@ -155,6 +173,9 @@ while [ "${LIBPATHS[CNT]}" != "" ]; do
155173
LIBPATH="${LIBPATHS[CNT]}"
156174
if [ -e "${LIBPATH}" ]; then
157175

176+
# Check if libstackusage is compatible with program to analyze
177+
check_arch_compat "${LIBPATH}" "${1}"
178+
158179
# Run program
159180
if [ "${DEBUG}" == "0" ]; then
160181
SU_FILE="${TMPLOG}${OUTFILE}" \

src/stackusage.1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
2-
.TH STACKUSAGE "1" "August 2021" "stackusage v1.14" "User Commands"
2+
.TH STACKUSAGE "1" "December 2021" "stackusage v1.15" "User Commands"
33
.SH NAME
44
stackusage \- measure stack usage in applications
55
.SH SYNOPSIS
@@ -57,6 +57,6 @@ Written by Kristofer Berggren
5757
.SH "REPORTING BUGS"
5858
Report bugs at https://github.com/d99kris/stackusage
5959
.SH COPYRIGHT
60-
Copyright \(co 2015\-2020 Kristofer Berggren
60+
Copyright \(co 2015\-2021 Kristofer Berggren
6161
.PP
6262
stackusage is distributed under the BSD 3\-Clause license.

0 commit comments

Comments
 (0)