Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1221398pxu; Wed, 6 Jan 2021 16:21:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBOyV7brFqU0tafAbZDTCbCA2aQsq+4vXNYCV5N0veiFZNYoDXm6IE60RV17hZXjXkdVaf X-Received: by 2002:a17:906:e18:: with SMTP id l24mr4324133eji.434.1609978902271; Wed, 06 Jan 2021 16:21:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609978902; cv=none; d=google.com; s=arc-20160816; b=NiE/rnIBy9/rMOjrH1fe+kdJwlqOUXaT+s7glL5oltqM+1vW/mKhvqt2h1nEF2sJeU Mdm7pNy4k6a0EsikKpweiQ6PwqP7qTVDnPrVW8SAYm3vqSvA55Cefk8VMU+hXRBjlvyz PYc3iPqEyUl742YIO4WBYo6pcJAFRfUJcddxBgBJSj0TkKs7GJlvKA26dedPUMjb4ywD ZduVUqPm+0B/QRKx618vu7Q06+YfNeVQ6p6k1qb6w28DyYZ1mSUPTslc9Jf6MEyQ0UfI eHqqJ90rDatuCkXmJ263FD5bZSJthY2GzCmvVcC1p1rbT81J1nS/3Q6vuHfS7KlWqR+u BJnQ== 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:mime-version:message-id:date :sender:dkim-signature; bh=lF6425iSo/7VCEtMZN9oNw0V0JdXZmHytXzvDMuDncU=; b=SuBOoBHP1MhiMsp6Z9jYtegtCbpN6tF0aUaCtOh99FuEmYvobI24meGHK8QNjzyi9k Z/8HZC3D/81Nyzg9MFBCrUXtiH84hWWzOJ+1Y/kwloc5rzAf21vfYNc+LXJeo67AcqHK E3TDz8W5Ru3pSgzay7h1yqemkVp03yEHW9JvKEdMJFkiK214tC7usOrtGWm4O9lgVd2N yggf57PrmDFC2QFfSkqglfnLpeWtHgiGPuHk403HAukpGe+XeFzoU+wpf3RXI0Ghj6KF imBVBAUpQxWuEKBq8r37fAlG5meJ0/iY6H/sIcdGuUUE0mqyu0ngg9klI9NZaYYE2qzy vvEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YbRzwjA0; 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 qp24si1692643ejb.323.2021.01.06.16.21.18; Wed, 06 Jan 2021 16:21:42 -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=YbRzwjA0; 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 S1726482AbhAGAS1 (ORCPT + 99 others); Wed, 6 Jan 2021 19:18:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726009AbhAGAS0 (ORCPT ); Wed, 6 Jan 2021 19:18:26 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 958B3C06136A for ; Wed, 6 Jan 2021 16:17:46 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id j1so7022027ybj.11 for ; Wed, 06 Jan 2021 16:17:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=lF6425iSo/7VCEtMZN9oNw0V0JdXZmHytXzvDMuDncU=; b=YbRzwjA0fz7XypKh56Rf93j+rf/C78PxiUEIqWoFm3/CDY8/jugRj44OIZmX7ZaLj2 cK4g/WXAFH0LuBIwS/OzMsK35bfp7vOjdm2lirgtzATw7NMo5Bx5qOOc/Pl0306yfyR9 tHHNaNn1TuxQoJ7YY4L4SG8mtQSOmY8C/vJQA/NAdgh2CqyL/SMzu9TzMzP7+ziNgL5o 3TX3JmDQCGvMCsh5PHuSI8vAANzRua2HZgJYletbyjHjA2D6zykEUrAUCX/Uu9lxt49d 8MypnxKoc5lUiKFW6BbogmX3vD7/4zgwP278P00ipGwyEUGRVWBXsJPBJNfloZw9UeEi k24Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=lF6425iSo/7VCEtMZN9oNw0V0JdXZmHytXzvDMuDncU=; b=Li7/zLom6dUFM5YWVv93d5RJnv5dGdaSqeUsckWEyJbntyrCXRdn2X0UwJArVDO79V xrkNRCf2P4E0pAEID/Tq9aB4d6R/pEG5CifkETpgHKqHD7r4K7e7tAk+Goy6U6UcoQYW zDjybV2o8pOlE2bhaet0plbaV1NFcVMNTYN+mmfUG1nx81zhXXILwchKGEyo/bzTJsS4 iMKz6eL6HHC6WimCjAyYgZi0XweKT0nUOgeZ1knJBnT6n0YDuZYaZycXHrIpqE8fCUWD TMeEYvVvrvRNAvOQzwlNZOPLwfjrdLfT2trgQawwRc2ihCh5HI7MFjx3gGnhAnHSuMwP SjdA== X-Gm-Message-State: AOAM530sYhrU7qvahisn2v1A+Ru+Nqur9IgkYxyQ003qfbE8gtuGSoSG hhUjpHZ8XX6H9kr6KRbCJt8Ds7klO7Fl 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:1386:: with SMTP id 128mr9503757ybt.374.1609978665106; Wed, 06 Jan 2021 16:17:45 -0800 (PST) Date: Wed, 6 Jan 2021 16:17:39 -0800 Message-Id: <20210107001739.1321725-1-maskray@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [PATCH] 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, Nick Desaulniers , Fangrui Song , Arnd Bergmann Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is similar to commit b21ebf2fb4cde1618915a97cc773e287ff49173e "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, but R_386_PLT32 is arguably preferable for -fno-pic code as well: this can avoid a "canonical PLT entry" (st_shndx=0, st_value!=0) if the symbol turns out to be defined externally. Latest Clang (since 961f31d8ad14c66829991522d73e14b5a96ff6d4) can use R_386_PLT32 for compiler produced symbols (if we drop -ffreestanding for CONFIG_X86_32, library call optimization can produce newer declarations) and future GCC may use R_386_PLT32 as well if the maintainers agree to adopt an option like -fdirect-access-external-data to avoid "canonical PLT entry"/copy relocations https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98112 Link: https://github.com/ClangBuiltLinux/linux/issues/1210 Reported-by: Arnd Bergmann Signed-off-by: Fangrui Song --- 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.29.2.729.g45daf8777d-goog