From patchwork Tue Jun 12 15:22:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 138360 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp5490543lji; Tue, 12 Jun 2018 08:23:29 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKmubA2lDBERfUcjgJrizOfMxs0NUhOrj0mVVyGKMdJ3920I9t0pOyLiAbP/ayRh7X+Pplp X-Received: by 2002:a63:715d:: with SMTP id b29-v6mr697497pgn.325.1528817009349; Tue, 12 Jun 2018 08:23:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528817009; cv=none; d=google.com; s=arc-20160816; b=XAN3yS/tIJYgxgXiHL6P+fg//zhOr5OxqWsWq3reuS2xGtfWqeRlWZs05NbiTM3lmd 00BxWQfR+YYjpoEjVoq0hYgIRSlm2FkzPCKXi1DEdtKu4AWFu+3swPBt0D08igANmXrz 5BNsYpnnFxNgw31N6TSIMqc11DtJ03uu1JzXQNy5zNeubhK+28UX301whsJNo97xI2ut IdEmrQxzIBPRxM9XuCo1/TAtkxlJbRwCxF2z7LXbwoHc3lFiRh/MniBLwMO+1xFU5AIO 1fY0fOQWwV4XuOH5buJkt3IMm5cQgRQIDEwXcsYS/isW1BqUtlPB4DkZSYOJSjzBGhqF swhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=rF23UJpAwn0UtavIm8kzhtzVCCK3RIWbu9+b9kbyY4E=; b=p1/w10KK/ZAsbGq04nYGmk5RgnRg2GlCksXUF7uQL3Ax6hJ9IXBdwhVO1nD3bpB8JE B7UtDnoc0nOksSszOUa1auRdwWtLNYZAqEbXlue7A44iqtg5qf4KY6oH0LfwJDGWedza kvTaehe0EKr3BF242mExpxjENEmT/m7faTOodBERc8X0x5q28zL3T38g9fyUAbXV3nqh LRMJ9LoNemwWyAqO2NCy8FYN1A2DNqn2CPe26kJh8PrMkf9aii2Lmm7+EW+fUrk5JqkU FMkyAcnDJsvyZB4LJZwqmc1d9Dp5hm+kolxBEC9WJKyii0xd68CeX+1wMnnyQS/PaHEn vPpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=jhwvZbbS; 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 sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id p61-v6si342760plb.472.2018.06.12.08.23.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jun 2018 08:23:29 -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 header.s=google header.b=jhwvZbbS; 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 sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 6573B21295B24; Tue, 12 Jun 2018 08:23:28 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c09::22a; helo=mail-wm0-x22a.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm0-x22a.google.com (mail-wm0-x22a.google.com [IPv6:2a00:1450:400c:c09::22a]) (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 000E121295B20 for ; Tue, 12 Jun 2018 08:23:26 -0700 (PDT) Received: by mail-wm0-x22a.google.com with SMTP id j15-v6so24217315wme.0 for ; Tue, 12 Jun 2018 08:23:26 -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; bh=p3FCmDNLSBjJUtFL2Go9nR5hb0mvi1IlErYDbv6/t9g=; b=jhwvZbbSjzHyDEGNMY4yp3cCkIP49qlnZLfRpfvjd/zAkNewBjY4o06/RdUJ2/HLGy vclZ+CL9XvHkzDnuL1hKNbT5n3Q7V0w3NX7SQClxAZLcEEx94Sah2em950Rj65jbEiCX ziC73+8y+j16UJ51N7MNGGVB6ccGtrOXZxuOA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=p3FCmDNLSBjJUtFL2Go9nR5hb0mvi1IlErYDbv6/t9g=; b=oDjUy9qIEZuh4EFTBCbu/N9BabZV3Pqb/SEyGDDKkEAGVtArfCA1IQUXTbrpeu1Roi UEMn104uQk2FJcEtH2ltV9pNkP/l17xthcDPhaF69p8mksgbMgG8plnSnpiC5ZFjuCnN 6tBAx4qGFs1F4nexYO1JZImyy0gA8FGP+MjU7ObVM0WrCViPo/WUTrkX5CbqYlKMXNy0 ph+zKY4CUhWrJ/jRJk3dTvaBHo7XmrCd4+0PJHQA0L+l0VvEzKxfmPp2VW9IkB3bH0v2 0upFiN0ZsBWuL9YYx24B2GCaYC+RUyWtbR2cm2+kzbG7RFWBBZRijGLd6fK2u0qkIPrD Bgtg== X-Gm-Message-State: APt69E3I7BmsYnHHi7Euhi/pl9b1TPjwA8FuEqBFtQWv3HAYGDpLK5I3 qcoFQVjf9ySJ4qeNwu4rME8EDg2A4iY= X-Received: by 2002:a1c:d509:: with SMTP id m9-v6mr580074wmg.69.1528817004925; Tue, 12 Jun 2018 08:23:24 -0700 (PDT) Received: from dogfood.home ([2a01:cb1d:112:6f00:3c84:18ae:27f2:d03]) by smtp.gmail.com with ESMTPSA id e2-v6sm500983wro.97.2018.06.12.08.23.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jun 2018 08:23:24 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Tue, 12 Jun 2018 17:22:55 +0200 Message-Id: <20180612152306.25998-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 Subject: [edk2] [RFC PATCH 00/11] GCC/X64: use hidden visibility for LTO PIE code X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Eric Dong , Ard Biesheuvel , Hao Wu , Jordan Justen , Andrew Fish , Leif Lindholm , Liming Gao , Zenith432 , Michael D Kinney , Laszlo Ersek , Star Zeng MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" The GCC toolchain uses PIE mode when building code for X64, because it is the most efficient in size: it uses relative references where possible, but still uses 64-bit quantities for absolute symbol references, which is optimal for executables that need to be converted to PE/COFF using GenFw. Enabling PIE mode has a couple of side effects though, primarily caused by the fact that the primary application area of GCC is to build programs for userland. GCC will assume that ELF symbols should be preemptible (which makes sense for PIC but not for PIE, but this simply seems to be the result of code being shared between the two modes), and it will attempt to keep absolute references close to each other so that dynamic relocations that trigger CoW for text pages have the smallest possible footprint. These side effects can be mititgated by overriding the visibility of all symbol definitions *and* symbol references, using a special #pragma. This will inform the compiler that symbol preemption and dynamic relocations are not a concern, and that all symbol references can be emitted as direct relative references rather than relative references to a GOT entry containing the absolute address. Unsurprisingly, this leads to better and smaller code. Unfortunately, we have not been able to set this override when LTO is in effect, because the LTO code generator infers from the hidden visibility of all symbols that none of the code is reachable, and discards it all, leading to corrupt, empty binaries. We can work around this by overriding the visibility for symbols that are module entry points. So implement this for all occcurrences of the symbol '_ModuleEntryPoint', and enable 'hidden' visibility in LTO builds as well. Note that all the changes in this series resolve to no-ops if USING_LTO is not #defined. Code can be found here: https://github.com/ardbiesheuvel/edk2/tree/x64-lto-visibility Cc: Michael D Kinney Cc: Liming Gao Cc: Ruiyu Ni Cc: Hao Wu Cc: Leif Lindholm Cc: Jordan Justen Cc: Andrew Fish Cc: Star Zeng Cc: Eric Dong Cc: Laszlo Ersek Cc: Zenith432 Cc: "Shi, Steven" Ard Biesheuvel (11): MdePkg/ProcessorBind.h: define macro to decorate module entry points DuetPkg: annotate module entry points with EFI_ENTRYPOINT EdkCompatibilityPkg: annotate module entry points with EFI_ENTRYPOINT EmbeddedPkg: annotate module entry points with EFI_ENTRYPOINT EmulatorPkg: annotate module entry points with EFI_ENTRYPOINT IntelFrameWorkPkg: annotate module entry points with EFI_ENTRYPOINT MdeModulePkg: annotate module entry points with EFI_ENTRYPOINT MdePkg: annotate module entry points with EFI_ENTRYPOINT Nt32Pkg: annotate module entry points with EFI_ENTRYPOINT UefiCpuPkg: annotate module entry points with EFI_ENTRYPOINT MdePkg/ProcessorBind.h X64: drop non-LTO limitation on visiblity override DuetPkg/DxeIpl/DxeInit.c | 1 + DuetPkg/EfiLdr/EfiLoader.c | 1 + .../EntryPoints/EdkIIGlueDxeDriverEntryPoint.c | 1 + .../EntryPoints/EdkIIGluePeimEntryPoint.c | 1 + .../EntryPoints/EdkIIGlueSmmDriverEntryPoint.c | 1 + .../Library/EdkIIGlueDxeSmmDriverEntryPoint.h | 1 + .../Include/Library/EdkIIGluePeimEntryPoint.h | 1 + .../Library/EdkIIGlueUefiDriverEntryPoint.h | 1 + EmbeddedPkg/TemplateSec/TemplateSec.c | 1 + EmulatorPkg/Sec/Sec.c | 1 + .../DxeSmmDriverEntryPoint/DriverEntryPoint.c | 1 + MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c | 1 + MdePkg/Include/Base.h | 7 +++++++ MdePkg/Include/Library/DxeCoreEntryPoint.h | 1 + MdePkg/Include/Library/PeiCoreEntryPoint.h | 1 + MdePkg/Include/Library/PeimEntryPoint.h | 1 + .../Include/Library/UefiApplicationEntryPoint.h | 1 + MdePkg/Include/Library/UefiDriverEntryPoint.h | 1 + MdePkg/Include/X64/ProcessorBind.h | 16 +++++++++++----- .../DxeCoreEntryPoint/DxeCoreEntryPoint.c | 1 + .../PeiCoreEntryPoint/PeiCoreEntryPoint.c | 1 + MdePkg/Library/PeimEntryPoint/PeimEntryPoint.c | 1 + .../ApplicationEntryPoint.c | 1 + .../UefiDriverEntryPoint/DriverEntryPoint.c | 1 + Nt32Pkg/Sec/SecMain.c | 1 + .../PlatformSecLibNull/PlatformSecLibNull.c | 1 + 26 files changed, 42 insertions(+), 5 deletions(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel