From nobody@FreeBSD.org  Tue Aug 23 08:56:16 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 30CB916A41F
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 23 Aug 2005 08:56:16 +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 EE9F543D46
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 23 Aug 2005 08:56:15 +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 j7N8uFs3049175
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 23 Aug 2005 08:56:15 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id j7N8uFQM049173;
	Tue, 23 Aug 2005 08:56:15 GMT
	(envelope-from nobody)
Message-Id: <200508230856.j7N8uFQM049173@www.freebsd.org>
Date: Tue, 23 Aug 2005 08:56:15 GMT
From: Kostik Belousov <kostikbel@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] libc contains relocation to the .text section
X-Send-Pr-Version: www-2.3

>Number:         85242
>Category:       i386
>Synopsis:       [libc] [patch] libc contains relocation to the .text section
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-i386
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Aug 23 09:00:39 GMT 2005
>Closed-Date:    Sat Jul 08 06:19:46 GMT 2006
>Last-Modified:  Sat Jul 08 06:19:46 GMT 2006
>Originator:     Kostik Belousov
>Release:        7-CURRENT
>Organization:
-
>Environment:
FreeBSD deviant.zoral.local 5.4-STABLE FreeBSD 5.4-STABLE #72: Fri Aug 19 11:58:24 EEST 2005     root@deviant.zoral.local:/usr/obj/usr/src/sys/DEVIANT  i386
>Description:
      All versions of FreeBSD on i386, starting from 5, constain R_386_PC32 relocations against .text in the libc.so. E.g., objdump -p /lib/libc.so shows TEXTREL dynamic entry. This leads to slower load time, since loader needs to remap libc text page rw, make reloc and remap ro; also it wastes a private page per process.

The offender is _ctx_start subroutine from lib/libc/i386/gen/_ctx_start.S. It shall use plt-based addressing of the  called symbols for pic code. Attached trivial patch solves the problem. Tested on 7-CURRENT, applicable for 5-, 6- and HEAD branches.

>How-To-Repeat:
      
>Fix:
--- orig/lib/libc/i386/gen/_ctx_start.S
+++ mod/lib/libc/i386/gen/_ctx_start.S
@@ -45,6 +45,6 @@
                                 * setup stack for completion routine;
                                 * ucp is now at top of stack
                                 */
-       call    _ctx_done       /* should never return */
-       call    abort           /* fubar */
+       call    PIC_PLT(_ctx_done)      /* should never return */
+       call    PIC_PLT(abort)          /* fubar */
        ret

>Release-Note:
>Audit-Trail:

From: Kostik Belousov <kostikbel@gmail.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: i386/85242: [patch] libc contains relocation to the .text section
Date: Tue, 23 Aug 2005 13:37:44 +0300

 Sorry,
 wrong patch.
 
 Correct one:
 
 --- orig/lib/libc/i386/gen/_ctx_start.S
 +++ mod/lib/libc/i386/gen/_ctx_start.S
 @@ -45,6 +45,10 @@
                                  * setup stack for completion routine;
                                  * ucp is now at top of stack
                                  */
 -       call    _ctx_done       /* should never return */
 -       call    abort           /* fubar */
 +#ifdef PIC
 +       PIC_PROLOGUE
 +       popl    %eax
 +#endif
 +       call    PIC_PLT(_ctx_done)      /* should never return */
 +       call    PIC_PLT(abort)          /* fubar */
         ret
 
 Tested _both_ static and dynamic linking of libc. Sorry.
State-Changed-From-To: open->closed 
State-Changed-By: kib 
State-Changed-When: Sat Jul 8 06:19:09 UTC 2006 
State-Changed-Why:  
Modified patch, as discussed with kan, is committed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=85242 
>Unformatted:
