Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp484028iob; Wed, 18 May 2022 06:32:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGknLCaDLj+b3Gmpp0sd+gCQVhYoJ4riNAJmfPQ+vKwTHaAGGSEOmecXRpjVKa4HvJbpw3 X-Received: by 2002:a17:903:1205:b0:15e:8cbc:fd2b with SMTP id l5-20020a170903120500b0015e8cbcfd2bmr27506694plh.99.1652880771128; Wed, 18 May 2022 06:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652880771; cv=none; d=google.com; s=arc-20160816; b=sFBB/bJE6xOmcPLcVoMDlqVOI/9sCSoOG8CsWE8lubudRiqcefh7T54EyXbvZ0O9QF nZLIp8tCaSjVfGvPPZkp5Fj5we0WoieJHY9814dFCs/FsQLLPWQjvbhIiXblKQvEc4qG TTG7QGWtm/mG0x8az3TQh60FhinUV0lUWDoOsA70cQBSgCJgq2/QKSIvmJ2AIU0NaYQD DiC90NfHSqrrq/vUBlJkIDOHLs3dI+rkonMiH8Cwip+t0E80BoA2XOT8YfRf+NDMHJJC BYFGwQmnaKf9CnZhXWKA8+89Mqrq+5exIWyk3adommcEmG4vuvQAmbz5lnyCYs6QZulR Pqyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=WcMQ1jNwCWloTdpOHWUHdU6u3lkdhIdHHgvKjDKaJhQ=; b=lESEy+jx77s8jjocMpjmKv/gzbjWr+cYO8+9uJKH5yvsjPOgVxmXSlIWUNoj1GUFlf 6gY05LEB8P+iRDOphuD2riNwnN3zlidBuEtoipkCuP+9j1HSsLjjfwizi45bi4oLJUzq xFsne90gmGk8pOK23j3dd3aX87NjMlJH8DjXFoyG+hePxu3s7oR7zzgOp+8R2Ra+hnUi YL1J8KdW6FsHo9j+me/reIn14tz42RKTOocY0AL3GzFfrPN1zLN9Bc4NclktusKifsKB 26M/BJFo1uKtf6rlDcG4G/RFUM0BusiKkOXrFITouTzg0gR2RBJS1tAFQyjrMMDEJdSb ngjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BkiNZUDv; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s71-20020a63774a000000b003c640139e92si2564580pgc.720.2022.05.18.06.32.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 06:32:51 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BkiNZUDv; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A643218AAB9; Wed, 18 May 2022 06:30:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238001AbiERNaB (ORCPT + 99 others); Wed, 18 May 2022 09:30:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238049AbiERN3t (ORCPT ); Wed, 18 May 2022 09:29:49 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0164C1A359B for ; Wed, 18 May 2022 06:29:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652880542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=WcMQ1jNwCWloTdpOHWUHdU6u3lkdhIdHHgvKjDKaJhQ=; b=BkiNZUDvd5+Uvr6ZB6TLe1z7GEKJmTAENtFTijTBYOnkH1WyL9Djy8yIrJWHquqYSlJMfP Tw5qNGrersurt4DZygF3PXhXGGYZal+KWrGjNcrhECPsPKOOQxoG/Cb3XnnsxODShpc+NF tc5BYKtdASqU7Ou8LHQ8KIh+6Pf4acA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-331-PWzgkEwWPLmtbfnu11grTA-1; Wed, 18 May 2022 09:28:58 -0400 X-MC-Unique: PWzgkEwWPLmtbfnu11grTA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7CFFD18E0044; Wed, 18 May 2022 13:28:58 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 723CF400E118; Wed, 18 May 2022 13:28:58 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id 24IDSwo0014628; Wed, 18 May 2022 09:28:58 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id 24IDSvJx014624; Wed, 18 May 2022 09:28:58 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Wed, 18 May 2022 09:28:57 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Peter Zijlstra cc: Linus Torvalds , Josh Poimboeuf , linux-kernel@vger.kernel.org Subject: [PATCH v2] objtool: fix objtool regression on x32 systems In-Reply-To: <20220516212517.GP76023@worktop.programming.kicks-ass.net> Message-ID: References: <20220516212517.GP76023@worktop.programming.kicks-ass.net> User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 16 May 2022, Peter Zijlstra wrote: > On Mon, May 16, 2022 at 11:56:21AM -0400, Mikulas Patocka wrote: > > > > With this patch, the compiled kernel works. With kernels 5.17 or older, it > > also works. I bisected it and the breakage is caused by the commit > > 4abff6d48dbc. > > Sure; but it works doesn't mean there aren't more latent issues. ILP32 > hosted (cross) builds just aren't a thing I've ever considered. If we > really want to go support that then we should at least audit the whole > thing. > > A quick look seems to suggest at least all the 'offset' fields should be > u64 or something. The only reason that works is because -mcmodel=kernel > keeps everything in the 2G range to make s32 immediates work. But it > isn't right. There are many 'offset' variables and its hard to determine which should be 64-bit. Would it be possible to commit this patch, so that kernel 5.18 can be compiled on x32 distributions? And you can do code refactoring in the next merge window. Mikulas From: Mikulas Patocka The patch 4abff6d48dbc ("objtool: Fix code relocs vs weak symbols") makes the kernel unbootable. The patch c087c6e7b551 ("objtool: Fix type of reloc::addend") attempts to fix it by replacing 'int' with 'long'. However, we may be running on a system with x32 ABI and 'long' on x32 is 32-bit, thus the patch c087c6e7b551 doesn't really change anything and we still end up with miscompiled kernel. This patch replaces 'long' with 's64', so that the 64-bit kernel is correctly compiled on a x32 system. Signed-off-by: Mikulas Patocka Fixes: 4abff6d48dbc ("objtool: Fix code relocs vs weak symbols") Fixes: c087c6e7b551 ("objtool: Fix type of reloc::addend") --- tools/objtool/check.c | 9 +++++---- tools/objtool/elf.c | 2 +- tools/objtool/include/objtool/elf.h | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) Index: linux-2.6/tools/objtool/check.c =================================================================== --- linux-2.6.orig/tools/objtool/check.c 2022-05-18 13:51:22.000000000 +0200 +++ linux-2.6/tools/objtool/check.c 2022-05-18 13:52:37.000000000 +0200 @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -560,12 +561,12 @@ static int add_dead_ends(struct objtool_ else if (reloc->addend == reloc->sym->sec->sh.sh_size) { insn = find_last_insn(file, reloc->sym->sec); if (!insn) { - WARN("can't find unreachable insn at %s+0x%lx", + WARN("can't find unreachable insn at %s+0x%"PRIx64, reloc->sym->sec->name, reloc->addend); return -1; } } else { - WARN("can't find unreachable insn at %s+0x%lx", + WARN("can't find unreachable insn at %s+0x%"PRIx64, reloc->sym->sec->name, reloc->addend); return -1; } @@ -595,12 +596,12 @@ reachable: else if (reloc->addend == reloc->sym->sec->sh.sh_size) { insn = find_last_insn(file, reloc->sym->sec); if (!insn) { - WARN("can't find reachable insn at %s+0x%lx", + WARN("can't find reachable insn at %s+0x%"PRIx64, reloc->sym->sec->name, reloc->addend); return -1; } } else { - WARN("can't find reachable insn at %s+0x%lx", + WARN("can't find reachable insn at %s+0x%"PRIx64, reloc->sym->sec->name, reloc->addend); return -1; } Index: linux-2.6/tools/objtool/elf.c =================================================================== --- linux-2.6.orig/tools/objtool/elf.c 2022-05-18 13:51:22.000000000 +0200 +++ linux-2.6/tools/objtool/elf.c 2022-05-18 13:51:22.000000000 +0200 @@ -546,7 +546,7 @@ static struct section *elf_create_reloc_ int reltype); int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset, - unsigned int type, struct symbol *sym, long addend) + unsigned int type, struct symbol *sym, s64 addend) { struct reloc *reloc; Index: linux-2.6/tools/objtool/include/objtool/elf.h =================================================================== --- linux-2.6.orig/tools/objtool/include/objtool/elf.h 2022-05-18 13:51:22.000000000 +0200 +++ linux-2.6/tools/objtool/include/objtool/elf.h 2022-05-18 13:51:22.000000000 +0200 @@ -73,7 +73,7 @@ struct reloc { struct symbol *sym; unsigned long offset; unsigned int type; - long addend; + s64 addend; int idx; bool jump_table_start; }; @@ -135,7 +135,7 @@ struct elf *elf_open_read(const char *na struct section *elf_create_section(struct elf *elf, const char *name, unsigned int sh_flags, size_t entsize, int nr); int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset, - unsigned int type, struct symbol *sym, long addend); + unsigned int type, struct symbol *sym, s64 addend); int elf_add_reloc_to_insn(struct elf *elf, struct section *sec, unsigned long offset, unsigned int type, struct section *insn_sec, unsigned long insn_off);