From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.92.18.66]) by mx.groups.io with SMTP id smtpd.web10.949.1591813273251514857 for ; Wed, 10 Jun 2020 11:21:13 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@outlook.com header.s=selector1 header.b=qbJK0Z2/; spf=pass (domain: outlook.com, ip: 40.92.18.66, mailfrom: spbrogan@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f2PrZXkvj57N2LqDYUlOO8snd2ObSijyZ+4a/NVh/8VnYxYdQX+DI+sa16KvaVQiZ7BtqJkG00sgg6eDdGVlwGvJFJfWp5tG6u5lnprSOphdX1bQVvRYR8+kDd5wmNCInXU5qE0+wlMadJovxYs8HJunhBbDsBGqgXXMWOnOCA3bknEda7ALXYcltwUlcpeCzUtHxOlkq1ZKEr9PyDOyA9m0q+R2/9Vi5kQNevZJOpSevtXCDJum9dSQXiWGMjmezfb7Z09HN2Wi/wN0YpfecBQ3kCWaJhr/AsW6YYKbCOCU8e6eEUbHJf+CL9qZejA0vGTKc5IjS6L+7T2yc9YP+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/w60fXSFu5yocJ1LIo4zRsM9N/wgyWEPKKvhxPNZLKg=; b=knLFgQMF1XTr96RTB2P48/HnvvhsfraZM7nBg6nEO5cCDaEOZdm0qpujjiPGFEKhtOBlHMMbrMabjBYcqmSgCsQ9ecFKZJl3ZkOSXfcqWaPWmQndhX80KxiFVZMDzCGxQNe2LbpGFweBkQXsNSz1fP86K709l32i6+1rKB08aN1wpIX2Bkj1yK/1M+DFaL7lkze5yy0xxDy+Db0iMs2DoLkM1cy1JvCgwtlyFFTNqKg0ojv4AHw2/s0U5EcDeM8WqgBIoaLemNdC81d7flzcQY6+xfb7EY7msBDqiU/pCvnilw/uLtQfKU4Qf7n3qUL8ixsKKw4YO/QCs9qoWyZeSQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/w60fXSFu5yocJ1LIo4zRsM9N/wgyWEPKKvhxPNZLKg=; b=qbJK0Z2/23MYsGSuprZbOUdW7vBPfDyJPx3I794FlHkNgz1qWjJjyNLFZg9c5hlLyBEK+5Tulzm5vypHAYdkyGAAKThRZLYLJzYinhOa3qiOkQpY8A86AVWoGSXSFBLjX2ojRtD5phl+DjOEHFbPoNr/OdY0KiPa8RA2+Fy6IfBEJv9cmQfSjgtTNhGEnrvuAVlWNHdB6EexDhrWKu567hEpYnXQDLa54NJPNiWAv4EOyWZ7qWEvsKSCT6VQpInp3WM1SS6oP+BvJFHNJR9sUneBGS+uV7jVZAm0yaO+s3svDaE7nn3e/lNhFqyrpF6U4qSQpRjExYY5SXcOILj/Ww== Received: from BN8NAM11FT044.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4b::4c) by BN8NAM11HT030.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4b::268) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.18; Wed, 10 Jun 2020 18:21:12 +0000 Received: from BN8PR07MB6962.namprd07.prod.outlook.com (2a01:111:e400:fc4b::51) by BN8NAM11FT044.mail.protection.outlook.com (2a01:111:e400:fc4b::475) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.18 via Frontend Transport; Wed, 10 Jun 2020 18:21:12 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:69049863ACE0B9AF7EC7F5C526B850EF29D2F127BBE8499E18349C6C01B6DBA5;UpperCasedChecksum:79D5410025DD58A0A08BDC85E0BF5F9A1A6A9D99E3CC08A1C6274F0589B2ED8E;SizeAsReceived:9006;Count:49 Received: from BN8PR07MB6962.namprd07.prod.outlook.com ([fe80::edbc:7122:7dd9:1403]) by BN8PR07MB6962.namprd07.prod.outlook.com ([fe80::edbc:7122:7dd9:1403%8]) with mapi id 15.20.3088.018; Wed, 10 Jun 2020 18:21:12 +0000 Subject: Re: [edk2-devel] [PATCH 4/5] StandaloneMmPkg: generate position independent code for StMM core To: devel@edk2.groups.io, ard.biesheuvel@arm.com Cc: Michael D Kinney , Liming Gao , Jiewen Yao , Sami Mujawar , Ilias Apalodimas References: <20200610081740.54581-1-ard.biesheuvel@arm.com> <20200610081740.54581-5-ard.biesheuvel@arm.com> From: "Sean" Message-ID: Date: Wed, 10 Jun 2020 11:21:09 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 In-Reply-To: <20200610081740.54581-5-ard.biesheuvel@arm.com> X-ClientProxiedBy: CO2PR04CA0079.namprd04.prod.outlook.com (2603:10b6:102:1::47) To BN8PR07MB6962.namprd07.prod.outlook.com (2603:10b6:408:d6::11) Return-Path: spbrogan@outlook.com X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.2.78] (50.47.113.221) by CO2PR04CA0079.namprd04.prod.outlook.com (2603:10b6:102:1::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.18 via Frontend Transport; Wed, 10 Jun 2020 18:21:11 +0000 X-Microsoft-Original-Message-ID: X-TMN: [vtOz1dUC86YLMN+Q1rbcMUsG/3+79NhD] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 49 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 925bd6ea-6226-43bb-941e-08d80d6b0dcc X-MS-TrafficTypeDiagnostic: BN8NAM11HT030: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gTGJ8Kzo5GE1/+kGh65Kkut90qeQXmFKvoIKmORz943CbdSflp+W8N8QInEc1uHvo8UDBJWBsprLMAt/TFtZTzprdB9gSPfrn+pHu4tnrI4NsC+azgm+SN6RckN0YB431u0N52sKa0RoGcycF8+CFzFxb9R6MP6mP0hngL2lgjAQge0oseIPfT/PFiHEc+2enbJO5nBywMOGjx86BJqcww== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR07MB6962.namprd07.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; X-MS-Exchange-AntiSpam-MessageData: x2OgRJcZ5hLBaCZGxx2zonKDLNQZAA2EI/vPBWjc/LDzsH1VyG8jmesB0q6nZY05HTszihlAm1gInLRkDGkwjnwRHcih+EcQQ+CUBlcEqMbFhsEqW08t7K76uwGngmJSCoLvTfMf1FggEwZ8LMU2HA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 925bd6ea-6226-43bb-941e-08d80d6b0dcc X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2020 18:21:12.0672 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8NAM11HT030 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Ard, I see you are only doing this for GCC? Is it not needed for VS or clang? Are these toolchains not supported for StandaloneMmPkg? Not trying to hold up your work and don't expect you to enable every toolchain but also don't like the idea of only building out support for a single toolchain given all the work that has gone into making modules compatible with numerous toolchains. thoughts? Thanks Sean On 6/10/2020 1:17 AM, Ard Biesheuvel wrote: > The standalone MM core runs in a restricted environment that is set > up by a higher privilege level, and which may not allow memory regions > to be writable and executable at the same time. > > This means that making the StMM core self-relocatable requires that > all the targets of the relocation fixups are outside of the executable > region of the image, given that we cannot remap the executable code > writable from the executable code itself without losing those execute > permissions. > > So instead, use the existing toolchain support to ensure that position > independent code is used where possible, and that all the remaining > relocated quantities are emitted into the data section. (Note that > staticallly initialized const pointers will be emitted into the > .data.rel.ro section, which gets pulled into the .data section by > our linker script) > > To ensure that we don't pick up any absolute references in executable > code inadvertently (e.g., in assembler code), add the '-z text' linker > option which will force the build to fail in this case. > > Signed-off-by: Ard Biesheuvel > --- > StandaloneMmPkg/Core/StandaloneMmCore.inf | 4 ++++ > StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf | 3 +++ > 2 files changed, 7 insertions(+) > > diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.inf b/StandaloneMmPkg/Core/StandaloneMmCore.inf > index d17ff9965bdc..87bf6e9440a7 100644 > --- a/StandaloneMmPkg/Core/StandaloneMmCore.inf > +++ b/StandaloneMmPkg/Core/StandaloneMmCore.inf > @@ -75,3 +75,7 @@ [Guids] > gEfiEventLegacyBootGuid > > gEfiEventExitBootServicesGuid > > gEfiEventReadyToBootGuid > > + > > +[BuildOptions] > > + GCC:*_*_*_CC_FLAGS = -fpie > > + GCC:*_*_*_DLINK_FLAGS = -Wl,-z,text,-Bsymbolic,-pie > > diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf > index 891c292e92f8..7d6ee4e08ecb 100644 > --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf > +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf > @@ -48,3 +48,6 @@ [Guids] > gEfiMmPeiMmramMemoryReserveGuid > > gEfiStandaloneMmNonSecureBufferGuid > > gEfiArmTfCpuDriverEpDescriptorGuid > > + > > +[BuildOptions] > > + GCC:*_*_*_CC_FLAGS = -fpie >