[PATCH] kconfig: detect LD implementation

Roger Pau Monne posted 1 patch 2 years, 2 months ago
Test gitlab-ci passed
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20220314105535.13518-1-roger.pau@citrix.com
xen/Kconfig | 6 ++++++
1 file changed, 6 insertions(+)
[PATCH] kconfig: detect LD implementation
Posted by Roger Pau Monne 2 years, 2 months ago
Detect GNU and LLVM ld implementations. This is required for further
patches that will introduce diverging behaviour depending on the
linker implementation in use.

Note that LLVM ld returns "compatible with GNU linkers" as part of the
version string, so be on the safe side and use '^' to only match at
the start of the line in case LLVM ever decides to change the text to
use "compatible with GNU ld" instead.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/Kconfig | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/xen/Kconfig b/xen/Kconfig
index d134397a0b..e8d5e70d46 100644
--- a/xen/Kconfig
+++ b/xen/Kconfig
@@ -23,6 +23,12 @@ config CLANG_VERSION
 	int
 	default $(shell,$(BASEDIR)/scripts/clang-version.sh $(CC))
 
+config LD_IS_GNU
+	def_bool $(success,$(LD) --version | head -n 1 | grep -q "^GNU ld")
+
+config LD_IS_LLVM
+	def_bool $(success,$(LD) --version | head -n 1 | grep -q "^LLD")
+
 # -fvisibility=hidden reduces -fpic cost, if it's available
 config CC_HAS_VISIBILITY_ATTRIBUTE
 	def_bool $(cc-option,-fvisibility=hidden)
-- 
2.34.1


Re: [PATCH] kconfig: detect LD implementation
Posted by Michal Orzel 2 years, 2 months ago
Hi Roger,

On 14.03.2022 11:55, Roger Pau Monne wrote:
> Detect GNU and LLVM ld implementations. This is required for further
> patches that will introduce diverging behaviour depending on the
> linker implementation in use.
> 
> Note that LLVM ld returns "compatible with GNU linkers" as part of the
> version string, so be on the safe side and use '^' to only match at
> the start of the line in case LLVM ever decides to change the text to
> use "compatible with GNU ld" instead.
> 
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> ---
>  xen/Kconfig | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/xen/Kconfig b/xen/Kconfig
> index d134397a0b..e8d5e70d46 100644
> --- a/xen/Kconfig
> +++ b/xen/Kconfig
> @@ -23,6 +23,12 @@ config CLANG_VERSION
>  	int
>  	default $(shell,$(BASEDIR)/scripts/clang-version.sh $(CC))
>  
> +config LD_IS_GNU
> +	def_bool $(success,$(LD) --version | head -n 1 | grep -q "^GNU ld")
> +> +config LD_IS_LLVM
> +	def_bool $(success,$(LD) --version | head -n 1 | grep -q "^LLD")
> +
>  # -fvisibility=hidden reduces -fpic cost, if it's available
>  config CC_HAS_VISIBILITY_ATTRIBUTE
>  	def_bool $(cc-option,-fvisibility=hidden)

NIT: You do not really need to use head especiialy if grep for the beginning of a line.
With or without this:
Reviewed-by: Michal Orzel <michal.orzel@arm.com>

Cheers,
Michal

Re: [PATCH] kconfig: detect LD implementation
Posted by Roger Pau Monné 2 years, 2 months ago
On Wed, Mar 16, 2022 at 11:28:48AM +0100, Michal Orzel wrote:
> Hi Roger,
> 
> On 14.03.2022 11:55, Roger Pau Monne wrote:
> > Detect GNU and LLVM ld implementations. This is required for further
> > patches that will introduce diverging behaviour depending on the
> > linker implementation in use.
> > 
> > Note that LLVM ld returns "compatible with GNU linkers" as part of the
> > version string, so be on the safe side and use '^' to only match at
> > the start of the line in case LLVM ever decides to change the text to
> > use "compatible with GNU ld" instead.
> > 
> > Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> > ---
> >  xen/Kconfig | 6 ++++++
> >  1 file changed, 6 insertions(+)
> > 
> > diff --git a/xen/Kconfig b/xen/Kconfig
> > index d134397a0b..e8d5e70d46 100644
> > --- a/xen/Kconfig
> > +++ b/xen/Kconfig
> > @@ -23,6 +23,12 @@ config CLANG_VERSION
> >  	int
> >  	default $(shell,$(BASEDIR)/scripts/clang-version.sh $(CC))
> >  
> > +config LD_IS_GNU
> > +	def_bool $(success,$(LD) --version | head -n 1 | grep -q "^GNU ld")
> > +> +config LD_IS_LLVM
> > +	def_bool $(success,$(LD) --version | head -n 1 | grep -q "^LLD")
> > +
> >  # -fvisibility=hidden reduces -fpic cost, if it's available
> >  config CC_HAS_VISIBILITY_ATTRIBUTE
> >  	def_bool $(cc-option,-fvisibility=hidden)
> 
> NIT: You do not really need to use head especiialy if grep for the beginning of a line.

I'm afraid I don't agree. We use head because we only want to match
against the first line of the output, and then we use '^' to match at
the beginning of such line. Without using head we would end up
matching at the beginning of any line present in the output.

Thanks, Roger.