From patchwork Thu Jul 22 13:22:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Isaev X-Patchwork-Id: 44452 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B9BA3383F42B for ; Thu, 22 Jul 2021 13:22:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B9BA3383F42B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1626960178; bh=M7jvPiBftznwZRkm9HOO5Ue05qrHahoL67Nqnye8ZfE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=hlnwK1/jHx/A81HzX41gxh5C8vyXCVNNRBoqBK4uTTloQcEpY8ssF4kKAjz+HItce Kw3m38wtZ/3ag90kC/kVTVusnKyUNdar5FEeIcbIPrDuezgdgtrtQiaU56UQduulRi cYxRbvTdOyL2OmvB/Derk78Os0C27Br7kYnCswck= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by sourceware.org (Postfix) with ESMTPS id 8B4963858417 for ; Thu, 22 Jul 2021 13:22:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8B4963858417 Received: from mailhost.synopsys.com (mdc-mailhost1.synopsys.com [10.225.0.209]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id A2D6A407CD; Thu, 22 Jul 2021 13:22:34 +0000 (UTC) Received: from isaev-debian.internal.synopsys.com (unknown [10.121.15.30]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id 70EBEA005D; Thu, 22 Jul 2021 13:22:31 +0000 (UTC) X-SNPS-Relay: synopsys.com To: libc-alpha@sourceware.org Subject: [PATCH] elf: _dl_fixup*: make @reloc_arg 64-bit safe Date: Thu, 22 Jul 2021 16:22:00 +0300 Message-Id: <20210722132200.43895-1-isaev@synopsys.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Vladimir Isaev via Libc-alpha From: Vladimir Isaev Reply-To: Vladimir Isaev Cc: Cupertino Miranda , Vineet Gupta , linux-snps-arc@lists.infradead.org, Vladimir Isaev Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This came up during arc64 glibc bringup on qemu usermode. On ARC, lazy rezolver calls _dl_fixup() with 2nd argument as PC of the PLT entry beiing fixed up. Thus this needs to be full 64-bit value for arc64, however _dl_fixup() defines @reloc_arg as ElfW(Word) which maps to Elf64_Word -> uint32_t causing gcc to truncate the value to 32-bits. This problem show on 64-bit ARC and not other arches likely due to the semantics of @reloc_arg. On ARC it is the runtime PC of PLT entry whereas for others it might be the index or something similar which doesn't need more than 32-bits. Reported-by: Cupertino Miranda Signed-off-by: Vladimir Isaev Signed-off-by: Vineet Gupta --- elf/dl-runtime.c | 6 +++--- sysdeps/hppa/dl-fptr.c | 2 +- sysdeps/i386/dl-machine.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/elf/dl-runtime.c b/elf/dl-runtime.c index 9d0d941000..6099a44ffb 100644 --- a/elf/dl-runtime.c +++ b/elf/dl-runtime.c @@ -56,7 +56,7 @@ _dl_fixup ( # ifdef ELF_MACHINE_RUNTIME_FIXUP_ARGS ELF_MACHINE_RUNTIME_FIXUP_ARGS, # endif - struct link_map *l, ElfW(Word) reloc_arg) + struct link_map *l, uintptr_t reloc_arg) { const ElfW(Sym) *const symtab = (const void *) D_PTR (l, l_info[DT_SYMTAB]); @@ -152,7 +152,7 @@ _dl_profile_fixup ( #ifdef ELF_MACHINE_RUNTIME_FIXUP_ARGS ELF_MACHINE_RUNTIME_FIXUP_ARGS, #endif - struct link_map *l, ElfW(Word) reloc_arg, + struct link_map *l, uintptr_t reloc_arg, ElfW(Addr) retaddr, void *regs, long int *framesizep) { void (*mcount_fct) (ElfW(Addr), ElfW(Addr)) = _dl_mcount; @@ -484,7 +484,7 @@ _dl_profile_fixup ( #include void ARCH_FIXUP_ATTRIBUTE -_dl_call_pltexit (struct link_map *l, ElfW(Word) reloc_arg, +_dl_call_pltexit (struct link_map *l, uintptr_t reloc_arg, const void *inregs, void *outregs) { #ifdef SHARED diff --git a/sysdeps/hppa/dl-fptr.c b/sysdeps/hppa/dl-fptr.c index 62ef68b62b..bcab1bf100 100644 --- a/sysdeps/hppa/dl-fptr.c +++ b/sysdeps/hppa/dl-fptr.c @@ -321,7 +321,7 @@ _dl_unmap (struct link_map *map) map->l_mach.fptr_table = NULL; } -extern ElfW(Addr) _dl_fixup (struct link_map *, ElfW(Word)) attribute_hidden; +extern ElfW(Addr) _dl_fixup (struct link_map *, uintptr_t) attribute_hidden; static inline Elf32_Addr elf_machine_resolve (void) diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h index 590b41d8d7..8f73e0efda 100644 --- a/sysdeps/i386/dl-machine.h +++ b/sysdeps/i386/dl-machine.h @@ -130,10 +130,10 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile) #define ARCH_FIXUP_ATTRIBUTE __attribute__ ((regparm (3), stdcall, unused)) extern ElfW(Addr) _dl_fixup (struct link_map *l, - ElfW(Word) reloc_offset) + uintptr_t reloc_offset) ARCH_FIXUP_ATTRIBUTE; extern ElfW(Addr) _dl_profile_fixup (struct link_map *l, - ElfW(Word) reloc_offset, + uintptr_t reloc_offset, ElfW(Addr) retaddr, void *regs, long int *framesizep) ARCH_FIXUP_ATTRIBUTE;