From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 245B93858C55 for ; Wed, 21 Sep 2022 01:18:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 245B93858C55 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx_2tSZipjyh0fAA--.49327S2; Wed, 21 Sep 2022 09:18:14 +0800 (CST) From: liuzhensong To: binutils@sourceware.org Cc: i.swmail@xen0n.name, xry111@xry111.site, maskray@google.com, mengqinggang@loongson.cn, liuzhensong Subject: [PATCH v2] LoongArch: Set e_flags to 0x40 of ELF while using new relocations. Date: Wed, 21 Sep 2022 09:17:56 +0800 Message-Id: <20220921011756.451005-1-liuzhensong@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:AQAAf8Dx_2tSZipjyh0fAA--.49327S2 X-Coremail-Antispam: 1UD129KBjvJXoW3AF4rWr4xCr45JF4rZry7Wrg_yoW3KFy7pr 1jyFW8Kr1Fkr13GF48tF1q9r1kGF4xArWYyFyUJr40qryq9ry8X3ykKr4fGF15Aa18Zas7 u3Z7Aw1jvFWkXwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkS14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r 4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2Wl Yx0E2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbV WUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc2xSY4AK6svP MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr 0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0E wIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJV W8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAI cVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjfUozVbDUUUU X-CM-SenderInfo: holx6xphqv003j6o00pqjv00gofq/ X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,SPF_HELO_PASS,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 List-Id: As the docs[1] describes, update the e_flags of ELF. 1. 32 or 64 bit is represented by EI_CLASS. 2. The bits of e_flags Base ABI [2:0]: soft float -- 0x1 single float -- 0x2 double float -- 0x3 ABI version [7:6]: obj-v0 -- 0x0 obj-v1 -- 0x1 3. Discussions [2]. docs: [1] https://github.com/loongson/LoongArch-Documentation/blob/ main/docs/LoongArch-ELF-ABI-EN.adoc#e_flags-identifies-abi-type-and-version [2] https://github.com/loongson/LoongArch-Documentation/pull/61 --- bfd/elfnn-loongarch.c | 21 ++++++++++++++++--- binutils/readelf.c | 10 ++++----- gas/config/tc-loongarch.c | 20 +++++++++--------- include/elf/loongarch.h | 44 +++++++++++++++++++-------------------- 4 files changed, 54 insertions(+), 41 deletions(-) diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c index 33c85e5207c..5b4b83eb07a 100644 --- a/bfd/elfnn-loongarch.c +++ b/bfd/elfnn-loongarch.c @@ -416,8 +416,22 @@ elfNN_loongarch_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) elf_elfheader (obfd)->e_flags = in_flags; return true; } + else if (out_flags != in_flags) + { + if ((EF_LOONGARCH_IS_OBJ_V0 (out_flags) + && EF_LOONGARCH_IS_OBJ_V1 (in_flags)) + || (EF_LOONGARCH_IS_OBJ_V0 (in_flags) + && EF_LOONGARCH_IS_OBJ_V1 (out_flags))) + { + elf_elfheader (obfd)->e_flags |= EF_LOONGARCH_ABI_OBJ_V1; + out_flags = elf_elfheader (obfd)->e_flags; + in_flags = out_flags; + } + } /* Disallow linking different ABIs. */ + /* Only check relocation version. + The obj_v0 is compatible with obj_v1 in this "release cycle". */ if (EF_LOONGARCH_ABI(out_flags ^ in_flags) & EF_LOONGARCH_ABI_MASK) { _bfd_error_handler (_("%pB: can't link different ABI object."), ibfd); @@ -1579,15 +1593,16 @@ loongarch_elf_size_dynamic_sections (bfd *output_bfd, if (bfd_link_executable (info) && !info->nointerp) { const char *interpreter; - flagword flags = elf_elfheader (output_bfd)->e_flags; s = bfd_get_linker_section (dynobj, ".interp"); BFD_ASSERT (s != NULL); - if (EF_LOONGARCH_IS_ILP32 (flags)) + + if (elf_elfheader (output_bfd)->e_ident[EI_CLASS] == ELFCLASS32) interpreter = "/lib32/ld.so.1"; - else if (EF_LOONGARCH_IS_LP64 (flags)) + else if (elf_elfheader (output_bfd)->e_ident[EI_CLASS] == ELFCLASS64) interpreter = "/lib64/ld.so.1"; else interpreter = "/lib/ld.so.1"; + s->contents = (unsigned char *) interpreter; s->size = strlen (interpreter) + 1; } diff --git a/binutils/readelf.c b/binutils/readelf.c index cafba9a4f56..6926cf16140 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -4340,11 +4340,6 @@ get_machine_flags (Filedata * filedata, unsigned e_flags, unsigned e_machine) } break; case EM_LOONGARCH: - if (EF_LOONGARCH_IS_LP64 (e_flags)) - strcat (buf, ", LP64"); - else if (EF_LOONGARCH_IS_ILP32 (e_flags)) - strcat (buf, ", ILP32"); - if (EF_LOONGARCH_IS_SOFT_FLOAT (e_flags)) strcat (buf, ", SOFT-FLOAT"); else if (EF_LOONGARCH_IS_SINGLE_FLOAT (e_flags)) @@ -4352,6 +4347,11 @@ get_machine_flags (Filedata * filedata, unsigned e_flags, unsigned e_machine) else if (EF_LOONGARCH_IS_DOUBLE_FLOAT (e_flags)) strcat (buf, ", DOUBLE-FLOAT"); + if (EF_LOONGARCH_IS_OBJ_V0 (e_flags)) + strcat (buf, ", OBJ-v0"); + else if (EF_LOONGARCH_IS_OBJ_V1 (e_flags)) + strcat (buf, ", OBJ-v1"); + break; } } diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c index 5bb8d317c5a..3e9204a5fa4 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -143,13 +143,13 @@ md_parse_option (int c, const char *arg) char ilp32[256] = ""; unsigned char *suf = (unsigned char *)arg; - lp64['s'] = lp64['S'] = EF_LOONGARCH_ABI_LP64_SOFT_FLOAT; - lp64['f'] = lp64['F'] = EF_LOONGARCH_ABI_LP64_SINGLE_FLOAT; - lp64['d'] = lp64['D'] = EF_LOONGARCH_ABI_LP64_DOUBLE_FLOAT; + lp64['s'] = lp64['S'] = EF_LOONGARCH_ABI_SOFT_FLOAT; + lp64['f'] = lp64['F'] = EF_LOONGARCH_ABI_SINGLE_FLOAT; + lp64['d'] = lp64['D'] = EF_LOONGARCH_ABI_DOUBLE_FLOAT; - ilp32['s'] = ilp32['S'] = EF_LOONGARCH_ABI_ILP32_SOFT_FLOAT; - ilp32['f'] = ilp32['F'] = EF_LOONGARCH_ABI_ILP32_SINGLE_FLOAT; - ilp32['d'] = ilp32['D'] = EF_LOONGARCH_ABI_ILP32_DOUBLE_FLOAT; + ilp32['s'] = ilp32['S'] = EF_LOONGARCH_ABI_SOFT_FLOAT; + ilp32['f'] = ilp32['F'] = EF_LOONGARCH_ABI_SINGLE_FLOAT; + ilp32['d'] = ilp32['D'] = EF_LOONGARCH_ABI_DOUBLE_FLOAT; switch (c) { @@ -216,24 +216,24 @@ void loongarch_after_parse_args () { /* Set default ABI/ISA LP64D. */ - if (!EF_LOONGARCH_IS_LP64(LARCH_opts.ase_abi) - && !EF_LOONGARCH_IS_ILP32(LARCH_opts.ase_abi)) + if (!LARCH_opts.ase_ilp32) { if (strcmp (default_arch, "loongarch64") == 0) { - LARCH_opts.ase_abi = EF_LOONGARCH_ABI_LP64_DOUBLE_FLOAT; + LARCH_opts.ase_abi = EF_LOONGARCH_ABI_DOUBLE_FLOAT; LARCH_opts.ase_ilp32 = 1; LARCH_opts.ase_lp64 = 1; } else if (strcmp (default_arch, "loongarch32") == 0) { - LARCH_opts.ase_abi = EF_LOONGARCH_ABI_ILP32_DOUBLE_FLOAT; + LARCH_opts.ase_abi = EF_LOONGARCH_ABI_DOUBLE_FLOAT; LARCH_opts.ase_ilp32 = 1; } else as_bad ("unknown default architecture `%s'", default_arch); } + LARCH_opts.ase_abi |= EF_LOONGARCH_ABI_OBJ_V1; /* Set default ISA double-float. */ if (!LARCH_opts.ase_nf && !LARCH_opts.ase_sf diff --git a/include/elf/loongarch.h b/include/elf/loongarch.h index 74757b82ca8..cceaa8cccc4 100644 --- a/include/elf/loongarch.h +++ b/include/elf/loongarch.h @@ -232,36 +232,34 @@ RELOC_NUMBER (R_LARCH_RELAX, 100) END_RELOC_NUMBERS (R_LARCH_count) /* Processor specific flags for the ELF header e_flags field. */ -/*The flag lp64s/lp64f/lp64d/ilp32s/ilp32f/ilp32d 3bits. */ -#define EF_LOONGARCH_ABI_LP64_SOFT_FLOAT 0x1 -#define EF_LOONGARCH_ABI_LP64_SINGLE_FLOAT 0x2 -#define EF_LOONGARCH_ABI_LP64_DOUBLE_FLOAT 0x3 +/* ase ABI modifier, 3bits. */ +#define EF_LOONGARCH_ABI_SOFT_FLOAT 0x1 +#define EF_LOONGARCH_ABI_SINGLE_FLOAT 0x2 +#define EF_LOONGARCH_ABI_DOUBLE_FLOAT 0x3 +#define EF_LOONGARCH_ABI_MODIFIER_MASK 0x7 -#define EF_LOONGARCH_ABI_ILP32_SOFT_FLOAT 0x5 -#define EF_LOONGARCH_ABI_ILP32_SINGLE_FLOAT 0x6 -#define EF_LOONGARCH_ABI_ILP32_DOUBLE_FLOAT 0x7 +#define EF_LOONGARCH_ABI_OBJ_V1 0x40 +#define EF_LOONGARCH_ABI_OBJ_MASK 0xC0 -#define EF_LOONGARCH_ABI_MASK 0x7 -#define EF_LOONGARCH_ABI_ILP32_MASK 0x4 -#define EF_LOONGARCH_ABI_FLOAT_MASK 0x3 -#define EF_LOONGARCH_ABI_SOFT_FLOAT_MASK 0x1 -#define EF_LOONGARCH_ABI_SINGLE_FLOAT_MASK 0x2 -#define EF_LOONGARCH_ABI_DOUBLE_FLOAT_MASK 0x3 +#define EF_LOONGARCH_ABI_MASK \ + (EF_LOONGARCH_ABI_OBJ_MASK | EF_LOONGARCH_ABI_MODIFIER_MASK) -#define EF_LOONGARCH_ABI(abi) (EF_LOONGARCH_ABI_MASK & (abi)) +#define EF_LOONGARCH_ABI_MODIFIER(abi) \ + (EF_LOONGARCH_ABI_MODIFIER_MASK & (abi)) +#define EF_LOONGARCH_ABI_OBJ(abi) \ + (EF_LOONGARCH_ABI_OBJ_MASK & (abi)) -#define EF_LOONGARCH_IS_LP64(abi) \ - (EF_LOONGARCH_ABI(abi) && (!(EF_LOONGARCH_ABI(abi) & EF_LOONGARCH_ABI_ILP32_MASK))) -#define EF_LOONGARCH_IS_ILP32(abi) \ - (EF_LOONGARCH_ABI(abi) && (EF_LOONGARCH_ABI(abi) & EF_LOONGARCH_ABI_ILP32_MASK)) +#define EF_LOONGARCH_ABI(abi) ((abi) & EF_LOONGARCH_ABI_MASK) #define EF_LOONGARCH_IS_SOFT_FLOAT(abi) \ - (!((EF_LOONGARCH_ABI(abi) & EF_LOONGARCH_ABI_FLOAT_MASK) ^ EF_LOONGARCH_ABI_SOFT_FLOAT_MASK)) - + (EF_LOONGARCH_ABI_MODIFIER (abi) == EF_LOONGARCH_ABI_SOFT_FLOAT) #define EF_LOONGARCH_IS_SINGLE_FLOAT(abi) \ - (!((EF_LOONGARCH_ABI(abi) & EF_LOONGARCH_ABI_FLOAT_MASK) ^ EF_LOONGARCH_ABI_SINGLE_FLOAT_MASK)) - + (EF_LOONGARCH_ABI_MODIFIER (abi) == EF_LOONGARCH_ABI_SINGLE_FLOAT) #define EF_LOONGARCH_IS_DOUBLE_FLOAT(abi) \ - (!((EF_LOONGARCH_ABI(abi) & EF_LOONGARCH_ABI_FLOAT_MASK) ^ EF_LOONGARCH_ABI_DOUBLE_FLOAT_MASK)) + (EF_LOONGARCH_ABI_MODIFIER (abi) == EF_LOONGARCH_ABI_DOUBLE_FLOAT) + +#define EF_LOONGARCH_IS_OBJ_V0(abi) (!EF_LOONGARCH_ABI_OBJ(abi)) +#define EF_LOONGARCH_IS_OBJ_V1(abi) \ + (EF_LOONGARCH_ABI_OBJ (abi) == EF_LOONGARCH_ABI_OBJ_V1) #endif /* _ELF_LOONGARCH_H */ -- 2.31.1