From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.15567.1684825681743221153 for ; Tue, 23 May 2023 00:08:01 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=K6Z7GS9y; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3192F62F92 for ; Tue, 23 May 2023 07:08:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70142C4339B for ; Tue, 23 May 2023 07:07:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684825679; bh=RaUTLmtiqUb8PJ3W/8Kgyn1PR9fcEopiqPBNxchIRi0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=K6Z7GS9yOBAOecfi5IBa7hqYZUnPd6bOfcG4AC2QkD8ZlkycDnfmC4M2zcn9z3i7E F8Bas3tzaXRZvk+mqKNvw0Ly1LHixVizn2FmLIbbkfCcyEQKTfETrHLHXOSQv6AQth Sc6Owq1G3xWV797DgYYWu6HsiRNtTdw79zm1uxM8zLmr0ldfWMqwstcnSC/ueNsjeN tUXNTFP7OPlAlF7/aCaRb70agWK085rv9FlIe2HBjEKcRd/eamsAM5g21sjjebX+LJ 5gO0ip0c1qX2wZycPgXzQ3SBbh0q/lbInLZMVh8vKiVaQ2uBXZu3nOcOii1r6qGu71 sRA6J4XZKHOKA== Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2af2c7f2883so38694071fa.3 for ; Tue, 23 May 2023 00:07:59 -0700 (PDT) X-Gm-Message-State: AC+VfDzjL1YnRmQfUIJl+tPgc2CSKWPOQyNOUcqcq83t5KbAKJeF/bLX 346XnVAFCMJ7dc/9IOLk4yao6gr38wKncxkINfU= X-Google-Smtp-Source: ACHHUZ7Whd1WKjaOOa9U8bkPfIbBEHbbbu5EuACESkMaMUAjLvnCYrjp01DkWWP9UXYHmu+DANBDhUIO18IBRx+oADQ= X-Received: by 2002:ac2:5315:0:b0:4ef:6ed9:7af2 with SMTP id c21-20020ac25315000000b004ef6ed97af2mr4252438lfh.8.1684825677428; Tue, 23 May 2023 00:07:57 -0700 (PDT) MIME-Version: 1.0 References: <20230414080250.1357004-2-kraxel@redhat.com> <18EC1A6E-8B81-4564-83A5-DA8EC2BA54ED@posteo.de> <7twvlm4w6euyc637maj4mqskob5747wfu4tridl4jtxujruegg@r4jyw7vitl3w> In-Reply-To: From: "Ard Biesheuvel" Date: Tue, 23 May 2023 09:07:45 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] [PATCH v4 01/10] BaseTools: add BASETOOLS define To: Gerd Hoffmann Cc: devel@edk2.groups.io, =?UTF-8?Q?Marvin_H=C3=A4user?= , Pawel Polawski , Dongyan Qian , Sunil V L , Baoqi Zhang , Chao Li , Rebecca Cran , Ard Biesheuvel , Zhiguang Liu , Liming Gao , Yuwei Chen , Leif Lindholm , Michael D Kinney , Daniel Schaefer , Bob Feng , Oliver Steffen Content-Type: text/plain; charset="UTF-8" On Mon, 22 May 2023 at 16:31, Gerd Hoffmann wrote: > > Hi, > > > > Recent clang does have a '-fdirect-access-external-data' switch which > > > should suppress these references, maybe in combination with > > > -fvisibility=hidden? > > > > I'll try that. > > Works (test patch below for reference). > Excellent, thanks for confirming. So basically, -fdirect-access-external-data forces the behavior in Clang that became the default behavior in GCC 5, which is to assume that an external variable reference can be resolved without the GOT, which is usually true for hosted binaries (given that shared libraries rarely export data symbols but only code symbols, so data symbols can be assumed to be part of the same executable). It is always true for EDK2 as we don't use runtime linking at all. So I think we should add this for all Clang configurations that enable PIE codegen. We don't support GCC < 5 anyway so this gives us uniform behavior for all ELF based toolchains used for x86. > > diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template > index 503a6687c1f0..f19992f68a84 100755 > --- a/BaseTools/Conf/tools_def.template > +++ b/BaseTools/Conf/tools_def.template > @@ -1929,7 +1929,7 @@ RELEASE_CLANGDWARF_X64_CC_FLAGS = DEF(CLANGDWARF_ALL_CC_FLAGS) -m64 "-DEFI > RELEASE_CLANGDWARF_X64_DLINK_FLAGS = DEF(CLANGDWARF_IA32_X64_DLINK_FLAGS) -flto -Wl,-O3 -Wl,-melf_x86_64 -Wl,--oformat,elf64-x86-64 -Wl,-pie -mcmodel=small -Wl,--apply-dynamic-relocs > RELEASE_CLANGDWARF_X64_DLINK2_FLAGS = DEF(CLANGDWARF_X64_DLINK2_FLAGS) -O3 -fuse-ld=lld > > -NOOPT_CLANGDWARF_X64_CC_FLAGS = DEF(CLANGDWARF_ALL_CC_FLAGS) -m64 "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -fpie -O0 DEF(CLANGDWARF_X64_TARGET) -g > +NOOPT_CLANGDWARF_X64_CC_FLAGS = DEF(CLANGDWARF_ALL_CC_FLAGS) -m64 "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -fpie -O0 DEF(CLANGDWARF_X64_TARGET) -g -fdirect-access-external-data > NOOPT_CLANGDWARF_X64_DLINK_FLAGS = DEF(CLANGDWARF_IA32_X64_DLINK_FLAGS) -Wl,-O0 -Wl,-melf_x86_64 -Wl,--oformat,elf64-x86-64 -Wl,-pie -mcmodel=small -Wl,--apply-dynamic-relocs > NOOPT_CLANGDWARF_X64_DLINK2_FLAGS = DEF(CLANGDWARF_X64_DLINK2_FLAGS) -O0 -fuse-ld=lld > >