From: Thomas Garnier Subject: [PATCH v3 17/27] x86/relocs: Handle PIE relocations Date: Wed, 23 May 2018 12:54:11 -0700 Message-ID: <20180523195421.180248-18-thgarnie@google.com> References: <20180523195421.180248-1-thgarnie@google.com> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Cc: linux-arch@vger.kernel.org, kvm@vger.kernel.org, linux-pm@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-sparse@vger.kernel.org, linux-crypto@vger.kernel.org, kernel-hardening@lists.openwall.com, xen-devel@lists.xenproject.org To: Herbert Xu , "David S . Miller" , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Peter Zijlstra , Josh Poimboeuf , Greg Kroah-Hartman , Thomas Garnier , Philippe Ombredanne , Kate Stewart , Arnaldo Carvalho de Melo , Yonghong Song , Andrey Ryabinin , Kees Cook , Tom Lendacky , "Kirill A . Shutemov" , Andy Lutomirski , Dominik Brodowski , Borislav Petkov , Borislav Petkov , "Rafael J . Wysocki" , Len Return-path: In-Reply-To: <20180523195421.180248-1-thgarnie@google.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" List-Id: linux-crypto.vger.kernel.org Q2hhbmdlIHRoZSByZWxvY2F0aW9uIHRvb2wgdG8gY29ycmVjdGx5IGhhbmRsZSByZWxvY2F0aW9u cyBnZW5lcmF0ZWQgYnkKLWZQSUUgb3B0aW9uOgoKIC0gQWRkIHJlbG9jYXRpb24gZm9yIGVhY2gg ZW50cnkgb2YgdGhlIC5nb3Qgc2VjdGlvbiBnaXZlbiB0aGUgbGlua2VyIGRvZXMgbm90CiAgIGdl bmVyYXRlIFJfWDg2XzY0X0dMT0JfREFUIG9uIGEgc2ltcGxlIGxpbmsuCiAtIElnbm9yZSBSX1g4 Nl82NF9HT1RQQ1JFTC4KClNpZ25lZC1vZmYtY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