From: Thomas Garnier Subject: [RFC v2 18/23] x86/relocs: Handle DYN relocations for PIE support Date: Thu, 10 Aug 2017 10:26:10 -0700 Message-ID: <20170810172615.51965-19-thgarnie@google.com> References: <20170810172615.51965-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-kernel@vger.kernel.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 , Matthias Kaehlcke , Boris Ostrovsky , Juergen Gross , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , Tom Lendacky , Andy Lutomirski , Borislav Petkov , Brian Gerst , "Kirill A . Shutemov" , "Rafael J . Wysocki" , Len Brown , Pavel Machek Return-path: In-Reply-To: <20170810172615.51965-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 Q2hhbmdlIHRoZSByZWxvY2F0aW9uIHRvb2wgdG8gY29ycmVjdGx5IGhhbmRsZSBEWU4vUElFIGtl cm5lbCB3aGVyZQp0aGUgcmVsb2NhdGlvbiB0YWJsZSBkb2VzIG5vdCByZWZlcmVuY2Ugc3ltYm9s cyBhbmQgcGVyY3B1IHN1cHBvcnQgaXMKbm90IG5lZWRlZC4gQWxzbyBhZGQgc3VwcG9ydCBmb3Ig Ul9YODZfNjRfUkVMQVRJVkUgcmVsb2NhdGlvbnMgdGhhdCBjYW4KYmUgaGFuZGxlZCBsaWtlIGEg NjQtYml0IHJlbG9jYXRpb24gZHVlIHRvIHRoZSB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