From patchwork Thu Jul 14 13:16:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 72009 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp74748qga; Thu, 14 Jul 2016 06:16:31 -0700 (PDT) X-Received: by 10.98.29.201 with SMTP id d192mr6405754pfd.142.1468502185355; Thu, 14 Jul 2016 06:16:25 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id r4si4433654pfd.242.2016.07.14.06.16.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Jul 2016 06:16:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; 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 2001:19d0:306:5::1 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 1B8D81A1F24; Thu, 14 Jul 2016 06:17:07 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x22c.google.com (mail-wm0-x22c.google.com [IPv6:2a00:1450:400c:c09::22c]) (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 CDDEC1A1F33 for ; Thu, 14 Jul 2016 06:17:04 -0700 (PDT) Received: by mail-wm0-x22c.google.com with SMTP id i5so112819139wmg.0 for ; Thu, 14 Jul 2016 06:16:18 -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=cRyrWsOFKW/1wBbqrJoZ+2PgTV0sbUfV5lvVp8M+mck=; b=hadi5vqB7CGGb6uOEDoMGvAVn7V1XVZT2oEHRvOZ7KHa1vAmcOYSfT9YzTiX1oP3+Q PbhtqscWzOOcp3N/nlnLXxRgGUEiMLktl6t1CH3ywZ6PLrlxfgZ6ohrBSJWfGsim8RNK Mt7kHvnPCWRS2tddwtig+tSUZhKVf8ZiHa/Mo= 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=cRyrWsOFKW/1wBbqrJoZ+2PgTV0sbUfV5lvVp8M+mck=; b=EKEspcyDe2b98dv6pSJQXYIr13OF/9Sgvw62MyCifrZSVuT0icnuwTyPLh2fnA687R geGECl7T8RqsMGTEA+ySF0DDPyp6rXgAcsOScgZ3vGEHN+aHwEfv/va0rCOBUPQIxqjr FloZMQCag55Ri03uK5oyrn2kGmHe2W7qMXjlGmfAxPq51N4CsASsb5Wnjy0XLJb8xOZ/ lgcnNSErCkLMeTKHNCONGXYRgjpvrbIv7QsBq5YZktTX9w7a4y/RMcgZfLPMLORrgffY EvvTzxObd5mSuKhCWGvrH3QXWlBptiesgMNukAyuZmoHHasxSy5ZiVisDYPtf3KzA4Mh 3rpg== X-Gm-Message-State: ALyK8tLGvOB34KIm+GSpC7PKBQFreyyo5zHUMzTdwe5HEqdtavJrfw/fcVEmBZ8QwfCNA8OV X-Received: by 10.28.193.140 with SMTP id r134mr10647097wmf.81.1468502177138; Thu, 14 Jul 2016 06:16:17 -0700 (PDT) Received: from localhost.localdomain ([188.203.148.129]) by smtp.gmail.com with ESMTPSA id q69sm43232902wmd.4.2016.07.14.06.16.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 14 Jul 2016 06:16:16 -0700 (PDT) From: Ard Biesheuvel To: steven.shi@intel.com, yonghong.zhu@intel.com, liming.gao@intel.com, michael.d.kinney@intel.com, jordan.l.justen@intel.com, lersek@redhat.com, afish@apple.com, edk2-devel@lists.01.org Date: Thu, 14 Jul 2016 15:16:08 +0200 Message-Id: <1468502169-15248-5-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1468502169-15248-1-git-send-email-ard.biesheuvel@linaro.org> References: <1468502169-15248-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH 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: 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 --- MdePkg/Include/X64/ProcessorBind.h | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.7.4 _______________________________________________ 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) //