Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp438539pxb; Wed, 24 Feb 2021 06:19:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/DzMY0D0qV6yqaY/YoC8WGV0RNrv2eahJ3jWgnwXcKMK4fGQ+o+B/4T9nH4i5mWgb25Ku X-Received: by 2002:a17:906:8614:: with SMTP id o20mr1570474ejx.386.1614176344291; Wed, 24 Feb 2021 06:19:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614176344; cv=none; d=google.com; s=arc-20160816; b=divtwpF1xoq+T3e51FVdeIL4LKTeCC8pirQj54IEOBkyc3h8KBhLiVcmt4wVsW2O/4 bH5lbHjhpeURhmPMN4zckGsb2vfb87WCnijnTVhVakCpzuSO66JQAmyIs6hpjHzLMeHg R8skXJ5OIF7Hm/+EKxY34wj6ZJdN3pnydRlA0WHUUM8mPZw7yLNexeFIn5unOy2zYA57 Hyey6w3+BZ67EZZ/pTC66vhU2gaR5hrPQ1di5FizP8ShHuHIvVHoUNfrXWWnSqlLDPX2 HLmJxeODVAcnBBFtltd42LWGQKYnju3nCbBDzMnUWsIjUTEj1fId2P2Y9kLppmu259GN 9uZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dEX47vrmgDyQK4WepJuu0oThhavHIwITtakqYiF+y14=; b=f72rlqui7WtN70fqoQaYB3+BueN7A9h4iqNTML8YLUrvixep0mhKimGrNnzdzR9Iev V3TegGrCO9KETLtb0X8GxnmXO8L9S9uHA2Zf69lVNq1mtLmlQ6juLh4OXZ+tnRtRGvtf YHXK7ad0kGningSaJonVcvhx4YOlx9qo70U4mwynB2wjyeLtB6ObN7OHrJlyPaQ44hZC z8Uvm9mxwKAo+uMS7SlPYp6y4mUTs4NEyZD1cQOkDXWe/hO6cyJ/eixiYhZB/KBsm2WF 5bFCiUigeLAmwqszDz/aP+zLTiN4nK6XFliHMPLJF9Dw7fcbmFhSqI47P54HydjYnDMu uvYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LIQKFlpo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ds6si1371583ejc.350.2021.02.24.06.18.16; Wed, 24 Feb 2021 06:19:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LIQKFlpo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236001AbhBXOPI (ORCPT + 99 others); Wed, 24 Feb 2021 09:15:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:59874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235289AbhBXNLR (ORCPT ); Wed, 24 Feb 2021 08:11:17 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0E30F64ED4; Wed, 24 Feb 2021 12:55:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614171324; bh=yaJKN2m7unVgBkTZpQRD8MKdszMywNTFfQE5CECuCeY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LIQKFlpom+kp5BeldDm43sd0a8D5F/n1iuDjiZFKIORD5Q/LHBNP4zgSFy+U/G783 MeLIBTjsqYzfAnbJlJ3alJX723FKMoAI5vW3wKexrXih7PQ2OeI+y4qhQ92ALROhjV 7A56cPSW1Dk8PNbn8KmVcuE05knNIuBiG/ng0FQ7hog5GWUmjo23UWzUek3jXTmvad aY8E+XY0SXiZJYR3dHd512vrjiI1e6Jf2DtQBoLK4ZBuGUhwUmiAFDY1egEtFcxTEl g5KQPsJlh4v10xiTrLO5qBFNd8vs0Tsp2UpEFRjd00qMDWRIZeNfM5wGfhhPW/eSFY s24r3q3TUquWw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Fangrui Song , Arnd Bergmann , Borislav Petkov , Nick Desaulniers , Nathan Chancellor , Sedat Dilek , Sasha Levin , clang-built-linux@googlegroups.com Subject: [PATCH AUTOSEL 4.14 07/16] x86/build: Treat R_386_PLT32 relocation as R_386_PC32 Date: Wed, 24 Feb 2021 07:55:04 -0500 Message-Id: <20210224125514.483935-7-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210224125514.483935-1-sashal@kernel.org> References: <20210224125514.483935-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fangrui Song [ Upstream commit bb73d07148c405c293e576b40af37737faf23a6a ] This is similar to commit b21ebf2fb4cd ("x86: Treat R_X86_64_PLT32 as R_X86_64_PC32") but for i386. As far as the kernel is concerned, R_386_PLT32 can be treated the same as R_386_PC32. R_386_PLT32/R_X86_64_PLT32 are PC-relative relocation types which can only be used by branches. If the referenced symbol is defined externally, a PLT will be used. R_386_PC32/R_X86_64_PC32 are PC-relative relocation types which can be used by address taking operations and branches. If the referenced symbol is defined externally, a copy relocation/canonical PLT entry will be created in the executable. On x86-64, there is no PIC vs non-PIC PLT distinction and an R_X86_64_PLT32 relocation is produced for both `call/jmp foo` and `call/jmp foo@PLT` with newer (2018) GNU as/LLVM integrated assembler. This avoids canonical PLT entries (st_shndx=0, st_value!=0). On i386, there are 2 types of PLTs, PIC and non-PIC. Currently, the GCC/GNU as convention is to use R_386_PC32 for non-PIC PLT and R_386_PLT32 for PIC PLT. Copy relocations/canonical PLT entries are possible ABI issues but GCC/GNU as will likely keep the status quo because (1) the ABI is legacy (2) the change will drop a GNU ld diagnostic for non-default visibility ifunc in shared objects. clang-12 -fno-pic (since [1]) can emit R_386_PLT32 for compiler generated function declarations, because preventing canonical PLT entries is weighed over the rare ifunc diagnostic. Further info for the more interested: https://github.com/ClangBuiltLinux/linux/issues/1210 https://sourceware.org/bugzilla/show_bug.cgi?id=27169 https://github.com/llvm/llvm-project/commit/a084c0388e2a59b9556f2de0083333232da3f1d6 [1] [ bp: Massage commit message. ] Reported-by: Arnd Bergmann Signed-off-by: Fangrui Song Signed-off-by: Borislav Petkov Reviewed-by: Nick Desaulniers Reviewed-by: Nathan Chancellor Tested-by: Nick Desaulniers Tested-by: Nathan Chancellor Tested-by: Sedat Dilek Link: https://lkml.kernel.org/r/20210127205600.1227437-1-maskray@google.com Signed-off-by: Sasha Levin --- arch/x86/kernel/module.c | 1 + arch/x86/tools/relocs.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index f58336af095c9..1ccfe6bb9122e 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -126,6 +126,7 @@ int apply_relocate(Elf32_Shdr *sechdrs, *location += sym->st_value; break; case R_386_PC32: + case R_386_PLT32: /* Add the value, subtract its position */ *location += sym->st_value - (uint32_t)location; break; diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 220e97841e494..c58b631781233 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -840,9 +840,11 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym, case R_386_PC32: case R_386_PC16: case R_386_PC8: + case R_386_PLT32: /* - * NONE can be ignored and PC relative relocations don't - * need to be adjusted. + * NONE can be ignored and PC relative relocations don't need + * to be adjusted. Because sym must be defined, R_386_PLT32 can + * be treated the same way as R_386_PC32. */ break; @@ -883,9 +885,11 @@ static int do_reloc_real(struct section *sec, Elf_Rel *rel, Elf_Sym *sym, case R_386_PC32: case R_386_PC16: case R_386_PC8: + case R_386_PLT32: /* - * NONE can be ignored and PC relative relocations don't - * need to be adjusted. + * NONE can be ignored and PC relative relocations don't need + * to be adjusted. Because sym must be defined, R_386_PLT32 can + * be treated the same way as R_386_PC32. */ break; -- 2.27.0