From patchwork Mon Feb 25 16:37:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Venkataramanan Kumar X-Patchwork-Id: 15065 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 3965E23E02 for ; Mon, 25 Feb 2013 16:37:35 +0000 (UTC) Received: from mail-ve0-f180.google.com (mail-ve0-f180.google.com [209.85.128.180]) by fiordland.canonical.com (Postfix) with ESMTP id D0BCDA18A3A for ; Mon, 25 Feb 2013 16:37:34 +0000 (UTC) Received: by mail-ve0-f180.google.com with SMTP id jx10so2344502veb.11 for ; Mon, 25 Feb 2013 08:37:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:mime-version:x-received:in-reply-to:references:date :message-id:subject:from:to:cc:content-type:x-gm-message-state; bh=/Ze9XehfpnhbX34YhD1zULve6ULw0rCMd7+M3nro+M0=; b=eIZqeAWghHTCtJh7JkLbOZcVAQGu0S4aTUs4FTAtrM89KTHvXlt/+xRzWc6P9GsHko w2OBeZKznZ1lhzmUH+hxdpIjCWBxnZvHhcsAgT4ZDEahte1BQFRUiWnVBqh1oBvuoH2h OxMm7lgf0hSDq/vOuPla8OB1CVI43CroXxz7lbnc2hPsDe4GKBLFIFcf/+4omt20Lmwb e+WegIwaMuc08DRZ1I3gilAoJPKiSxylzkA1fUOQt3QLRjLTZJa9iVok7YbnphWW2qED qH2FWMwLCvInKdj+vcibUQlXt7o4ViVLB6nGuluc9Y+5SWKqau3GDxhQGpSatt2Eh6uz 7itg== X-Received: by 10.52.177.163 with SMTP id cr3mr8828363vdc.94.1361810254266; Mon, 25 Feb 2013 08:37:34 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patch@linaro.org Received: by 10.58.145.101 with SMTP id st5csp67211veb; Mon, 25 Feb 2013 08:37:33 -0800 (PST) X-Received: by 10.43.134.202 with SMTP id id10mr4669748icc.46.1361810252945; Mon, 25 Feb 2013 08:37:32 -0800 (PST) Received: from mail-ie0-x22d.google.com (mail-ie0-x22d.google.com [2607:f8b0:4001:c03::22d]) by mx.google.com with ESMTPS id ce6si14407927icc.105.2013.02.25.08.37.32 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Feb 2013 08:37:32 -0800 (PST) Received-SPF: neutral (google.com: 2607:f8b0:4001:c03::22d is neither permitted nor denied by best guess record for domain of venkataramanan.kumar@linaro.org) client-ip=2607:f8b0:4001:c03::22d; Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:4001:c03::22d is neither permitted nor denied by best guess record for domain of venkataramanan.kumar@linaro.org) smtp.mail=venkataramanan.kumar@linaro.org Received: by mail-ie0-f173.google.com with SMTP id 9so3319427iec.4 for ; Mon, 25 Feb 2013 08:37:32 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.42.28.130 with SMTP id n2mr4753782icc.6.1361810252285; Mon, 25 Feb 2013 08:37:32 -0800 (PST) Received: by 10.64.170.206 with HTTP; Mon, 25 Feb 2013 08:37:32 -0800 (PST) In-Reply-To: References: Date: Mon, 25 Feb 2013 22:07:32 +0530 Message-ID: Subject: Re: [Patch, AARCH64] gc-section support From: Venkataramanan Kumar To: Yufeng Zhang Cc: binutils@sourceware.org, Patch Tracking X-Gm-Message-State: ALoCoQkCnW9C18+G6oL3wDqhUO7T0Jykku5xlCfk4QhYEvpnXcYQenvfdSSbsjHuJv+rC8tnqkk1 Hi Yufeng, I have done the formating changes and used normal diff instaed of cvs diff now. Attached is the updated patch. regards, Venkat. > > Hi Venkat, > > Thanks for the patch. > > Can you please generate the patch using "diff -u -p"? This will make > the patch easier to review. Also the indent is not consistent with the > existing style, which is hard tab(s) plus spaces. Can you please > correct it as well. > > Thanks, > Yufeng > > On 02/22/13 17:25, Venkataramanan Kumar wrote: >> Hi Maintainers, >> >> Attached is a small patch that enables gc-section support for AARCH64. >> >> In the sweep hook I have handled TLS and GOT related relocs that were >> already supported in that file. >> >> Make check passes along with the gc-section tests. >> >> I used the patched binutils to build gcc for aarch64-none-elf target >> and tested the gcc testsuite in v8 foundation model. >> >> Ok for trunk? >> >> regards, >> Venkat, >> >> >> ChangeLog: >> >> BFD >> >> 2013-02-21 Venkataramanan Kumar >> >> * elf64-aarch64.c (elf_backend_can_gc_sections): Enable >> gc-section support. >> (elf64_aarch64_gc_sweep_hook): Handle GOT, TLS and PLT related r > elocs. >> >> LD >> >> 2013-02-21 Venkataramanan Kumar >> >> * lib/ld-lib.exp (check_gc_sections_available): Remove aarch64 >> from list of >> targets that don't support gc-section. >> diff -x '*CVS*' -u -p -r src/bfd/elf64-aarch64.c src-patch/bfd/elf64-aarch64.c --- src/bfd/elf64-aarch64.c 2013-02-21 08:32:30.000000000 +0530 +++ src-patch/bfd/elf64-aarch64.c 2013-02-25 20:34:58.137044054 +0530 @@ -4866,8 +4866,8 @@ elf64_aarch64_print_private_bfd_data (bf return TRUE; } -/* Update the got entry reference counts for the section being removed. */ +/* Update the got entry reference counts for the section being removed. */ static bfd_boolean elf64_aarch64_gc_sweep_hook (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *info ATTRIBUTE_UNUSED, @@ -4875,6 +4875,139 @@ elf64_aarch64_gc_sweep_hook (bfd *abfd A const Elf_Internal_Rela * relocs ATTRIBUTE_UNUSED) { + struct elf64_aarch64_link_hash_table *htab; + Elf_Internal_Shdr *symtab_hdr; + struct elf_link_hash_entry **sym_hashes; + bfd_signed_vma *local_got_refcounts; + const Elf_Internal_Rela *rel, *relend; + + if (info->relocatable) + return TRUE; + + htab = elf64_aarch64_hash_table (info); + + if (htab == NULL) + return FALSE; + + elf_section_data (sec)->local_dynrel = NULL; + + symtab_hdr = &elf_symtab_hdr (abfd); + sym_hashes = elf_sym_hashes (abfd); + + local_got_refcounts = elf_local_got_refcounts (abfd); + + relend = relocs + sec->reloc_count; + for (rel = relocs; rel < relend; rel++) + { + unsigned long r_symndx; + unsigned int r_type; + struct elf_link_hash_entry *h = NULL; + + r_symndx = ELF64_R_SYM (rel->r_info); + + if (r_symndx >= symtab_hdr->sh_info) + { + struct elf64_aarch64_link_hash_entry *eh; + struct elf_dyn_relocs **pp; + struct elf_dyn_relocs *p; + + h = sym_hashes[r_symndx - symtab_hdr->sh_info]; + while (h->root.type == bfd_link_hash_indirect + || h->root.type == bfd_link_hash_warning) + h = (struct elf_link_hash_entry *) h->root.u.i.link; + eh = (struct elf64_aarch64_link_hash_entry *) h; + + for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) + { + if (p->sec == sec) + { + /* Everything must go for SEC. */ + *pp = p->next; + break; + } + } + } + else + { + Elf_Internal_Sym *isym; + + /* A local symbol. */ + isym = bfd_sym_from_r_symndx (&htab->sym_cache, + abfd, r_symndx); + if (isym == NULL) + return FALSE; + } + + r_type = ELF64_R_TYPE (rel->r_info); + r_type = aarch64_tls_transition (abfd,info, r_type, h ,r_symndx); + switch (r_type) + { + case R_AARCH64_LD64_GOT_LO12_NC: + case R_AARCH64_GOT_LD_PREL19: + case R_AARCH64_ADR_GOT_PAGE: + case R_AARCH64_TLSGD_ADR_PAGE21: + case R_AARCH64_TLSGD_ADD_LO12_NC: + case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: + case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: + case R_AARCH64_TLSLE_ADD_TPREL_LO12: + case R_AARCH64_TLSLE_ADD_TPREL_HI12: + case R_AARCH64_TLSLE_ADD_TPREL_LO12_NC: + case R_AARCH64_TLSLE_MOVW_TPREL_G2: + case R_AARCH64_TLSLE_MOVW_TPREL_G1: + case R_AARCH64_TLSLE_MOVW_TPREL_G1_NC: + case R_AARCH64_TLSLE_MOVW_TPREL_G0: + case R_AARCH64_TLSLE_MOVW_TPREL_G0_NC: + case R_AARCH64_TLSDESC_ADR_PAGE: + case R_AARCH64_TLSDESC_ADD_LO12_NC: + case R_AARCH64_TLSDESC_LD64_LO12_NC: + if (h != NULL) + { + if (h->got.refcount > 0) + h->got.refcount -= 1; + } + else if (local_got_refcounts != NULL) + { + if (local_got_refcounts[r_symndx] > 0) + local_got_refcounts[r_symndx] -= 1; + } + break; + + case R_AARCH64_ADR_PREL_PG_HI21_NC: + case R_AARCH64_ADR_PREL_PG_HI21: + case R_AARCH64_ADR_PREL_LO21: + if (h != NULL && info->executable) + { + if (h->plt.refcount > 0) + h->plt.refcount -= 1; + } + break; + + case R_AARCH64_CALL26: + case R_AARCH64_JUMP26: + /* If this is a local symbol then we resolve it + directly without creating a PLT entry. */ + if (h == NULL) + continue; + + if (h->plt.refcount > 0) + h->plt.refcount -= 1; + break; + + case R_AARCH64_ABS64: + if (h != NULL && info->executable) + { + if (h->plt.refcount > 0) + h->plt.refcount -= 1; + } + break; + + default: + break; + + } + + } + return TRUE; } @@ -7049,7 +7182,7 @@ const struct elf_size_info elf64_aarch64 elf64_aarch64_size_info #define elf_backend_can_refcount 1 -#define elf_backend_can_gc_sections 0 +#define elf_backend_can_gc_sections 1 #define elf_backend_plt_readonly 1 #define elf_backend_want_got_plt 1 #define elf_backend_want_plt_sym 0 diff -x '*CVS*' -u -p -r src/ld/testsuite/lib/ld-lib.exp src-patch/ld/testsuite/lib/ld-lib.exp --- src/ld/testsuite/lib/ld-lib.exp 2013-02-19 06:40:06.000000000 +0530 +++ src-patch/ld/testsuite/lib/ld-lib.exp 2013-02-25 20:34:46.737044219 +0530 @@ -1518,8 +1518,7 @@ proc check_gc_sections_available { } { if {![info exists gc_sections_available_saved]} { # Some targets don't support gc-sections despite whatever's # advertised by ld's options. - if {[istarget aarch64*-*-*] - || [istarget arc-*-*] + if {[istarget arc-*-*] || [istarget d30v-*-*] || [istarget dlx-*-*] || [istarget i960-*-*]