From patchwork Fri Jul 15 22:16:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 72149 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp21038qga; Fri, 15 Jul 2016 15:17:06 -0700 (PDT) X-Received: by 10.66.0.74 with SMTP id 10mr35390917pac.38.1468621026001; Fri, 15 Jul 2016 15:17:06 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id r73si2392291pfi.287.2016.07.15.15.17.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Jul 2016 15:17:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 653851A1F39; Fri, 15 Jul 2016 15:17:49 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x230.google.com (mail-wm0-x230.google.com [IPv6:2a00:1450:400c:c09::230]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E16061A1F34 for ; Fri, 15 Jul 2016 15:17:47 -0700 (PDT) Received: by mail-wm0-x230.google.com with SMTP id o80so46735010wme.1 for ; Fri, 15 Jul 2016 15:17:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=T85n+j1kHDhKpqyEOCn5IKqO6RgynIipkpLAMuv9RbQ=; b=jFbHcremQskr7Qd0lSkPSJBQHXaQjqwsll6f4mH4312SOErH55ih9RwLZSAlBRXMPO os3Ixb1ro+7MKYvazfCNNiIYJgMsrZ7glm61+lBWktlx12dAjfa/whqN0gZVTKDbVew9 gGiOEaqW+ZEpEfm7ahJdhIq3bLRBQm4nJ0+p0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=T85n+j1kHDhKpqyEOCn5IKqO6RgynIipkpLAMuv9RbQ=; b=JcH2zU3zU2/fBk92mC8WYJw3VZPjkqvkU2YOv4dpOlUsr7CVQMf3FJ6yGDG4Lms88R kE0MvKTS4UAiHDCN5tqd2Hw2PydrrRYTO7Qg8qJFr7mtz3y8cR8DqNFkNv/SOQdPN1uy aK6A9b0SNQ0TRWuPk7ZTZUbWznDTnX7MWJVbwCECmLmlRrmdVru3nk39t8zaCR/C+kS3 S4KQjgdxX/qCO7GCmLI3ydKB9RaPh0sdwnv4B19HbhsskbUy2YpViIkTpr8mGysf2maL YwkXjmdGxi9CpEaKr9egZ4VPes3/H0iQa4Hg9fj9gGcc9ygEoaaAlCUlI49MlpGgH/iz eR7w== X-Gm-Message-State: ALyK8tIsBD5WZUFTnAPIH9IuedDWYu9wV510KzEnu+tkeGTaMNECpoGUkI0KyNBzkc2wu1Tu X-Received: by 10.194.53.228 with SMTP id e4mr2537457wjp.179.1468621019204; Fri, 15 Jul 2016 15:16:59 -0700 (PDT) Received: from localhost.localdomain ([188.203.148.129]) by smtp.gmail.com with ESMTPSA id kr1sm2736108wjc.46.2016.07.15.15.16.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Jul 2016 15:16:58 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, lersek@redhat.com, afish@apple.com, liming.gao@intel.com, steven.shi@intel.com, yonghong.zhu@intel.com, michael.d.kinney@intel.com, jordan.l.justen@intel.com Date: Sat, 16 Jul 2016 00:16:10 +0200 Message-Id: <1468620971-5960-5-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468620971-5960-1-git-send-email-ard.biesheuvel@linaro.org> References: <1468620971-5960-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 4/5] MdePkg X64: force 'hidden' visibility when building with -fpic X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: bruce@cran.org.uk, pbonzini@redhat.com, Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" When building position independent (PIC) ELF objects, the GCC compiler assumes that each symbol with external linkage may potentially end up being exported from a shared library, which means that each of those symbols may be subject to symbol preemption, i.e., the executable linking to the shared library at runtime may override symbols exported by the shared library, and every internal reference held by the shared library itself *must* be made to point to the overridden version instead. For this reason, PIC code symbol references always go via the Global Offset Table (GOT), even if the code in question references symbols that are defined in the same compilation unit. The GOT refers to each symbol by absolute address, and so each entry is subject to runtime relocation. Since not every symbol with external linkage is ultimately exported from a shared library, the GCC compiler allows control over symbol visibility using attributes, command line arguments and pragmas, where 'hidden' means that the symbol is only referenced by the shared library itself. Due to the poor hygiene in EDK2 regarding the use of the 'static' modifier, many symbols that are local to their compilation unit end up being referenced indirectly via the GOT when building PIC code. In UEFI, there are no shared libraries and so there is no need to deal with symbol preemption, and we can mark every symbol reference 'hidden'. The only method that applies to all symbol definitions as well as declarations is the #pragma. So set the visibility 'hidden' pragma when building PIC code for X64 using GCC. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel Tested-by: Laszlo Ersek --- MdePkg/Include/X64/ProcessorBind.h | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdePkg/Include/X64/ProcessorBind.h b/MdePkg/Include/X64/ProcessorBind.h index 705104af062a..96df78fca07d 100644 --- a/MdePkg/Include/X64/ProcessorBind.h +++ b/MdePkg/Include/X64/ProcessorBind.h @@ -27,6 +27,16 @@ #pragma pack() #endif +#if defined(__GNUC__) && defined(__pic__) +// +// Mark all symbol declarations and references as hidden, meaning they will not +// be exported from a shared library, and thus will not be subject to symbol +// preemption. This allows the compiler to refer to symbols directly using +// relative references rather than via the GOT, which contains absolute symbol +// addresses that are subject to runtime relocation. +// +#pragma GCC visibility push (hidden) +#endif #if defined(__INTEL_COMPILER) //