From patchwork Thu Mar 22 14:38:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christophe Lyon X-Patchwork-Id: 132296 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp930795ljb; Thu, 22 Mar 2018 07:40:20 -0700 (PDT) X-Google-Smtp-Source: AG47ELvOz8S8g8I8X6Lfdj87hg6/Aw+ozZUfp/lkvhLwsMyioWjTJ52smRk6u0TN8lqR4kyhN4Jl X-Received: by 2002:a17:902:24:: with SMTP id 33-v6mr25365476pla.341.1521729620347; Thu, 22 Mar 2018 07:40:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521729620; cv=none; d=google.com; s=arc-20160816; b=G+/dW+EzVrcBwCtEbzPKwT3GyrdFyXQDnvt5kscIdJ2n/VhUpL3b8oI568KOWSUC+X SvZeJKO+zDUZwAI80CRq5fn6iQ5RZ8z2/hGXlUNVBIxa0gIG5q1tlFgqt0uPin5mFnvX h5cdoLOZM8tIw7439NCWU5FKGJnjL5+A8GRF8zZ/Hm4wcaBG/qFiHeF47gMho3uWhjkw HYf5ZNetNSQiU7r4DY89uQqv1cO2OwXJ2woTbYFDZxi+puW71ouGUbgIlXGyj8TFVJII aeE+J40FpGcnyi0wYaO9NwGfrHJtgG/Q5RdWGGFrgjnZnpJ260daphepB9Z4YDQhBwKr gcMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:delivered-to:sender:list-help :list-post:list-archive:list-subscribe:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=CmqDTcLP9BZpktFBlxPdwZTcfkQPbU46m4kCZjGT6pw=; b=YrSMt6ziRcNiUTm+MbOJD1BikIODlPgoJk0dEK45Rf5iwMqYxvACSgJvgJxBascT3P iGo/Y7dWjMf2u3vwWFy26w+PbiEvTtUc3CmY2ydnSZwQvQjqp6hGrYP+t0N/a+K+Iriw LMuU+qVP7ocq9Zygpa/AO680wRdxYRcYaxETCs2WVaFgz9qRvbd1FqShl/YjvEr8TNVF HtsUL8vI6ueCbfL+ms6LtvxSyKMFB0acr0Ej7TfS78YOxHV44jiUhANp5elK1fFSbdm1 ICWT943upNEklwNO0JerKOdgfYtMrX+lMN1idaxbtmjIhuAT2aOsZPG1+k0c5hhtQwxR xpVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=NhXuItsP; spf=pass (google.com: domain of binutils-return-101082-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=binutils-return-101082-patch=linaro.org@sourceware.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id u24si4897507pfh.326.2018.03.22.07.40.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Mar 2018 07:40:20 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-return-101082-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=NhXuItsP; spf=pass (google.com: domain of binutils-return-101082-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=binutils-return-101082-patch=linaro.org@sourceware.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; q=dns; s=default; b=p5Li2EPkBudHPU4QxEygC74ofc542VooVmM5BTXopqJ tp2miUwPMfYWRVEK9URljL0A2ebHM4IfIATJH0OK6cM4IiFHZKOYBECh6kdVlJaZ vVUS8B3eGkaDtsEBDIr3+vb3WZoIsYinFMtJpkdpYgOmBFxRQh1g18en7A5RiOwM = 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:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; s=default; bh=Gh9xgXfI0ockZ7mOmVMnos5e5ik=; b=NhXuItsP87CA7oHPi r8prq9EVFxrfMQqigRZ2lkT6hOvd+I+0NOPWQmj880IKjjZ5a+BorZUVzhcq+Txm UnQ8QLvlrYZQ/SBiR+EurvZRnbGdGnus8y/LxzWB0GMiNec+tVm59Gjuj1Xi1PhY FFLviID5UMan8TjFAfE+4Q2Qq4= Received: (qmail 66494 invoked by alias); 22 Mar 2018 14:40:06 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Delivered-To: mailing list binutils@sourceware.org Received: (qmail 63553 invoked by uid 89); 22 Mar 2018 14:40:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-27.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx07-00178001.pphosted.com Received: from mx08-00178001.pphosted.com (HELO mx07-00178001.pphosted.com) (91.207.212.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 22 Mar 2018 14:39:59 +0000 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w2MEdAn9000359 for ; Thu, 22 Mar 2018 15:39:56 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2gv6742kth-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Thu, 22 Mar 2018 15:39:56 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id E096A31 for ; Thu, 22 Mar 2018 14:39:55 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag5node1.st.com [10.75.127.13]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id AA9A52B0A for ; Thu, 22 Mar 2018 14:39:55 +0000 (GMT) Received: from gnx2104.gnb.st.com (10.75.127.51) by SFHDAG5NODE1.st.com (10.75.127.13) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Thu, 22 Mar 2018 15:39:55 +0100 From: Christophe Lyon To: Subject: [ARM-FDPIC 03/12] [ARM] Add FDPIC relocations definitions Date: Thu, 22 Mar 2018 15:38:21 +0100 Message-ID: <20180322143850.1766-4-christophe.lyon@st.com> In-Reply-To: <20180322143850.1766-1-christophe.lyon@st.com> References: <20180322143850.1766-1-christophe.lyon@st.com> MIME-Version: 1.0 X-ClientProxiedBy: SFHDAG4NODE1.st.com (10.75.127.10) To SFHDAG5NODE1.st.com (10.75.127.13) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-22_07:, , signatures=0 X-IsSubscribed: yes Add FDPIC relocation definitions in BFD and gas. Gas rejects them if the --fdpic option was not specified. 2018-XX-XX Christophe Lyon Mickaël Guêné bfd/ * bfd-in2.c (BFD_RELOC_ARM_GOTFUNCDESC) (BFD_RELOC_ARM_GOTOFFFUNCDESC, BFD_RELOC_ARM_FUNCDESC) (BFD_RELOC_ARM_FUNCDESC_VALUE): New. * elf32-arm.c (elf32_arm_howto_table_2): Add R_ARM_GOTFUNCDESC, R_ARM_GOTOFFFUNCDESC, R_ARM_FUNCDESC, R_ARM_FUNCDESC_VALUE. (elf32_arm_howto_from_type): Take new members of elf32_arm_howto_table_2 into account. (elf32_arm_reloc_map): Add BFD_RELOC_ARM_GOTFUNCDESC, BFD_RELOC_ARM_GOTOFFFUNCDESC, BFD_RELOC_ARM_FUNCDESC, BFD_RELOC_ARM_FUNCDESC_VALUE. * reloc.c: Add BFD_RELOC_ARM_GOTFUNCDESC, BFD_RELOC_ARM_GOTOFFFUNCDESC, BFD_RELOC_ARM_FUNCDESC, BFD_RELOC_ARM_FUNCDESC_VALUE. gas/ * config/tc-arm.c (reloc_names): Add gotfuncdesc, gotofffuncdesc, funcdesc. (md_apply_fix): Support the new relocations. (tc_gen_reloc): Likewise. * testsuite/gas/arm/reloc-fdpic.d: New. * testsuite/gas/arm/reloc-fdpic.s: New. include/ * elf/arm.h (R_ARM_GOTFUNCDESC, R_ARM_GOTOFFFUNCDESC) (R_ARM_FUNCDESC) (R_ARM_FUNCDESC_VALUE): Define new relocations. --- bfd/bfd-in2.h | 6 ++++ bfd/elf32-arm.c | 63 +++++++++++++++++++++++++++++++++++-- bfd/reloc.c | 11 +++++++ gas/config/tc-arm.c | 27 +++++++++++++++- gas/testsuite/gas/arm/reloc-fdpic.d | 20 ++++++++++++ gas/testsuite/gas/arm/reloc-fdpic.s | 9 ++++++ include/elf/arm.h | 4 +++ 7 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 gas/testsuite/gas/arm/reloc-fdpic.d create mode 100644 gas/testsuite/gas/arm/reloc-fdpic.s -- 2.6.3 diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 9742c1a..0c2279f 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -3565,6 +3565,12 @@ pc-relative or some form of GOT-indirect relocation. */ BFD_RELOC_ARM_THUMB_MOVW_PCREL, BFD_RELOC_ARM_THUMB_MOVT_PCREL, +/* ARM FDPIC specific relocations. */ + BFD_RELOC_ARM_GOTFUNCDESC, + BFD_RELOC_ARM_GOTOFFFUNCDESC, + BFD_RELOC_ARM_FUNCDESC, + BFD_RELOC_ARM_FUNCDESC_VALUE, + /* Relocations for setting up GOTs and PLTs for shared libraries. */ BFD_RELOC_ARM_JUMP_SLOT, BFD_RELOC_ARM_GLOB_DAT, diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index a0b0be3..3805f71 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -1746,7 +1746,7 @@ static reloc_howto_type elf32_arm_howto_table_1[] = }; /* 160 onwards: */ -static reloc_howto_type elf32_arm_howto_table_2[1] = +static reloc_howto_type elf32_arm_howto_table_2[5] = { HOWTO (R_ARM_IRELATIVE, /* type */ 0, /* rightshift */ @@ -1760,7 +1760,59 @@ static reloc_howto_type elf32_arm_howto_table_2[1] = TRUE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ - FALSE) /* pcrel_offset */ + FALSE), /* pcrel_offset */ + HOWTO (R_ARM_GOTFUNCDESC, /* type */ + 0, /* rightshift */ + 2, /* size (0 = byte, 1 = short, 2 = long) */ + 32, /* bitsize */ + FALSE, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_bitfield,/* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_ARM_GOTFUNCDESC", /* name */ + FALSE, /* partial_inplace */ + 0, /* src_mask */ + 0xffffffff, /* dst_mask */ + FALSE), /* pcrel_offset */ + HOWTO (R_ARM_GOTOFFFUNCDESC, /* type */ + 0, /* rightshift */ + 2, /* size (0 = byte, 1 = short, 2 = long) */ + 32, /* bitsize */ + FALSE, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_bitfield,/* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_ARM_GOTOFFFUNCDESC",/* name */ + FALSE, /* partial_inplace */ + 0, /* src_mask */ + 0xffffffff, /* dst_mask */ + FALSE), /* pcrel_offset */ + HOWTO (R_ARM_FUNCDESC, /* type */ + 0, /* rightshift */ + 2, /* size (0 = byte, 1 = short, 2 = long) */ + 32, /* bitsize */ + FALSE, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_bitfield,/* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_ARM_FUNCDESC", /* name */ + FALSE, /* partial_inplace */ + 0, /* src_mask */ + 0xffffffff, /* dst_mask */ + FALSE), /* pcrel_offset */ + HOWTO (R_ARM_FUNCDESC_VALUE, /* type */ + 0, /* rightshift */ + 2, /* size (0 = byte, 1 = short, 2 = long) */ + 64, /* bitsize */ + FALSE, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_bitfield,/* complain_on_overflow */ + bfd_elf_generic_reloc, /* special_function */ + "R_ARM_FUNCDESC_VALUE",/* name */ + FALSE, /* partial_inplace */ + 0, /* src_mask */ + 0xffffffff, /* dst_mask */ + FALSE), /* pcrel_offset */ }; /* 249-255 extended, currently unused, relocations: */ @@ -1829,7 +1881,8 @@ elf32_arm_howto_from_type (unsigned int r_type) if (r_type < ARRAY_SIZE (elf32_arm_howto_table_1)) return &elf32_arm_howto_table_1[r_type]; - if (r_type == R_ARM_IRELATIVE) + if (r_type >= R_ARM_IRELATIVE + && r_type < R_ARM_IRELATIVE + ARRAY_SIZE (elf32_arm_howto_table_2)) return &elf32_arm_howto_table_2[r_type - R_ARM_IRELATIVE]; if (r_type >= R_ARM_RREL32 @@ -1913,6 +1966,10 @@ static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] = {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32}, {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32}, {BFD_RELOC_ARM_IRELATIVE, R_ARM_IRELATIVE}, + {BFD_RELOC_ARM_GOTFUNCDESC, R_ARM_GOTFUNCDESC}, + {BFD_RELOC_ARM_GOTOFFFUNCDESC, R_ARM_GOTOFFFUNCDESC}, + {BFD_RELOC_ARM_FUNCDESC, R_ARM_FUNCDESC}, + {BFD_RELOC_ARM_FUNCDESC_VALUE, R_ARM_FUNCDESC_VALUE}, {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT}, {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY}, {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC}, diff --git a/bfd/reloc.c b/bfd/reloc.c index 42e35b9..5715317 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -3217,6 +3217,17 @@ ENUMDOC Low and High halfword relocations for MOVW and MOVT instructions. ENUM + BFD_RELOC_ARM_GOTFUNCDESC +ENUMX + BFD_RELOC_ARM_GOTOFFFUNCDESC +ENUMX + BFD_RELOC_ARM_FUNCDESC +ENUMX + BFD_RELOC_ARM_FUNCDESC_VALUE +ENUMDOC + ARM FDPIC specific relocations. + +ENUM BFD_RELOC_ARM_JUMP_SLOT ENUMX BFD_RELOC_ARM_GLOB_DAT diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c index 8a3a282..e869084 100644 --- a/gas/config/tc-arm.c +++ b/gas/config/tc-arm.c @@ -19320,7 +19320,13 @@ static struct reloc_entry reloc_names[] = { "tlscall", BFD_RELOC_ARM_TLS_CALL}, { "TLSCALL", BFD_RELOC_ARM_TLS_CALL}, { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ}, - { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ} + { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}, + { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC }, + { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC }, + { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC }, + { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC }, + { "funcdesc", BFD_RELOC_ARM_FUNCDESC }, + { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC } }; #endif @@ -24024,6 +24030,22 @@ md_apply_fix (fixS * fixP, if (fixP->fx_done || !seg->use_rela_p) md_number_to_chars (buf, fixP->fx_offset, 4); break; + + /* Relocations for FDPIC. */ + case BFD_RELOC_ARM_GOTFUNCDESC: + case BFD_RELOC_ARM_GOTOFFFUNCDESC: + case BFD_RELOC_ARM_FUNCDESC: + if (arm_fdpic) + { + if (fixP->fx_done || !seg->use_rela_p) + md_number_to_chars (buf, 0, 4); + } + else + { + as_bad_where (fixP->fx_file, fixP->fx_line, + _("Relocation supported only in FDPIC mode")); + } + break; #endif case BFD_RELOC_RVA: @@ -24785,6 +24807,9 @@ tc_gen_reloc (asection *section, fixS *fixp) case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC: case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC: case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC: + case BFD_RELOC_ARM_GOTFUNCDESC: + case BFD_RELOC_ARM_GOTOFFFUNCDESC: + case BFD_RELOC_ARM_FUNCDESC: code = fixp->fx_r_type; break; diff --git a/gas/testsuite/gas/arm/reloc-fdpic.d b/gas/testsuite/gas/arm/reloc-fdpic.d new file mode 100644 index 0000000..768c3a1 --- /dev/null +++ b/gas/testsuite/gas/arm/reloc-fdpic.d @@ -0,0 +1,20 @@ +#as: --fdpic +#objdump: -dr --show-raw-insn +#name: FDPIC relocations +# This test is only valid on ELF based ports. +#not-target: *-*-*coff *-*-pe *-*-wince *-*-*aout* *-*-netbsd *-*-riscix* + +.*: +file format .*arm.* + + +Disassembly of section .text: + +00000000 : +.* + 0: R_ARM_GOTFUNCDESC myfunc + 4: R_ARM_GOTOFFFUNCDESC myfunc + 8: R_ARM_FUNCDESC myfunc + +0000000c : + c: e12fff1e bx lr +.* \ No newline at end of file diff --git a/gas/testsuite/gas/arm/reloc-fdpic.s b/gas/testsuite/gas/arm/reloc-fdpic.s new file mode 100644 index 0000000..cbb61c5 --- /dev/null +++ b/gas/testsuite/gas/arm/reloc-fdpic.s @@ -0,0 +1,9 @@ + .syntax unified + + .word myfunc(GOTFUNCDESC) + .word myfunc(GOTOFFFUNCDESC) + .word myfunc(FUNCDESC) + + .type myfunc, %function +myfunc: + bx lr diff --git a/include/elf/arm.h b/include/elf/arm.h index fb9c5f6..158f7b1 100644 --- a/include/elf/arm.h +++ b/include/elf/arm.h @@ -240,6 +240,10 @@ START_RELOC_NUMBERS (elf_arm_reloc_type) RELOC_NUMBER (R_ARM_THM_ALU_ABS_G3_NC,135) RELOC_NUMBER (R_ARM_IRELATIVE, 160) + RELOC_NUMBER (R_ARM_GOTFUNCDESC, 161) + RELOC_NUMBER (R_ARM_GOTOFFFUNCDESC, 162) + RELOC_NUMBER (R_ARM_FUNCDESC, 163) + RELOC_NUMBER (R_ARM_FUNCDESC_VALUE, 164) /* Extensions? R=read-only? */ RELOC_NUMBER (R_ARM_RXPC25, 249)