From owner-freebsd-bugs@FreeBSD.ORG Tue Feb 14 06:40:05 2006 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 68E8216A420 for ; Tue, 14 Feb 2006 06:40:05 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id B310843D53 for ; Tue, 14 Feb 2006 06:40:04 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k1E6e4a1055921 for ; Tue, 14 Feb 2006 06:40:04 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k1E6e4OR055920; Tue, 14 Feb 2006 06:40:04 GMT (envelope-from gnats) Resent-Date: Tue, 14 Feb 2006 06:40:04 GMT Resent-Message-Id: <200602140640.k1E6e4OR055920@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Qu Fuping Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 656EB16A420 for ; Tue, 14 Feb 2006 06:33:07 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id 400B543D69 for ; Tue, 14 Feb 2006 06:32:59 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k1E6Wx2j089915 for ; Tue, 14 Feb 2006 06:32:59 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id k1E6WxMN089914; Tue, 14 Feb 2006 06:32:59 GMT (envelope-from nobody) Message-Id: <200602140632.k1E6WxMN089914@www.freebsd.org> Date: Tue, 14 Feb 2006 06:32:59 GMT From: Qu Fuping To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Cc: Subject: bin/93317: ld-elf.so doesn't translate unresolved weak symbol into 0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Feb 2006 06:40:05 -0000 >Number: 93317 >Category: bin >Synopsis: ld-elf.so doesn't translate unresolved weak symbol into 0 >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Feb 14 06:40:03 GMT 2006 >Closed-Date: >Last-Modified: >Originator: Qu Fuping >Release: FreeBSD 6.0-RELEASE i386 >Organization: IOS of CAS, China >Environment: FreeBSD coolq.localdomain 6.0-RELEASE FreeBSD 6.0-RELEASE #0: Thu Nov 3 09:36:13 UTC 2005 root@x64.samsco.home:/usr/obj/usr/src/sys/GENERIC i386 >Description: In ELF-spec, it quotes(page 69 of 106 from TLS-elf spec v1.2) "When the link editor searches archive libraries, it extracts archive members that contain definitions of undefined global symbols. The member's definition may be either a global or a weak symbol. The link editor does not extract archive members to resolve undefined weak symbols. Unresolved weak symbols have a zero value." I meet this problem when I implement PIE support for FreeBSD. See http://mirror.vtx.ch/hlfs/view/unstable/glibc/chapter02/pie.html for information about PIE. I modified kernel, libc, gcc, so it can generate PIE, and load it properly. But when ld-elf resolves symbols, things go wrong. The PIE contains a weak symbol named __register_frame_info, in gcc, it's called like this(in crtstuff.c) if(__register_frame_info) __register_frame_info(__EH_FRAME_BEGIN, &object); in rtld-elf/i386/reloc.c the "__register_frame_info" is resolved by reloc_non_plt .... case R_386_GLOB_DAT: { const Elf_Sym *def; const Obj_Entry *defobj; def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, false, cache); if (def == NULL) goto done; *where = (Elf_Addr) (defobj->relocbase + def->st_value); } break; .... Since __register_frame_info is a weak symbol, it should resolve to 0 according to elf-spec. find_symdef DO returns a reference to "static sym_zero", def->st_value = 0, but for PIE, defobj->relocbase != 0, so this symbol is resolved to defobj->relocbase, and the app will jump to defobj->relocbase, then segmentation fault :( >How-To-Repeat: The PIE contains lots of modifications, but I think the full description above is self-explained. >Fix: if find_symdef returns sym_zero, it should be *where = (Elf_Addr)0; >Release-Note: >Audit-Trail: >Unformatted: