From patchwork Fri Mar 28 15:39:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chung-Lin Tang X-Patchwork-Id: 335 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx23.g.dreamhost.com (caibbdcaabja.dreamhost.com [208.113.200.190]) by wilcox.dreamhost.com (Postfix) with ESMTP id E83433606ED for ; Fri, 28 Mar 2014 08:39:15 -0700 (PDT) Received: by homiemail-mx23.g.dreamhost.com (Postfix, from userid 14307373) id 96F5162116D67; Fri, 28 Mar 2014 08:39:15 -0700 (PDT) X-Original-To: glibc@patchwork.siddhesh.in Delivered-To: x14307373@homiemail-mx23.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx23.g.dreamhost.com (Postfix) with ESMTPS id 5CA6062116D76 for ; Fri, 28 Mar 2014 08:39:15 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:cc :subject:content-type; q=dns; s=default; b=UZIjUPL7fT//mIxpEI+aO c9tOQn282D6h6DJVDSXhRyaXKiAe3lO8j6T0PVpBA8NAjfrGjquygKSBbZjg7MT6 iS3OoU2PRAdwgNCVvnPCiqcYYmjrHNvgb7fbPPvoUAaEux8KYLK1WSVRB9T87qxl sbrekMQAmO0/iyGs4txBbM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:cc :subject:content-type; s=default; bh=xiCYY0Kk6WCGXrmshvdeuInac6c =; b=iAVuEcPN3idfQPwNthGzKWDhQPm8qJoEHVqXDS/9pamtEMZzPdnGgYOGLs7 brqvh+YoKdepH75+/M3WglIGUqiAcRh9IHwCMoc0LFvC6qWlf/Jd46qw6qpK9qr4 Q+uz93AykeAlwqq09U/UBOXYkgOLH1yndEFfrQ6puw0b0STw= Received: (qmail 16571 invoked by alias); 28 Mar 2014 15:39:13 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 16557 invoked by uid 89); 28 Mar 2014 15:39:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, FROM_12LTRDOM autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Message-ID: <533597A8.10101@codesourcery.com> Date: Fri, 28 Mar 2014 23:39:20 +0800 From: Chung-Lin Tang User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: CC: Sandra Loosemore , "Joseph S. Myers" Subject: [PATCH 1/4] Nios II: elf subdir changes, unsigned divide in ld.so X-DH-Original-To: glibc@patchwork.siddhesh.in This patch contains the changes in the elf/ subdir. The main changes are: (1) The changes to add Nios II to elf/elf.h, machine number, relocations, etc. Pretty standard stuff copied from BFD. (2) A change in elf/dynamic-link.h, to allow a port to define a special unsigned integer divide during RTLD_BOOTSTRAP, by defining RTLD_BOOTSTRAP_UDIV. The rationale is: while Nios II does have optional hardware integer divide defined as part of the ISA spec, the current support we're working on here is for the common no-divider case, relying on libgcc __udivsi3. Unfortunately however, Nios II does not have PC-relative calls (only a direct transfer call similar to MIPS), so all subroutine calls under PIC have to go through the GOT, which... is not available yet during RTLD_BOOTSTRAP. So the RTLD_BOOTSTRAP_UDIV macro facility allows nios2 to define its own inline udiv in dl-machine.h, for use when libgcc is still not accessible. Thanks, Chung-Lin * elf/dynamic-link.h (RTLD_UDIV): New macro. (elf_machine_lazy_rel): Change divide operation to use RTLD_UDIV. * elf/elf.h (EM_ALTERA_NIOS2): New machine number for Altera Nios II. (DT_NIOS2_GP): New dynamic entry type for Nios II _gp address. (R_NIOS2_*): Define Nios II relocations. diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h index 7b3e295..67dabd5 100644 --- a/elf/dynamic-link.h +++ b/elf/dynamic-link.h @@ -97,6 +97,15 @@ elf_machine_lazy_rel (struct link_map *map, # define ELF_DURING_STARTUP (0) # endif +/* Allow targets that do not have libgcc __udivsi3 available to define + one locally. */ +# if defined RTLD_BOOTSTRAP && defined RTLD_BOOTSTRAP_UDIV +# define RTLD_UDIV(A, B) RTLD_BOOTSTRAP_UDIV (A, B) +# else +# define RTLD_UDIV(A, B) ((A) / (B)) +# endif + + /* Get the definitions of `elf_dynamic_do_rel' and `elf_dynamic_do_rela'. These functions are almost identical, so we use cpp magic to avoid duplicating their code. It cannot be done in a more general function @@ -123,7 +132,7 @@ elf_machine_lazy_rel (struct link_map *map, if (map->l_info[VERSYMIDX (DT_##RELOC##COUNT)] != NULL) \ ranges[0].nrelative \ = MIN (map->l_info[VERSYMIDX (DT_##RELOC##COUNT)]->d_un.d_val, \ - ranges[0].size / sizeof (ElfW(reloc))); \ + RTLD_UDIV (ranges[0].size, sizeof (ElfW(reloc)))); \ } \ if ((map)->l_info[DT_PLTREL] \ && (!test_rel || (map)->l_info[DT_PLTREL]->d_un.d_val == DT_##RELOC)) \ diff --git a/elf/elf.h b/elf/elf.h index 40e87b2..85401c3 100644 --- a/elf/elf.h +++ b/elf/elf.h @@ -249,6 +249,7 @@ typedef struct #define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */ #define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */ #define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ +#define EM_ALTERA_NIOS2 113 /* Altera Nios II */ #define EM_AARCH64 183 /* ARM AARCH64 */ #define EM_TILEPRO 188 /* Tilera TILEPro */ #define EM_MICROBLAZE 189 /* Xilinx MicroBlaze */ @@ -3132,6 +3133,57 @@ typedef Elf32_Addr Elf32_Conflict; #define R_MICROBLAZE_TLSGOTTPREL32 28 /* TLS Offset From Thread Pointer. */ #define R_MICROBLAZE_TLSTPREL32 29 /* TLS Offset From Thread Pointer. */ +/* Legal values for d_tag (dynamic entry type). */ +#define DT_NIOS2_GP 0x70000002 /* Address of _gp. */ + +/* Nios II relocations. */ +#define R_NIOS2_NONE 0 /* No reloc. */ +#define R_NIOS2_S16 1 /* Direct signed 16 bit. */ +#define R_NIOS2_U16 2 /* Direct unsigned 16 bit. */ +#define R_NIOS2_PCREL16 3 /* PC relative 16 bit. */ +#define R_NIOS2_CALL26 4 +#define R_NIOS2_IMM5 5 +#define R_NIOS2_CACHE_OPX 6 +#define R_NIOS2_IMM6 7 +#define R_NIOS2_IMM8 8 +#define R_NIOS2_HI16 9 +#define R_NIOS2_LO16 10 +#define R_NIOS2_HIADJ16 11 +#define R_NIOS2_BFD_RELOC_32 12 +#define R_NIOS2_BFD_RELOC_16 13 +#define R_NIOS2_BFD_RELOC_8 14 +#define R_NIOS2_GPREL 15 +#define R_NIOS2_GNU_VTINHERIT 16 +#define R_NIOS2_GNU_VTENTRY 17 +#define R_NIOS2_UJMP 18 +#define R_NIOS2_CJMP 19 +#define R_NIOS2_CALLR 20 +#define R_NIOS2_ALIGN 21 +#define R_NIOS2_GOT16 22 +#define R_NIOS2_CALL16 23 +#define R_NIOS2_GOTOFF_LO 24 +#define R_NIOS2_GOTOFF_HA 25 +#define R_NIOS2_PCREL_LO 26 +#define R_NIOS2_PCREL_HA 27 +#define R_NIOS2_TLS_GD16 28 +#define R_NIOS2_TLS_LDM16 29 +#define R_NIOS2_TLS_LDO16 30 +#define R_NIOS2_TLS_IE16 31 +#define R_NIOS2_TLS_LE16 32 +#define R_NIOS2_TLS_DTPMOD 33 +#define R_NIOS2_TLS_DTPREL 34 +#define R_NIOS2_TLS_TPREL 35 +#define R_NIOS2_COPY 36 +#define R_NIOS2_GLOB_DAT 37 +#define R_NIOS2_JUMP_SLOT 38 +#define R_NIOS2_RELATIVE 39 +#define R_NIOS2_GOTOFF 40 +#define R_NIOS2_CALL26_NOAT 41 +#define R_NIOS2_GOT_LO 42 +#define R_NIOS2_GOT_HA 43 +#define R_NIOS2_CALL_LO 44 +#define R_NIOS2_CALL_HA 45 + /* TILEPro relocations. */ #define R_TILEPRO_NONE 0 /* No reloc */ #define R_TILEPRO_32 1 /* Direct 32 bit */