From owner-freebsd-hackers@FreeBSD.ORG Tue Sep 16 20:31:35 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2F86B1065673 for ; Tue, 16 Sep 2008 20:31:35 +0000 (UTC) (envelope-from nparhar@gmail.com) Received: from mail-gx0-f17.google.com (mail-gx0-f17.google.com [209.85.217.17]) by mx1.freebsd.org (Postfix) with ESMTP id DE7118FC0A for ; Tue, 16 Sep 2008 20:31:34 +0000 (UTC) (envelope-from nparhar@gmail.com) Received: by gxk10 with SMTP id 10so26338742gxk.19 for ; Tue, 16 Sep 2008 13:31:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type:content-transfer-encoding :content-disposition; bh=Nn43oeS4SfGD9sWlpHn5o5RQIpiYQxaGv78b1Zj+ew8=; b=RQMUxReiYmqas95eYHlhVljLfRB8bBTiSMUi/19/Wz9aYwNKXdmmbHwZNqGHPgMkK7 IBV5lQ34ti1ZWz4fDrjdDZH8zOlT+8j5puR/P5to2ctvheWds9lENVavesioZjV8yzNf Ib2oE9+4HuiTmtkPB6noeH8jyuXmrXP/35HYo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition; b=hUsWJVNuiiPj+ppeYk4NXgxwXQKNnJIIMY0DBd9gMo+Uda6n5WJy57kIef9cbKAJ7y 6M6yB7IT+sT5LDM0XosBirYkwPX3MkYBchsgBoWdUbpd3eoss3Uf1DeXQEDk+Pcsx7+K /s6Nwf21gTnEROfWfvmgYstJQFmYT5rtDVUIk= Received: by 10.151.108.5 with SMTP id k5mr2075238ybm.226.1221595666989; Tue, 16 Sep 2008 13:07:46 -0700 (PDT) Received: by 10.150.228.8 with HTTP; Tue, 16 Sep 2008 13:07:46 -0700 (PDT) Message-ID: Date: Tue, 16 Sep 2008 13:07:46 -0700 From: "Navdeep Parhar" To: freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: kgdb's add-kld broken on amd64 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Sep 2008 20:31:35 -0000 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 -------------------------------------------------------------------------- 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 -------------------------------------------------------------------------- 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 -------------------------------------------------------------------------- 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 --------------------------------------------------------------------------