From c982c3d232b62ea702a77e6e125707ee974fcf00 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Wed, 8 Oct 2025 11:42:43 +0200 Subject: [PATCH] first version of script to detect FLP assembled instructions in the executable --- scripts/find_fp_insn.sh | 93 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100755 scripts/find_fp_insn.sh diff --git a/scripts/find_fp_insn.sh b/scripts/find_fp_insn.sh new file mode 100755 index 0000000000..fe0090a55e --- /dev/null +++ b/scripts/find_fp_insn.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash + +# +# (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, +# Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., +# Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, +# Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other +# contributors to this repository. All Rights Reserved. +# +# This software is protected by copyright law and by international treaties. +# The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, +# Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., +# Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, +# Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other +# contributors to this repository retain full ownership rights in their respective contributions in +# the software. This notice grants no license of any kind, including but not limited to patent +# license, nor is any license granted by implication, estoppel or otherwise. +# +# Contributors are required to enter into the IVAS codec Public Collaboration agreement before making +# contributions. +# +# This software is provided "AS IS", without any express or implied warranties. The software is in the +# development stage. It is intended exclusively for experts who have experience with such software and +# solely for the purpose of inspection. All implied warranties of non-infringement, merchantability +# and fitness for a particular purpose are hereby disclaimed and excluded. +# +# Any dispute, controversy or claim arising under or in relation to providing this software shall be +# submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in +# accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and +# the United Nations Convention on Contracts on the International Sales of Goods. +# + +# fp_insn_finder.sh +# Usage: ./find_fp_insn.sh +# disassembles executable, lists common floating-point instructions + +set -euo pipefail + +if [ $# -ne 1 ]; then + echo "Usage: $0 " + echo "Find floating-point instructions in an executable based on assembler instructions" + echo "Pre-requisites: Perl or gawk" + exit 1 +fi + +EXE="$1" +if [ ! -x "$EXE" ]; then + echo "Error: '$EXE' is no executable" + exit 2 +fi + +perl_avail=0 +# check, whether we have perl installed +if command -v perl >/dev/null 2>&1; then + perl_avail=1 +fi + +gawk_avail=0 +awk_option="" +# check, whether we have awk (POSIX) or gawk (GNU) on the system +if command -v gawk >/dev/null 2>&1; then + gawk_avail=1 + awk_option="--posix" +fi + + +if [ $perl_avail -ne 0 ]; then + + objdump -d -Mintel "$EXE" \ + | perl -nE ' + # Regex for floating-point instructions + our $fp = qr/\b(?:fadd|fsub|fmul|fdiv|fld|fst|movss|movsd|addss|addsd|subss|subsd|mulss|mulsd|divss|divsd)\b/; + if (/^[0-9a-f]+ <([^>]+)>:/) { $func = $1 } + elsif (/$fp/) { say "$func: $_" } + ' + +else + + objdump -d -Mintel "$EXE" | + awk ${awk_option} ' + /^[0-9a-f]+ :.*$/, "") + func = $0 + next + } + /(^|[^[:alnum:]_])(fadd|fsub|fmul|fdiv|fld|fst|movss|movsd|addss|addsd|subss|subsd|mulss|mulsd|divss|divsd)($|[^[:alnum:]_])/ { + print func ": " $0 + } + ' + +fi -- GitLab