kgdb's add-kld broken on amd64

Navdeep Parhar nparhar at gmail.com
Tue Sep 16 20:31:35 UTC 2008


Hello everyone,

The add-kld command in kgdb does not work as expected on amd64
(I'm using a recent HEAD, problem may affect others too).  It uses
the same address for all sections:

(kgdb) add-kld if_cxgb.ko
add symbol table from file "/boot/kernel/if_cxgb.ko" at
	.text_addr = 0xffffffff81022000
	.rodata_addr = 0xffffffff81022000
	.rodata.str1.8_addr = 0xffffffff81022000
	.rodata.str1.1_addr = 0xffffffff81022000
	set_modmetadata_set_addr = 0xffffffff81022000
	set_sysctl_set_addr = 0xffffffff81022000
	set_sysinit_set_addr = 0xffffffff81022000
	set_sysuninit_set_addr = 0xffffffff81022000
	.data_addr = 0xffffffff81022000
	.bss_addr = 0xffffffff81022000
(y or n)

This is not correct.  The .text section's address is OK but the
others are not.

The problem seems to be that all amd64 kernel objects have VMA set
to 0 for all sections.  add_section() in gnu/usr.bin/gdb/kgdb/kld.c
uses this VMA to adjust the address of the section:

address = asi->base_addr + bfd_get_section_vma(bfd, sect);

objdump -h shows that the userland objects on amd64 and all
objects (kernel + userland) on i386 set VMA.  It is only the
kernel objects on amd64 that have VMA = 0.  (sample output from
amd64 and i386 machines appended at the end)

For the time being I've patched kgdb to consider the file offset
and not the VMA while calculating the section address.  It seems
to work but is probably not the right way to fix the problem.

Any thoughts?

Regards,
Navdeep

--------------------------------------------------------------------------
amd64# objdump -h /boot/kernel/if_cxgb.ko

/boot/kernel/if_cxgb.ko:     file format elf64-x86-64

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .text         0001c444  0000000000000000  0000000000000000  00000040  2**4
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  1 .rodata       00000d91  0000000000000000  0000000000000000  0001c4a0  2**5
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
  2 .rodata.str1.8 000018fa  0000000000000000  0000000000000000  0001d238  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .rodata.str1.1 00001b94  0000000000000000  0000000000000000  0001eb32  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
<snipped>
--------------------------------------------------------------------------
amd64# objdump -h /bin/ls

/bin/ls:     file format elf64-x86-64

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .interp       00000015  00000000004001c8  00000000004001c8  000001c8  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  1 .note.ABI-tag 00000018  00000000004001e0  00000000004001e0  000001e0  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  2 .hash         00000274  00000000004001f8  00000000004001f8  000001f8  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .dynsym       00000840  0000000000400470  0000000000400470  00000470  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
<snipped>
--------------------------------------------------------------------------
i386# objdump -h /boot/kernel/if_cxgb.ko

/boot/kernel/if_cxgb.ko:     file format elf32-i386-freebsd

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .hash         0000064c  00000094  00000094  00000094  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  1 .dynsym       00000cc0  000006e0  000006e0  000006e0  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  2 .dynstr       00000a5e  000013a0  000013a0  000013a0  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
<snipped>
--------------------------------------------------------------------------
i386# objdump -h /bin/ls

/bin/ls:     file format elf32-i386-freebsd

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .interp       00000015  08048114  08048114  00000114  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  1 .note.ABI-tag 00000018  0804812c  0804812c  0000012c  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  2 .hash         00000264  08048144  08048144  00000144  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .dynsym       00000540  080483a8  080483a8  000003a8  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
<snipped>
--------------------------------------------------------------------------


More information about the freebsd-hackers mailing list