From patchwork Fri Oct 14 07:58:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zac Walker X-Patchwork-Id: 2560 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp54891wrs; Fri, 14 Oct 2022 00:59:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM43Ipmt3tWxU9BXjYq0ebE1YNN90qzrBj37LbO9s+rEtPu18stkQ7+JDtHK5Jyod7W/BfEU X-Received: by 2002:a05:6402:5c9:b0:446:fb0:56bb with SMTP id n9-20020a05640205c900b004460fb056bbmr3310108edx.173.1665734386045; Fri, 14 Oct 2022 00:59:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665734386; cv=none; d=google.com; s=arc-20160816; b=QDuPYaZAXh4ZwJFt6ohWz8TsnZx58oNMZ62YA0LY652JS8Fyn8v9t67lpemYhOKcFu ayKbsY2aqcE2cHjlB5EQWho1Q5hpwklyJw4SgpLLH3zkymO5+US4+psopJo6H1Fn5aXg HnAx5T3q9MWDGqzAM9/o7QuiH+c8OnNg4m4uByuZEQ0h6l1lSwn9q9QiyQ6N0cdRyT/r w/NiJEPtFo105Sel/R66L96bCE6TH4vvpGIKj8byq/mpOoBOWplCmFIOZoPUsQtqVEQv nsK8ekTjoQrT5MfvpPjy47JInQ89LW6g95IiEijdse6+unHWqyGLhBSGaeneBnFkU8LX 7Xrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :content-language:user-agent:mime-version:date:message-id :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=LoMUGceYk7DLXv/i7m5rW5ScIEG0dyhHybml1Sb0w9k=; b=h5sdcoBbnKDfHqBrdSNrbXlFYk5XVdUJE9ikmADSfXNXWYfLqUF1/rMmZVO+pZo4cZ 5rDu3k3+eO/o2mggGlF7Vdj7ScXOTINhCHkOzxzn0kWTbebAuOC2KLEOztNrT8wyyenb 3ZQwyo8LhKuy+S86vWtkFsUt3oXD/iEg9jxSFqtFZd+14pwMI45UG63Mj/BMujd4C3+s RVyuy/lCEL/U5MnyUoe3MxRQJ+9wb5gr9iyevWvEytRx+0WrPHmlgAVVdcSgNeT68U/r II9PtIA7e2sKI287pqTp0o/1tu41wf/QVIKhNCEP239+OXgtGGZKwqiTy0QAHlZQIDau dfZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=rpKQLAhM; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id he19-20020a1709073d9300b0078bdbb52361si2136474ejc.209.2022.10.14.00.59.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 00:59:46 -0700 (PDT) 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=pass header.i=@sourceware.org header.s=default header.b=rpKQLAhM; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 547EA3857822 for ; Fri, 14 Oct 2022 07:58:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 547EA3857822 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665734321; bh=LoMUGceYk7DLXv/i7m5rW5ScIEG0dyhHybml1Sb0w9k=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=rpKQLAhMAsWgz7v3dDkiwjtc+3RBSkxTICehe5zj7aUWFMH1xq9sgypsUd8G/koHY IJpfaoeEunvmZ4e1Tjd2wk/304St/Otl67prJslSQXIynr6nd5CIaDBdZ6gSe1jy9g 0jAmBd6sTP5VBi4DgJulX9xr3BTiJcdeWRwHt3sM= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id 12696385801C for ; Fri, 14 Oct 2022 07:58:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 12696385801C Received: by mail-ej1-x62d.google.com with SMTP id 13so8796367ejn.3 for ; Fri, 14 Oct 2022 00:58:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LoMUGceYk7DLXv/i7m5rW5ScIEG0dyhHybml1Sb0w9k=; b=udrlgS69rrF0ReXzfDliTyQjjW2Am+9jnfbfMbrzCB6abaQGEC82OzaUwTErL0SBeS RC9LedT8KsQpIqoFKfRi1Cl+39Li14u1eAhoVHMXGX+Hh61yIH5EATTg8k3W1ia2ck8n pLcvdC4DiVIfWFeIT9DIbme07CPfkyJP0sZBh10eibgKdqnJj8axb5lcvVfLW5Ci9tzL zSgXbcTswRHO5Gsr7QRIlqIarMt7oTcqiTWv45FcUY7TYfutpJzA5r1+SpObKCRhBr28 TP+XLelkxWWHWNM+d+bjvkfKpoTMVA6EXoFD/1N9eZ4UOQ2vycjYxcU9AJmLd2g68dqZ gXpQ== X-Gm-Message-State: ACrzQf2QjlOTRqQWGNOIOKwtCBIVUCdy0hLtbSFIOlRZrOPpl2VbRMAC 710eH3HrdKdi8P5sI9IAm1a6Ovbh0KcZwfnx X-Received: by 2002:a17:906:6a1a:b0:78c:fa9c:e621 with SMTP id qw26-20020a1709066a1a00b0078cfa9ce621mr2751184ejc.160.1665734304301; Fri, 14 Oct 2022 00:58:24 -0700 (PDT) Received: from [172.29.64.46] ([94.230.145.250]) by smtp.gmail.com with ESMTPSA id d9-20020a170906370900b0073022b796a7sm1132947ejc.93.2022.10.14.00.58.23 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 14 Oct 2022 00:58:23 -0700 (PDT) Message-ID: <027ae69a-636b-6757-297a-eec42936401e@linaro.org> Date: Fri, 14 Oct 2022 09:58:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Content-Language: en-US To: binutils@sourceware.org Subject: [PATCH v3] aarch64-pe support for LD, GAS and BFD X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, 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: , X-Patchwork-Original-From: Zac Walker via Binutils From: Zac Walker Reply-To: Zac Walker 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?1746649099276028478?= X-GMAIL-MSGID: =?utf-8?q?1746649099276028478?= V3 of the patch originally written by Jedidiah Thompson. It allows aarch64-pe to be targeted natively, not having to use objcopy to convert it from ELF to PE. Between V2 and V3 I made a few recommended updates most notably adding the missing BFD_RELOC_AARCH64_BRANCH19 and additional const correctness. I have included a diff between patches v2 and v3. Patch and diff included as attachments to avoid text formatting issues. Changes since that original patch: - Added minimal relocation support and tested generated binaries run on a Surface-ProX ARM64 test machine. - Been through a review process with colleagues at Linaro. Linaro has agreed to run CI for aarch64-pe going forward in their test lab. - Run tests for multiple platforms; aarch64-linux-gnu, x86_64-linux-gnu, x86_64-w64-mingw32. Those tests pass and see no regressions. Multiple GAS tests still fail for aarch64-pe because of ELF specific assumptions. I plan to fix these later. The long-term goal of this work is to help enable MSYS2 for Window on ARM64. As discussed here: https://github.com/msys2/MSYS2-packages/issues/1888 The original work by Jedidiah Thompson here can be found here: https://sourceware.org/pipermail/binutils/2022-January/119077.html Regards, Zac Walker diff --git a/bfd/coff-aarch64.c b/bfd/coff-aarch64.c index 74dc7e8f55..2c3e225a22 100644 --- a/bfd/coff-aarch64.c +++ b/bfd/coff-aarch64.c @@ -39,56 +39,59 @@ #include "libcoff.h" - - - /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */ #define MINUS_ONE (~ (bfd_vma) 0) -static reloc_howto_type arm64_reloc_howto_64 = HOWTO(IMAGE_REL_ARM64_ADDR64, 0, 8, 64, false, 0, +static const reloc_howto_type arm64_reloc_howto_64 = HOWTO(IMAGE_REL_ARM64_ADDR64, 0, 8, 64, false, 0, complain_overflow_bitfield, NULL, "64", false, MINUS_ONE, MINUS_ONE, false); -static reloc_howto_type arm64_reloc_howto_32 = HOWTO (IMAGE_REL_ARM64_ADDR32, 0, 4, 32, false, 0, +static const reloc_howto_type arm64_reloc_howto_32 = HOWTO (IMAGE_REL_ARM64_ADDR32, 0, 4, 32, false, 0, complain_overflow_bitfield, NULL, "32", false, 0xffffffff, 0xffffffff, false); -static reloc_howto_type arm64_reloc_howto_32_pcrel = HOWTO (IMAGE_REL_ARM64_REL32, 0, 4, 32, true, 0, +static const reloc_howto_type arm64_reloc_howto_32_pcrel = HOWTO (IMAGE_REL_ARM64_REL32, 0, 4, 32, true, 0, complain_overflow_bitfield, NULL, "DISP32", false, 0xffffffff, 0xffffffff, true); -static reloc_howto_type arm64_reloc_howto_branch26 = HOWTO (IMAGE_REL_ARM64_BRANCH26, 0, 4, 26, true, 0, +static const reloc_howto_type arm64_reloc_howto_branch26 = HOWTO (IMAGE_REL_ARM64_BRANCH26, 0, 4, 26, true, 0, complain_overflow_bitfield, NULL, "BRANCH26", false, 0x03ffffff, 0x03ffffff, true); -static reloc_howto_type arm64_reloc_howto_page21 = HOWTO (IMAGE_REL_ARM64_PAGEBASE_REL21, 12, 4, 21, true, 0, +static const reloc_howto_type arm64_reloc_howto_page21 = HOWTO (IMAGE_REL_ARM64_PAGEBASE_REL21, 12, 4, 21, true, 0, complain_overflow_signed, NULL, "PAGE21", false, 0x1fffff, 0x1fffff, false); -static reloc_howto_type arm64_reloc_howto_lo21 = HOWTO (IMAGE_REL_ARM64_REL21, 0, 4, 21, true, 0, +static const reloc_howto_type arm64_reloc_howto_lo21 = HOWTO (IMAGE_REL_ARM64_REL21, 0, 4, 21, true, 0, complain_overflow_signed, NULL, "LO21", false, 0x1fffff, 0x1fffff, true); -static reloc_howto_type arm64_reloc_howto_pgoff12 = HOWTO (IMAGE_REL_ARM64_PAGEOFFSET_12L, 1, 4, 12, true, 0, +static const reloc_howto_type arm64_reloc_howto_pgoff12 = HOWTO (IMAGE_REL_ARM64_PAGEOFFSET_12L, 1, 4, 12, true, 0, complain_overflow_signed, NULL, "PGOFF12", false, 0xffe, 0xffe, true); +static const reloc_howto_type arm64_reloc_howto_branch19 = HOWTO (IMAGE_REL_ARM64_BRANCH19, 2, 4, 19, true, 0, + complain_overflow_signed, + NULL, "BRANCH19", + false, 0x7ffff, 0x7ffff, true); + -static reloc_howto_type* arm64_howto_table[] = { +static const reloc_howto_type* const arm64_howto_table[] = { &arm64_reloc_howto_64, &arm64_reloc_howto_32, &arm64_reloc_howto_32_pcrel, &arm64_reloc_howto_branch26, &arm64_reloc_howto_page21, &arm64_reloc_howto_lo21, - &arm64_reloc_howto_pgoff12 + &arm64_reloc_howto_pgoff12, + &arm64_reloc_howto_branch19 }; #ifndef NUM_ELEM @@ -100,8 +103,6 @@ static reloc_howto_type* arm64_howto_table[] = { #define coff_bfd_reloc_type_lookup coff_aarch64_reloc_type_lookup #define coff_bfd_reloc_name_lookup coff_aarch64_reloc_name_lookup - - static reloc_howto_type * coff_aarch64_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code) { @@ -122,6 +123,8 @@ coff_aarch64_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real return &arm64_reloc_howto_lo21; case BFD_RELOC_AARCH64_LDST16_LO12: return &arm64_reloc_howto_pgoff12; + case BFD_RELOC_AARCH64_BRANCH19: + return &arm64_reloc_howto_branch19; default: BFD_FAIL (); return NULL; @@ -148,7 +151,7 @@ coff_aarch64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, #define COFF_PAGE_SIZE 0x1000 static reloc_howto_type * -coff_aarch64_rtype_lookup (unsigned int code ATTRIBUTE_UNUSED) +coff_aarch64_rtype_lookup (unsigned int code) { switch (code) { @@ -164,8 +167,10 @@ coff_aarch64_rtype_lookup (unsigned int code ATTRIBUTE_UNUSED) return &arm64_reloc_howto_page21; case IMAGE_REL_ARM64_REL21: return &arm64_reloc_howto_lo21; - case BFD_RELOC_AARCH64_LDST16_LO12: + case IMAGE_REL_ARM64_PAGEOFFSET_12L: return &arm64_reloc_howto_pgoff12; + case IMAGE_REL_ARM64_BRANCH19: + return &arm64_reloc_howto_branch19; default: BFD_FAIL (); return NULL; diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c index 6f6b204cdc..f6fa158583 100644 --- a/gas/config/tc-aarch64.c +++ b/gas/config/tc-aarch64.c @@ -10250,10 +10250,13 @@ struct aarch64_option_abi_value_table enum aarch64_abi_type value; }; -#ifdef OBJ_ELF static const struct aarch64_option_abi_value_table aarch64_abis[] = { +#ifdef OBJ_ELF {"ilp32", AARCH64_ABI_ILP32}, {"lp64", AARCH64_ABI_LP64}, +#else + {"llp64", AARCH64_ABI_LLP64}, +#endif }; static int @@ -10277,13 +10280,10 @@ aarch64_parse_abi (const char *str) as_bad (_("unknown abi `%s'\n"), str); return 0; } -#endif static struct aarch64_long_option_table aarch64_long_opts[] = { -#ifdef OBJ_ELF {"mabi=", N_("\t specify for ABI "), aarch64_parse_abi, NULL}, -#endif /* OBJ_ELF */ {"mcpu=", N_("\t assemble for CPU "), aarch64_parse_cpu, NULL}, {"march=", N_("\t assemble for architecture "),