[edk2-devel] [PATCH v4 01/10] BaseTools: add BASETOOLS define

Ard Biesheuvel ardb at kernel.org
Tue May 23 07:07:45 UTC 2023


On Mon, 22 May 2023 at 16:31, Gerd Hoffmann <kraxel at redhat.com> 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
>
>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#105156): https://edk2.groups.io/g/devel/message/105156
Mute This Topic: https://groups.io/mt/98257896/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list