From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by sourceware.org (Postfix) with ESMTPS id C5B9F3858C5E for ; Tue, 4 Apr 2023 15:46:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C5B9F3858C5E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oi1-x230.google.com with SMTP id r14so18847497oiw.12 for ; Tue, 04 Apr 2023 08:46:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680623188; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=uaIaNFHtKbWzP85KRXyteZQKH298iy+yV0h+ePcODsM=; b=Wa4Wt56MFCyLYkSdjJGIDd4fS8P76+v/9DZwnR/Mcj5TIVoy/gKHeRoUkX6e513CIz 3ehgpTVrrZWRpubHFB9tfkTJE0xKzvlw78U/niBBjfrJCwRBr+27KVYE/LajTlZj8/Y/ O39CjygHDDfphsv2d7eDoGeW4VyNWx753IybaY2MdW1/jp0bwLYotOTnrExP5egJ2twd AOGnbDyLp63Def3gb3kDT/q8cqAiM77m90L4ZVORqV2E/sr218FDGN89FdeZ6VFJug98 y/+yvTtlvhfCPryEWqnh99k1TVKmicwzI/tyIByIhfLdzak4eCTNxHYpXA6cJdaD9jdO o7TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680623188; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uaIaNFHtKbWzP85KRXyteZQKH298iy+yV0h+ePcODsM=; b=E3vEKkB17x5i0L+LAJTEGpZTfDUBrjh4jYkTpcIkNXTTzXIPsbVIL+bV4gk/95DPQM fHtJw8pRCRtmJNtfDbqM8VbiGxcY8nYBnrfLYQnlOroE3wt4p1ntdh9Z7oPiotHNg4t6 4HG6dLKsgx0RwpShqiOG9lo9bkJG9TspnrNh+AVYY6KYXpYrcO867S3h0tJCQcaOKnVm 4Kzf/e9AVaPQn+NQ93CLEU2ZAZv3eRwoI0LsI/BjREoDmBCtRYdL4ywSF7c8SWQCRELl OEz0BRuylAmr71WjhB1fCbqabk/lfOKA+Gekvc9mMrabZKnIs3cv8r+8ueasU9VIliQH Uufg== X-Gm-Message-State: AAQBX9foxbpRfJjUH5tC8W8R1idrPVoMCLlqxUkDnf2BX1FN5qHcEKzj wAY2mIU+UhKTZSovbTKwaef1Tj3Vttx6++Jz2tXvoKyaPfV6vKLBE+8= X-Google-Smtp-Source: AKy350acIslw3rkaqSxDOn3xMiGqxgLHTeUF2L2CBUXr9PuX7IC+eGEAp9i7ehLmt6V2MmGzEiEisichNRpK3yt8zRM= X-Received: by 2002:a05:6808:1804:b0:36e:f6f5:604c with SMTP id bh4-20020a056808180400b0036ef6f5604cmr986656oib.9.1680623188070; Tue, 04 Apr 2023 08:46:28 -0700 (PDT) MIME-Version: 1.0 References: <1680319133-22776-1-git-send-email-tangyouling@loongson.cn> In-Reply-To: <1680319133-22776-1-git-send-email-tangyouling@loongson.cn> From: Hengqi Chen Date: Tue, 4 Apr 2023 23:45:52 +0800 Message-ID: Subject: Re: [PATCH] backends: add checks for _GLOBAL_OFFSET_TABLE_ on loongarch To: Youling Tang Cc: elfutils-devel@sourceware.org, Liwei Ge Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,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 List-Id: Hi, Youling On Sat, Apr 1, 2023 at 11:19=E2=80=AFAM Youling Tang wrote: > > Add handling of _GLOBAL_OFFSET_TABLE_. > > Before applying the patch: > $ ./src/elflint --gnu-ld ./src/elflint > section [35] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol value 0x68548 > does not match .got.plt section address 0x68238 > > After applying the patch: > $ ./src/elflint --gnu-ld ./src/elflint > No errors > > Signed-off-by: Liwei Ge > Signed-off-by: Youling Tang > --- > backends/ChangeLog | 4 ++++ > backends/loongarch_init.c | 1 + > backends/loongarch_symbol.c | 35 +++++++++++++++++++++++++++++++++++ > 3 files changed, 40 insertions(+) > > diff --git a/backends/ChangeLog b/backends/ChangeLog > index 81f08314..41071953 100644 > --- a/backends/ChangeLog > +++ b/backends/ChangeLog > @@ -1,3 +1,7 @@ > +2023-04-01 Youling Tang > + * loongarch_init.c (loongarch_init): Hook check_special_symbol. > + * loongarch_symbol.c (loongarch_check_special_symbol): New functi= on. > + > 2023-02-07 Mark Wielaard > > * libebl_CPU.h (dwarf_peeled_die_type): Explicitly handle > diff --git a/backends/loongarch_init.c b/backends/loongarch_init.c > index 59d8cc3d..b641b07f 100644 > --- a/backends/loongarch_init.c > +++ b/backends/loongarch_init.c > @@ -46,6 +46,7 @@ loongarch_init (Elf *elf __attribute__ ((unused)), > loongarch_init_reloc (eh); > HOOK (eh, reloc_simple_type); > HOOK (eh, machine_flag_check); > + HOOK (eh, check_special_symbol); > > return eh; > } > diff --git a/backends/loongarch_symbol.c b/backends/loongarch_symbol.c > index 43306ab8..5ce55bad 100644 > --- a/backends/loongarch_symbol.c > +++ b/backends/loongarch_symbol.c > @@ -79,3 +79,38 @@ loongarch_machine_flag_check (GElf_Word flags) > return ((flags &~ (EF_LARCH_ABI_MODIFIER_MASK > | EF_LARCH_OBJABI_V1)) =3D=3D 0); > } > + > +/* Check whether given symbol's st_value and st_size are OK despite fail= ing > + normal checks. */ > +bool > +loongarch_check_special_symbol (Elf *elf, const GElf_Sym *sym, > + const char *name, const GElf_Shdr *destshdr) > +{ > + if (name !=3D NULL > + && strcmp (name, "_GLOBAL_OFFSET_TABLE_") =3D=3D 0) > + { > + size_t shstrndx; > + if (elf_getshdrstrndx (elf, &shstrndx) !=3D 0) > + return false; > + const char *sname =3D elf_strptr (elf, shstrndx, destshdr->sh_name= ); > + if (sname !=3D NULL > + && (strcmp (sname, ".got") =3D=3D 0 || strcmp (sname, ".got.plt= ") =3D=3D 0)) > + { > + Elf_Scn *scn =3D NULL; > + while ((scn =3D elf_nextscn (elf, scn)) !=3D NULL) > + { > + GElf_Shdr shdr_mem; > + GElf_Shdr *shdr =3D gelf_getshdr (scn, &shdr_mem); > + if (shdr !=3D NULL) > + { > + sname =3D elf_strptr (elf, shstrndx, shdr->sh_name); > + if (sname !=3D NULL && strcmp (sname, ".got") =3D=3D 0) > + return (sym->st_value >=3D shdr->sh_addr > + && sym->st_value < shdr->sh_addr + shdr->sh_s= ize); > + } > + } > + } > + } > + > + return false; > +} > -- > 2.37.1 > I've tested this locally, but still remains one error: section [34] '.symtab': _DYNAMIC symbol size 0 does not match dynamic segment size 480 Cheers, --- Hengqi