Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp636576pxb; Thu, 14 Jan 2021 14:53:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJxwm9IizFynFelFkCE+kH7nXXLHFRToSrVhC0JkOf5ahsx1d2w/P6scP/Gnv6576kjYi0lw X-Received: by 2002:a05:6402:5206:: with SMTP id s6mr5854634edd.92.1610664819631; Thu, 14 Jan 2021 14:53:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610664819; cv=none; d=google.com; s=arc-20160816; b=R+Tl3kxmuDgq3nPqTDojRB8t1Trggy9CNNHLnQyGO48aa7MU/zP1JGTdkd5mQnwj8L /uYLQ6ff3rn02kJ13Fl1gNkIZOz3V6pF3vBCeR39KogM8pn4iZlLJhHTUk/yLEACCdPm 8zGbreHOK3Rz/OKaFyKuHjhQdnYcflXNbtHwSswArA5tvpvzaGbz22E0oKITeKq3VWvw HCFBeBfPNOaXwCq5fjzQ2Vs3mD3+MsjgIB/7NRzBohMFq3gCuuih5wKQkFhYcaacHNd+ rWbzi/a4/hh+9c9khQ2vGaHxceLZRmtBVeqRbqh1NV7PAbEf+qePprxOrX0eD3IIcDHD 5FOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=RbsfhVoCXn95CjDh/v1ZbeIm2/iYKTwaoq52D6PfEPY=; b=07GinjEAYNrZBApaqONUQFYJj1yohCMEplHrDnkax1FCBwcycACADyRo+GzEwz6fk1 T+J6TctZatJjEgDxKAJ6LuhUStKrqoaLGW3aHlRXE1CE9hNpj0BFgEJJwmn/jlhB9Uwy YAYpU+iwH9InB/JuxdDVoANqS89wH6wjebAeh4FFC4HIx7/i+IGXRJBE2V2qhiTLNy4M GXCHrd1S9DRwzjN3JSwMsVLD9gHnaemtL0y6KZWChVXaBWW6riTUBBSigJG0wxovWoAF 59muU+3Ci2EPfEsPxFC6h0YObTokVoVIpSvcnmOcVw7+WZ8KMVhGHcvC2VLumA/ZETUy 3Sgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=JuCQDAek; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id by17si2449748edb.1.2021.01.14.14.53.16; Thu, 14 Jan 2021 14:53:39 -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=@google.com header.s=20161025 header.b=JuCQDAek; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730852AbhANWtE (ORCPT + 99 others); Thu, 14 Jan 2021 17:49:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730815AbhANWtD (ORCPT ); Thu, 14 Jan 2021 17:49:03 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 246B2C061575 for ; Thu, 14 Jan 2021 14:48:23 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id v187so1911691ybv.21 for ; Thu, 14 Jan 2021 14:48:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=RbsfhVoCXn95CjDh/v1ZbeIm2/iYKTwaoq52D6PfEPY=; b=JuCQDAekJiG5HdKehuCqJGAjkuyxlcwDj+qlmc/HReJX5IoAhBrxD4wk92faxiGz0q se8iaJ5om2woDhR+QpQ0gSvGSq801b47MjUYZv04QXCV8DP+OAi/GO7uEF0fJdmFuOpY oUF/exMaBeMhH+2iQDx2kF3N1wFl056I8v7n+WUKaDffCMRHzFQj3GXnpzTwAGtaYCwN JoWc6wM31t1VlGVUbqjK6ML0g1g5jxq96Z5I+v2l1h8s3QGhKvgAciC+fLDadzmdTvXC HD/e8DsQZLZHR7+lTGbaZ3QjC5sCmpDM4lJ0U53AevQTleFRjPzSjGAZMWwPoRMgmf9y A7kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=RbsfhVoCXn95CjDh/v1ZbeIm2/iYKTwaoq52D6PfEPY=; b=chVouDa/e6fYgwUc2AgZGClDEBO1+eauWabbxWfRYNAUxMV6McWdBy63kzkkOF8LKm e6xxooKAXZ0MFeYNWhf019K8rN3AREhgyud8C49XRgwKU+TVhIoPjmfONCc6IC/poMwl 3j8gJzbGeUdTg+asePckEZzSJ+lJ0VhuOXbEXwPyM/kzHEsCx/Mmi9q68PKF8o6bF94P QBL7BdLN/Ym0DzfZa94FpW2aoJFgkxnA7+PhiTcw93+/JA9OfrcYmDfyfAAXBBiAn5K+ Y8ADls+eTlbMQnTqngjayK+etUisdcqQa8se+51QeDWxW1eJbM0ZvbM1KruX3j0ZFhdD E1dg== X-Gm-Message-State: AOAM530U2kzQ5UHI2UsdRBfoJt+pdesecM93tr5SYhWXwldY+6rLq50G 8pH0Q85yj154F+Bo6eMlEltfIx38fBzi Sender: "maskray via sendgmr" X-Received: from maskray1.svl.corp.google.com ([2620:15c:2ce:0:a6ae:11ff:fe11:4abb]) (user=maskray job=sendgmr) by 2002:a25:b341:: with SMTP id k1mr14146305ybg.37.1610664502367; Thu, 14 Jan 2021 14:48:22 -0800 (PST) Date: Thu, 14 Jan 2021 14:48:19 -0800 In-Reply-To: <20210107185555.2781221-1-maskray@google.com> Message-Id: <20210114224819.1608929-1-maskray@google.com> Mime-Version: 1.0 References: <20210107185555.2781221-1-maskray@google.com> X-Mailer: git-send-email 2.30.0.296.g2bfb1c46d8-goog Subject: [PATCH v3] x86: Treat R_386_PLT32 as R_386_PC32 From: Fangrui Song To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org Cc: linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, Fangrui Song , Arnd Bergmann , Nick Desaulniers , Nathan Chancellor Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is similar to commit b21ebf2fb4cd ("x86: Treat R_X86_64_PLT32 as R_X86_64_PC32"), but for i386. As far as Linux kernel is concerned, R_386_PLT32 can be treated the same as R_386_PC32. R_386_PC32/R_X86_64_PC32 are PC-relative relocation types with the requirement that the symbol address is significant. R_386_PLT32/R_X86_64_PLT32 are PC-relative relocation types without the address significance requirement. 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. On i386, there are 2 types of PLTs, PIC and non-PIC. Currently the convention is to use R_386_PC32 for non-PIC PLT and R_386_PLT32 for PIC PLT. clang-12 -fno-pic (since https://github.com/llvm/llvm-project/commit/a084c0388e2a59b9556f2de0083333232da3f1d6) can emit R_386_PLT32 for compiler generated function declarations as well to avoid a canonical PLT entry (st_shndx=0, st_value!=0) if the symbol turns out to be defined externally. GCC/GNU as will likely keep using R_386_PC32 because (1) the ABI is legacy (2) the change will drop a GNU ld non-default visibility ifunc for shared objects. https://sourceware.org/bugzilla/show_bug.cgi?id=27169 Link: https://github.com/ClangBuiltLinux/linux/issues/1210 Reported-by: Arnd Bergmann Signed-off-by: Fangrui Song Reviewed-by: Nick Desaulniers Reviewed-by: Nathan Chancellor Tested-by: Nick Desaulniers Tested-by: Nathan Chancellor --- Change in v2: * Improve commit message --- Change in v3: * Change the GCC link to the more relevant GNU as link. * Fix the relevant llvm-project commit id. --- arch/x86/kernel/module.c | 1 + arch/x86/tools/relocs.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index 34b153cbd4ac..5e9a34b5bd74 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -114,6 +114,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 ce7188cbdae5..717e48ca28b6 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -867,6 +867,7 @@ 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. @@ -910,6 +911,7 @@ 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. -- 2.30.0.296.g2bfb1c46d8-goog