Skip to contentSkip to conversation

scripts/decodecode: Decode 32-bit code correctly on x86_64

PATCH In review Andy Shevchenko 3 participants 6 messages Mar 5, 2021 – Mar 8, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/decodecode: Decode 32-bit code correctly on x86_64

On x86_64 host the objdump uses current architecture which is 64-bit and hence decodecode shows wrong instructions.

Fix it by supplying '-M i386' in case of ARCH i?86 or x86.

---
 scripts/decodecode | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
scripts/decodecode +9 -5
index 31d884e35f2f..020a84982249 100755
@@ -75,21 +75,25 @@ disas() {
 
 	${CROSS_COMPILE}as $AFLAGS -o $t.o $t.s > /dev/null 2>&1
 
-	if [ "$ARCH" = "arm" ]; then
+	case "$ARCH" in
+	arm)
 		if [ $width -eq 2 ]; then
 			OBJDUMPFLAGS="-M force-thumb"
 		fi
 
 		${CROSS_COMPILE}strip $t.o
-	fi
-
-	if [ "$ARCH" = "arm64" ]; then
+		;;
+	arm64)
 		if [ $width -eq 4 ]; then
 			type=inst
 		fi
 
 		${CROSS_COMPILE}strip $t.o
-	fi
+		;;
+	i?86|x86)
+			OBJDUMPFLAGS="-M i386"
+		;;
+	esac
 
 	if [ $pc_sub -ne 0 ]; then
 		if [ $PC ]; then
Signature · 1 line
2.30.1
#1 lore raw
Quoted 4 lines · Andy Shevchenko

On x86_64 host the objdump uses current architecture which is 64-bit and hence decodecode shows wrong instructions.

Fix it by supplying '-M i386' in case of ARCH i?86 or x86.

At the beginning of the script says:

# e.g., to decode an i386 oops on an x86_64 system, use:
# AFLAGS=--32 decodecode < 386.oops

What kind of oops are you decoding such that that doesn't work for you?

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

SUSE Software Solutions Germany GmbH, GF: Felix Imendörffer, HRB 36809, AG Nürnberg
#2 lore raw
Quoted 5 lines · Borislav Petkov
Quoted 3 lines · Andy Shevchenko

On x86_64 host the objdump uses current architecture which is 64-bit and hence decodecode shows wrong instructions.

Quoted 8 lines
Quoted 1 line

Fix it by supplying '-M i386' in case of ARCH i?86 or x86.

At the beginning of the script says:

# e.g., to decode an i386 oops on an x86_64 system, use:
# AFLAGS=--32 decodecode < 386.oops

What kind of oops are you decoding such that that doesn't work for you?

It works, but... The question here is why the script behaviour depends so much on the architecture in question (by environment). ARM stuff is using traditional ARCH (and that's what I have expected to work), while x86 has a set of other variables.
So, I have to rephrase the commit message then and do actually an alias when ARCH is set in a certain way, Would it be better?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 6 lines · Andy Shevchenko

It works, but... The question here is why the script behaviour depends so much on the architecture in question (by environment). ARM stuff is using traditional ARCH (and that's what I have expected to work), while x86 has a set of other variables.
So, I have to rephrase the commit message then and do actually an alias when ARCH is set in a certain way, Would it be better?

No, I have no clue what you're trying to accomplish. You wanted to supply ARCH when decoding a 32-bit oops because you expected ARCH to work...?

AFLAGS has always been there, ARM folks added ARCH AFAIR. Also, you need AFLAGS to compile the snippet in the correct bitsize.

And there's a usage note at the beginning of the script and I always read it to make sure I'm using it right.

So what's the problem again?

Signature · 4 lines
Regards/Gruss,
    Boris.

SUSE Software Solutions Germany GmbH, GF: Felix Imendörffer, HRB 36809, AG Nürnberg
#4 lore raw
Quoted 9 lines · Borislav Petkov
Quoted 6 lines · Andy Shevchenko

It works, but... The question here is why the script behaviour depends so much on the architecture in question (by environment). ARM stuff is using traditional ARCH (and that's what I have expected to work), while x86 has a set of other variables.
So, I have to rephrase the commit message then and do actually an alias when ARCH is set in a certain way, Would it be better?

Quoted 3 lines

No, I have no clue what you're trying to accomplish. You wanted to supply ARCH when decoding a 32-bit oops because you expected ARCH to work...?

Yes.

Quoted 7 lines

AFLAGS has always been there, ARM folks added ARCH AFAIR. Also, you need AFLAGS to compile the snippet in the correct bitsize.

And there's a usage note at the beginning of the script and I always read it to make sure I'm using it right.

So what's the problem again?

Inconsistency.
For the ARM we have to provide ARCH, for x86 a variety of all the flags.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 1 line · Andy Shevchenko

For the ARM we have to provide ARCH, for x86 a variety of all the flags.

For x86 you have to provide only AFLAGS.

If you want to make this script parse proper cmdline options like --arch, --width and --help along with keeping the old methods functional, I guess that would be ok.

Signature · 4 lines
Regards/Gruss,
    Boris.

SUSE Software Solutions Germany GmbH, GF: Felix Imendörffer, HRB 36809, AG Nürnberg