From patchwork Mon Jan 23 00:32:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Harmstone X-Patchwork-Id: 47022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1358083wrn; Sun, 22 Jan 2023 16:32:45 -0800 (PST) X-Google-Smtp-Source: AMrXdXvfIjle2FtC4qr6RLCVXcREcQh8HPiDoxyDqLurE5zvw6wBCAIhY9J1NlV88pLh7PvtaxOv X-Received: by 2002:a17:906:a0ce:b0:86e:7683:422b with SMTP id bh14-20020a170906a0ce00b0086e7683422bmr21403355ejb.68.1674433965683; Sun, 22 Jan 2023 16:32:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674433965; cv=none; d=google.com; s=arc-20160816; b=CLZYCTPKSJFc1q5hHEzwAwyMy9Fukobm3T7xKAd0bHClv4n+/d4w2ElGRH9/l7KuMW uysudXvIboJwZ6LSLsmCHhStgRmCsjgKUzbh8/yZhwWoPIB6Y/xqWQiO45YXWse67f/2 FE2w2e4q2dOw55aDpAAYd5lU5yLJDuMtBfGvDwGulv19EpOdmMGfcw1e2tXhKNwveWyM 3ic2ARmTMz5h2EGCOjdxtluO1Z2osXqqlmbengn+CahQEiSaOxR+k2D6UgEoHpwhwh0C dgRdeuv6RfgSMIf2SaAjTK18m+rM7Zg+ilCFE+6ZE+5gZ8R8h2zSEJrQ1x57VPm7Pvwx 0ckQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=3aMJqQkb6RIzXGfA+kE0aWdn+Bsk0J8B9Y0XyOlzY7I=; b=bXQyvOrkVIesbXCMN40TzmlxQHxLnNWI4zAXxXesYOGhw5uVqv0m6TOlOXkbIQOk73 nQqf2XvDa9kyuPtaYl50o55F/A4QHcupnmFe6oc/qGHoqHH6RkAdljbAVO3adcpeiPE1 oit/DKE6qUZ+BehnlOSmeatTmcqZfP6UX0CFPhqLffWZjAOymFliW6E6R02g7BiYdfVM B3xqwQ8+yC2jB11cJHtMpURkxQb1K1mKB/0GIiC7lcrix+pifQGxH4qyMwTEXWcrhvzb PCqJkVQ++U2QZKF6hhJwnfXTxaI/+qg0fGX1zdaoghOUMMcdKwrwpxP0BSMYAgoCBWuo TIxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=HR5DKYlV; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g14-20020a1709065d0e00b0086b5808d6b4si36578861ejt.717.2023.01.22.16.32.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jan 2023 16:32:45 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=HR5DKYlV; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B35EB3858CDA for ; Mon, 23 Jan 2023 00:32:44 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id AD0023858D32 for ; Mon, 23 Jan 2023 00:32:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD0023858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=harmstone.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-x336.google.com with SMTP id g10so7867349wmo.1 for ; Sun, 22 Jan 2023 16:32:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=3aMJqQkb6RIzXGfA+kE0aWdn+Bsk0J8B9Y0XyOlzY7I=; b=HR5DKYlVI5nClh8ihW0EWa+0uV55XRXXz4oApg2gIjORuSIooeirFAiK0Mg8WaqKWx kev6tFNfGPBsrvb5AKMWTd8AeIcfQT0c3GC5VGC66AQgCTB7VMI6fNCrt071HRpPMG8d megiGyqeXVPwcIWYJyEM8huWhD3PtYVyQDjVpDfU/U36JU1UUM/BcZRlEs/VW4BN37CQ oCgcHpzx01NVQ9erL2luW/u53DUORnjTWGY9W7gd3XfIj0aMP9t8pNTnEiHTVN15+BJH jrUDYRaUslOEuUc30qePvM8UKI0j6QH6i0JUQ0ZnIUnnGVtlbgBFhIJe9DyHiGDnC4cu zY8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3aMJqQkb6RIzXGfA+kE0aWdn+Bsk0J8B9Y0XyOlzY7I=; b=sGL1rtyQQ9or6xe/cwOjkplPjQBv5FKXQF0xQuMrvl4kglKF5eCUaxwJZ42evbkmkM Bt0d4aBkXH1afJUnpaSqU/Y9jeuZ/6i1LmLFjaDP5eRzJiJY7zT1hwFo+9YzqI1kbdo4 l2v+71S1jyh5HiPxlPl4Gmn3nLosl8g3ZSozehku66ZLdFMh8+4PVglJgRBobbnYtyEG F0XmG1t+x7xoou94D/TK1Fknme/QT/tMyHD93z5uX0LsQDLtWIs+2ZuQO00BaC3pRxaD 9Poa+AqrIfesC2x0vPtumYUl40FIOwvuKOKdYv21qLsYIHw7lf5KpTJZTp6Ybm5VGtSz 0bnA== X-Gm-Message-State: AFqh2krQfLNzC+ukTdnVsV1+M98URj2Bt20gIjnoK3f9j7o7ntQ4UBJf bFNNB3lDvWGnRYthWE5q5SdIsUcFPic= X-Received: by 2002:a05:600c:995:b0:3da:f4f5:ad0e with SMTP id w21-20020a05600c099500b003daf4f5ad0emr21619629wmp.9.1674433955227; Sun, 22 Jan 2023 16:32:35 -0800 (PST) Received: from beren.harmstone.com ([2a02:8010:64ea:0:8eb8:7eff:fe53:9d5f]) by smtp.gmail.com with ESMTPSA id z4-20020a05600c0a0400b003db01178b62sm10339613wmp.40.2023.01.22.16.32.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jan 2023 16:32:34 -0800 (PST) From: Mark Harmstone To: binutils@sourceware.org, zac.walker@linaro.org Cc: Mark Harmstone Subject: [PATCH] Add support for secidx relocations to aarch64-w64-mingw32 Date: Mon, 23 Jan 2023 00:32:31 +0000 Message-Id: <20230123003231.3100-1-mark@harmstone.com> X-Mailer: git-send-email 2.38.2 MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755771270158251659?= X-GMAIL-MSGID: =?utf-8?q?1755771270158251659?= This patch adds support for the .secidx directive and its corresponding relocation to aarch64-w64-mingw32. As with x86, this is a two-byte LE integer which gets filled in with the 1-based index of the output section that a symbol ends up in. This is needed for PDBs, which represent addresses as a .secrel32, .secidx pair. The test is substantially the same as for amd64, but with changes made for padding and alignment. --- bfd/coff-aarch64.c | 36 ++++++++++++++++++++++++++++- gas/config/tc-aarch64.c | 26 +++++++++++++++++++++ ld/testsuite/ld-pe/pe.exp | 2 ++ ld/testsuite/ld-pe/secidx_aarch64.d | 27 ++++++++++++++++++++++ 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 ld/testsuite/ld-pe/secidx_aarch64.d diff --git a/bfd/coff-aarch64.c b/bfd/coff-aarch64.c index 73fa2442dfe..12e242e18d0 100644 --- a/bfd/coff-aarch64.c +++ b/bfd/coff-aarch64.c @@ -305,6 +305,10 @@ static const reloc_howto_type arm64_reloc_howto_secrel = HOW (IMAGE_REL_ARM64_SECREL, 0, 4, 32, false, 0, dont, secrel_reloc, 0xffffffff); +static const reloc_howto_type arm64_reloc_howto_secidx += HOW (IMAGE_REL_ARM64_SECTION, + 0, 2, 16, false, 0, dont, NULL, 0xffff); + static const reloc_howto_type* const arm64_howto_table[] = { &arm64_reloc_howto_abs, &arm64_reloc_howto_64, @@ -318,7 +322,8 @@ static const reloc_howto_type* const arm64_howto_table[] = { &arm64_reloc_howto_branch14, &arm64_reloc_howto_pgoff12a, &arm64_reloc_howto_32nb, - &arm64_reloc_howto_secrel + &arm64_reloc_howto_secrel, + &arm64_reloc_howto_secidx }; /* No adjustment to addends should be needed. The actual relocation @@ -372,6 +377,8 @@ coff_aarch64_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real return &arm64_reloc_howto_32nb; case BFD_RELOC_32_SECREL: return &arm64_reloc_howto_secrel; + case BFD_RELOC_16_SECIDX: + return &arm64_reloc_howto_secidx; default: BFD_FAIL (); return NULL; @@ -428,6 +435,8 @@ coff_aarch64_rtype_lookup (unsigned int code) return &arm64_reloc_howto_32nb; case IMAGE_REL_ARM64_SECREL: return &arm64_reloc_howto_secrel; + case IMAGE_REL_ARM64_SECTION: + return &arm64_reloc_howto_secidx; default: return NULL; } @@ -847,6 +856,31 @@ coff_pe_aarch64_relocate_section (bfd *output_bfd, break; } + case IMAGE_REL_ARM64_SECTION: + { + uint16_t idx = 0, i = 1; + asection *s; + + s = output_bfd->sections; + while (s) + { + if (s == sec->output_section) + { + idx = i; + break; + } + + i++; + s = s->next; + } + + + bfd_putl16 (idx, contents + rel->r_vaddr); + rel->r_type = IMAGE_REL_ARM64_ABSOLUTE; + + break; + } + default: info->callbacks->einfo (_("%F%P: Unhandled relocation type %u\n"), rel->r_type); diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c index 2b74db256a2..2aeab6f958a 100644 --- a/gas/config/tc-aarch64.c +++ b/gas/config/tc-aarch64.c @@ -2127,6 +2127,25 @@ tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size) exp.X_add_number = 0; emit_expr (&exp, size); } + +static void +s_secidx (int dummy ATTRIBUTE_UNUSED) +{ + expressionS exp; + + do + { + expression (&exp); + if (exp.X_op == O_symbol) + exp.X_op = O_secidx; + + emit_expr (&exp, 2); + } + while (*input_line_pointer++ == ','); + + input_line_pointer--; + demand_empty_rest_of_line (); +} #endif /* TE_PE */ static void s_aarch64_arch (int); @@ -2166,6 +2185,7 @@ const pseudo_typeS md_pseudo_table[] = { #endif #ifdef TE_PE {"secrel32", s_secrel, 0}, + {"secidx", s_secidx, 0}, #endif {"float16", float_cons, 'h'}, {"bfloat16", float_cons, 'b'}, @@ -9304,6 +9324,7 @@ md_apply_fix (fixS * fixP, valueT * valP, segT seg) case BFD_RELOC_RVA: case BFD_RELOC_32_SECREL: + case BFD_RELOC_16_SECIDX: break; default: @@ -9395,6 +9416,11 @@ cons_fix_new_aarch64 (fragS * frag, int where, int size, expressionS * exp) exp->X_op = O_symbol; type = BFD_RELOC_32_SECREL; } + else if (exp->X_op == O_secidx) + { + exp->X_op = O_symbol; + type = BFD_RELOC_16_SECIDX; + } else { #endif diff --git a/ld/testsuite/ld-pe/pe.exp b/ld/testsuite/ld-pe/pe.exp index c4d48bb8c08..35a88d26bcf 100644 --- a/ld/testsuite/ld-pe/pe.exp +++ b/ld/testsuite/ld-pe/pe.exp @@ -86,6 +86,8 @@ if {[istarget "aarch64-*-pe*"] || [istarget "aarch64-*-mingw*"]} { {{objdump -dr aarch64.d}} "aarch64.x"} {".secrel32" "--disable-reloc-section" "" "" {secrel1.s secrel2.s} {{objdump -s secrel_64.d}} "secrel.x"} + {".secidx" "--disable-reloc-section" "" "" {secidx1.s secidx2.s} + {{objdump -s secidx_aarch64.d}} "secidx.x"} } run_ld_link_tests $pe_tests diff --git a/ld/testsuite/ld-pe/secidx_aarch64.d b/ld/testsuite/ld-pe/secidx_aarch64.d new file mode 100644 index 00000000000..e119d1cff6f --- /dev/null +++ b/ld/testsuite/ld-pe/secidx_aarch64.d @@ -0,0 +1,27 @@ + +tmpdir/secidx\.x: +file format pei-.* + +Contents of section \.text: + .*1000 3e3e3e3e 3c3c3c3c 3e3e3e3e 3e3c3c3c .* + .*1010 3e3e3e3e 3e3e3c3c 3e3e3e3e 3e3e3e3c .* + .*1020 3c3c3c3c 3e3e3e3e 3e000000 00000000 .* + .*1030 ffffffff ffffffff 00000000 00000000 .* + .*1040 ffffffff ffffffff 00000000 00000000 .* +Contents of section \.data: + .*2000 3e3e3e3e 3c3c3c3c 3e3e3e3e 3e3c3c3c .* + .*2010 3e3e3e3e 3e3e3c3c 3e3e3e3e 3e3e3e3c .* + .*2020 3e3e3e3e 01001101 00110100 11010011 .* + .*2030 3c3c3c3c 3c3c3c3c 3e3e3e3e 02001102 .* + .*2040 00110200 11020011 3c3c3c3c 3c3c3c3c .* + .*2050 3e3e3e3e 03001103 00110300 11030011 .* + .*2060 3c3c3c3c 3c3c3c3c 3e3e3e3e 01001102 .* + .*2070 00110300 113c3c3c 3c3c3c3c 3c000000 .* + .*2080 3c3c3c3e 3e3e3e3e 3e000000 .* +Contents of section \.rdata: + .*3000 3e3e3e3e 3c3c3c3c 3e3e3e3e 3e3c3c3c .* + .*3010 3e3e3e3e 3e3e3c3c 3e3e3e3e 3e3e3e3c .* + .*3020 3e3e3e3e 00000000 00000000 00000000 .* + .*3030 3c3c3c3e 3e3e3e3e 3e000000 .* +Contents of section \.idata: + .*4000 00000000 00000000 00000000 00000000 .* + .*4010 00000000 00000000 .*