From: Thomas Garnier Subject: [PATCH v1 16/27] x86/relocs: Handle PIE relocations Date: Wed, 11 Oct 2017 13:30:16 -0700 Message-ID: <20171011203027.11248-17-thgarnie@google.com> References: <20171011203027.11248-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 , Arnd Bergmann , Thomas Garnier , Kees Cook , Andrey Ryabinin , Matthias Kaehlcke , Tom Lendacky , Andy Lutomirski , "Kirill A . Shutemov" , Borislav Petkov , "Rafael J . Wysocki" , Len Brown , Pavel Machek , Juergen Gross , Chris Wright , Alok Kataria , Rusty Russell , Tejun Heo In-Reply-To: <20171011203027.11248-1-thgarnie@google.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" List-Id: linux-crypto.vger.kernel.org Q2hhbmdlIHRoZSByZWxvY2F0aW9uIHRvb2wgdG8gY29ycmVjdGx5IGhhbmRsZSByZWxvY2F0aW9u cyBnZW5lcmF0ZWQgYnkKLWZQSUUgb3B0aW9uOgoKIC0gQWRkIHJlbG9jYXRpb24gZm9yIGVhY2gg ZW50cnkgb2YgdGhlIC5nb3Qgc2VjdGlvbiBnaXZlbiB0aGUgbGlua2VyIGRvZXMgbm90CiAgIGdl bmVyYXRlIFJfWDg2XzY0X0dMT0JfREFUIG9uIGEgc2ltcGxlIGxpbmsuCiAtIElnbm9yZSBSX1g4 Nl82NF9HT1RQQ1JFTCBhbmQgUl9YODZfNjRfUExUMzIuCg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