Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 154077

Summary: [binutils] x86_64-objdump -dr fails too disassmble correctly
Product: Gentoo Linux Reporter: Danny van Dyk (RETIRED) <kugelfang>
Component: New packagesAssignee: Gentoo Toolchain Maintainers <toolchain>
Status: RESOLVED INVALID    
Severity: normal CC: amd64
Priority: High    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description Danny van Dyk (RETIRED) gentoo-dev 2006-11-04 15:19:03 UTC
Consider the following listing (taken from a proprietary piece of objectcode,
thus the masquerading of symbols and offsets):

XXc0:	66 3b 05 00 00 00 00	cmp	0(%rip),%ax # XXc7 <SOMESYMBOL+0x18>
XXc3:   R_X86_64_PC32		.rodata+0xSOMECONST

Let's dissec the first instruction:
66 <-- Operand size override (to 16bit)
3b <-- CMP for one register, stored in reg part of the ModR/M byte
05 <-- ModR/M byte: 00 000 101
Mod 00 <-- Director Addressing using 32bit addresses directly following the
       ModR/M byte OR indirect addressing using the register specified by R/M
reg 000 <-- Select the accumulator as register. For 16 bit, this is %ax.
R/M 101 <-- Treat the the following byte as _direct_ address.
00 00 00 00 <-- The direct address (to be substituted by the following
            relocation)

The binary should thus be read as:
cmp ($0x00000000),%ax

I consider this a bug. Alas, I don't know if this kind of notation is used
purposefully, as using %rip there makes absolutely no sense. IIRC you can't
use %rip as source of a comparison. You'd need to first mov its contents to
a GPR.
Comment 1 Danny van Dyk (RETIRED) gentoo-dev 2006-11-05 03:19:46 UTC
INVALID. Gcc emmits this and gas groks this sample. Seems like some
undocumented/poorly documented "feature".
Comment 2 Danny van Dyk (RETIRED) gentoo-dev 2006-11-05 12:47:23 UTC
My bad, the relocation is of type 'R_X86_64_PC32', emphasis on PC32 as in
Program Counter (%rip). Didn't see that before. Sorry for all the fuss.