From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9016 invoked by alias); 24 Jun 2013 16:41:53 -0000 Mailing-List: contact libc-ports-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: libc-ports-owner@sourceware.org Received: (qmail 9004 invoked by uid 89); 24 Jun 2013 16:41:52 -0000 X-Spam-SWARE-Status: No, score=-7.0 required=5.0 tests=AWL,BAYES_00,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 24 Jun 2013 16:41:52 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5OGfnah017156 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 24 Jun 2013 12:41:50 -0400 Received: from [10.3.113.21] (ovpn-113-21.phx2.redhat.com [10.3.113.21]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r5OGfnEE001584; Mon, 24 Jun 2013 12:41:49 -0400 Message-ID: <1372092109.3739.13.camel@t520.redhat.com> Subject: aarch64 prelink issue From: Mark Salter To: marcus.shawcroft@linaro.org Cc: libc-ports Date: Mon, 24 Jun 2013 16:41:00 -0000 Content-Type: text/plain; charset="us-ascii" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-SW-Source: 2013-06/txt/msg00043.txt.bz2 I'm trying to get prelink working for aarch64 and ran into a problem in the aarch64 elf_machine_dynamic() function which is simply: /* Return the link-time address of _DYNAMIC. Conveniently, this is the first element of the GOT. */ static inline ElfW(Addr) __attribute__ ((unused)) elf_machine_dynamic (void) { ElfW(Addr) addr = (ElfW(Addr)) &_DYNAMIC; return addr; } This routine is only used early before rtld has relocated itself and is expected to return the static link address of the .dynamic section. The problem is that the above code generates a got entry + reloc for the reference to &_DYNAMIC. When the rtld is prelinked, the early startup code in rtld adds the load address to an already relocated value and then segfaults as soon as it uses the bogus result. I worked around this with: diff --git a/ports/sysdeps/aarch64/dl-machine.h b/ports/sysdeps/aarch64/dl-machine.h index 94f1108..f69c618 100644 --- a/ports/sysdeps/aarch64/dl-machine.h +++ b/ports/sysdeps/aarch64/dl-machine.h @@ -36,7 +36,14 @@ elf_machine_matches_host (const ElfW(Ehdr) *ehdr) static inline ElfW(Addr) __attribute__ ((unused)) elf_machine_dynamic (void) { - ElfW(Addr) addr = (ElfW(Addr)) &_DYNAMIC; + ElfW(Addr) addr; + + asm (" \n\ + ldr %w0, 1f \n\ + b 2f \n\ +1: .word _DYNAMIC \n\ +2: \n\ + " : "=r" (addr)); return addr; } I suppose the prelink tool could work around this itself which would allow it to work on all versions of glibc. Even in that case, the above patch still saves an unnecessary got+reloc. --Mark