Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1702266 > unrolled thread

Re: [PATCH 1/2] kbuild: Add macros cc-option-3 and __cc-option-3

Started byMatthias Kaehlcke <mka@chromium.org>
First post2017-08-02 18:50 +0200
Last post2017-08-07 20:40 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH 1/2] kbuild: Add macros cc-option-3 and __cc-option-3 Matthias Kaehlcke <mka@chromium.org> - 2017-08-02 18:50 +0200
    Re: [PATCH 1/2] kbuild: Add macros cc-option-3 and __cc-option-3 Masahiro Yamada <yamada.masahiro@socionext.com> - 2017-08-07 03:10 +0200
      Re: [PATCH 1/2] kbuild: Add macros cc-option-3 and __cc-option-3 Matthias Kaehlcke <mka@chromium.org> - 2017-08-07 20:40 +0200

#1702266 — Re: [PATCH 1/2] kbuild: Add macros cc-option-3 and __cc-option-3

FromMatthias Kaehlcke <mka@chromium.org>
Date2017-08-02 18:50 +0200
SubjectRe: [PATCH 1/2] kbuild: Add macros cc-option-3 and __cc-option-3
Message-ID<ua50m-3TJ-15@gated-at.bofh.it>
El Fri, Jul 21, 2017 at 02:56:56PM -0700 Matthias Kaehlcke ha dit:

> The macro cc-option receives two parameters (the second may be empty). It
> returns the first parameter if it is a valid compiler option, otherwise
> the second one. It is not evaluated if the second parameter is a valid
> compiler option. This seems to be fine in virtually all cases, however
> there are scenarios where the second paramater needs to be evaluated too,
> and an empty value (or a third option) should be returned if it is not
> valid.
> 
> The macro cc-option-3 receives three parameters and returns parameter 1
> or 2 (in this order) if one of them is found to be a valid compiler
> option, and otherwise paramater 3. The macro __cc-option-3 works
> analogously.

Any comment on this?

Thanks

Matthias

> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> ---
>  scripts/Kbuild.include | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
> index dd8e2dde0b34..dc83635f2317 100644
> --- a/scripts/Kbuild.include
> +++ b/scripts/Kbuild.include
> @@ -113,6 +113,11 @@ as-instr = $(call try-run,\
>  __cc-option = $(call try-run,\
>  	$(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4))
>  
> +# __cc-option-3
> +# Usage: MY_CFLAGS += $(call __cc-option-3,$(CC),$(MY_CFLAGS),\
> +#	-mpreferred-stack-boundary=2,-mstack-alignment=4,)
> +__cc-option-3 = $(call __cc-option,$(1),$(2),$(3),$(call __cc-option,$(1),$(2),$(4),$(5)))
> +
>  # Do not attempt to build with gcc plugins during cc-option tests.
>  # (And this uses delayed resolution so the flags will be up to date.)
>  CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
> @@ -123,6 +128,10 @@ CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
>  cc-option = $(call __cc-option, $(CC),\
>  	$(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS),$(1),$(2))
>  
> +# cc-option-3
> +# Usage: cflags-y += $(call cc-option-3,-mpreferred-stack-boundary=3,-mstack-alignment=8,)
> +cc-option-3 = $(call cc-option,$(1),$(call cc-option,$(2),$(3)))
> +
>  # hostcc-option
>  # Usage: cflags-y += $(call hostcc-option,-march=winchip-c6,-march=i586)
>  hostcc-option = $(call __cc-option, $(HOSTCC),\

[toc] | [next] | [standalone]


#1705034

FromMasahiro Yamada <yamada.masahiro@socionext.com>
Date2017-08-07 03:10 +0200
Message-ID<ubEIp-1q6-3@gated-at.bofh.it>
In reply to#1702266
Hi Matthias,

Sorry for my late reply.

2017-08-03 1:46 GMT+09:00 Matthias Kaehlcke <mka@chromium.org>:
> El Fri, Jul 21, 2017 at 02:56:56PM -0700 Matthias Kaehlcke ha dit:
>
>> The macro cc-option receives two parameters (the second may be empty). It
>> returns the first parameter if it is a valid compiler option, otherwise
>> the second one. It is not evaluated if the second parameter is a valid
>> compiler option. This seems to be fine in virtually all cases, however
>> there are scenarios where the second paramater needs to be evaluated too,
>> and an empty value (or a third option) should be returned if it is not
>> valid.
>>
>> The macro cc-option-3 receives three parameters and returns parameter 1
>> or 2 (in this order) if one of them is found to be a valid compiler
>> option, and otherwise paramater 3. The macro __cc-option-3 works
>> analogously.
>
> Any comment on this?
>
> Thanks
>
> Matthias
>
>> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
>> ---
>>  scripts/Kbuild.include | 9 +++++++++
>>  1 file changed, 9 insertions(+)
>>
>> diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
>> index dd8e2dde0b34..dc83635f2317 100644
>> --- a/scripts/Kbuild.include
>> +++ b/scripts/Kbuild.include
>> @@ -113,6 +113,11 @@ as-instr = $(call try-run,\
>>  __cc-option = $(call try-run,\
>>       $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4))
>>
>> +# __cc-option-3
>> +# Usage: MY_CFLAGS += $(call __cc-option-3,$(CC),$(MY_CFLAGS),\
>> +#    -mpreferred-stack-boundary=2,-mstack-alignment=4,)
>> +__cc-option-3 = $(call __cc-option,$(1),$(2),$(3),$(call __cc-option,$(1),$(2),$(4),$(5)))
>> +
>>  # Do not attempt to build with gcc plugins during cc-option tests.
>>  # (And this uses delayed resolution so the flags will be up to date.)
>>  CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
>> @@ -123,6 +128,10 @@ CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
>>  cc-option = $(call __cc-option, $(CC),\
>>       $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS),$(1),$(2))
>>
>> +# cc-option-3
>> +# Usage: cflags-y += $(call cc-option-3,-mpreferred-stack-boundary=3,-mstack-alignment=8,)
>> +cc-option-3 = $(call cc-option,$(1),$(call cc-option,$(2),$(3)))


I do not like this macro much for the following reasons:


[1]
I guess your motivation is to evaluate the second option,
not receive the third option.

If this is the demand, I thought it might be nicer to
change cc-option to always evaluate the second option.

(I do no have a good idea for the implementation.)


[2]

cc-option-3 = $(call cc-option,$(1),$(call cc-option,$(2),$(3)))

evaluates the inner $(call cc-option,) first.

This works a bit differently from our expectation.


For example, let's consider the following case.

 $(call cc-option-3,-Oz,-Os,-O2)


I think we generally expect -Oz, -Os are tested in this order.
(If -Oz is supported by the compiler, the test for -Os will be skipped.)


In fact, cc-option-3 tests  -Os, -Oz in this order
because inner cc-option is evaluated before the outer one.
The test for -Os may or may not be necessary.

I do not have a good idea to improve this...





-- 
Best Regards
Masahiro Yamada

[toc] | [prev] | [next] | [standalone]


#1705786

FromMatthias Kaehlcke <mka@chromium.org>
Date2017-08-07 20:40 +0200
Message-ID<ubV6z-416-31@gated-at.bofh.it>
In reply to#1705034
Hi Masahiro,

El Mon, Aug 07, 2017 at 10:01:41AM +0900 Masahiro Yamada ha dit:

> Hi Matthias,
> 
> Sorry for my late reply.
> 
> 2017-08-03 1:46 GMT+09:00 Matthias Kaehlcke <mka@chromium.org>:
> > El Fri, Jul 21, 2017 at 02:56:56PM -0700 Matthias Kaehlcke ha dit:
> >
> >> The macro cc-option receives two parameters (the second may be empty). It
> >> returns the first parameter if it is a valid compiler option, otherwise
> >> the second one. It is not evaluated if the second parameter is a valid
> >> compiler option. This seems to be fine in virtually all cases, however
> >> there are scenarios where the second paramater needs to be evaluated too,
> >> and an empty value (or a third option) should be returned if it is not
> >> valid.
> >>
> >> The macro cc-option-3 receives three parameters and returns parameter 1
> >> or 2 (in this order) if one of them is found to be a valid compiler
> >> option, and otherwise paramater 3. The macro __cc-option-3 works
> >> analogously.
> >
> > Any comment on this?
> >
> > Thanks
> >
> > Matthias
> >
> >> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> >> ---
> >>  scripts/Kbuild.include | 9 +++++++++
> >>  1 file changed, 9 insertions(+)
> >>
> >> diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
> >> index dd8e2dde0b34..dc83635f2317 100644
> >> --- a/scripts/Kbuild.include
> >> +++ b/scripts/Kbuild.include
> >> @@ -113,6 +113,11 @@ as-instr = $(call try-run,\
> >>  __cc-option = $(call try-run,\
> >>       $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4))
> >>
> >> +# __cc-option-3
> >> +# Usage: MY_CFLAGS += $(call __cc-option-3,$(CC),$(MY_CFLAGS),\
> >> +#    -mpreferred-stack-boundary=2,-mstack-alignment=4,)
> >> +__cc-option-3 = $(call __cc-option,$(1),$(2),$(3),$(call __cc-option,$(1),$(2),$(4),$(5)))
> >> +
> >>  # Do not attempt to build with gcc plugins during cc-option tests.
> >>  # (And this uses delayed resolution so the flags will be up to date.)
> >>  CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
> >> @@ -123,6 +128,10 @@ CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
> >>  cc-option = $(call __cc-option, $(CC),\
> >>       $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS),$(1),$(2))
> >>
> >> +# cc-option-3
> >> +# Usage: cflags-y += $(call cc-option-3,-mpreferred-stack-boundary=3,-mstack-alignment=8,)
> >> +cc-option-3 = $(call cc-option,$(1),$(call cc-option,$(2),$(3)))
> 
> 
> I do not like this macro much for the following reasons:
> 
> 
> [1]
> I guess your motivation is to evaluate the second option,
> not receive the third option.

In this case yes, a future use case could be to support another
compiler with different option names, but I suppose we can focus
on the present for now.

> If this is the demand, I thought it might be nicer to
> change cc-option to always evaluate the second option.

I considered that, but was reluctant to change current behavior,
though in practice it shouldn't make a difference.

> (I do no have a good idea for the implementation.)

One option could be a variant of the try-run macro, that receives the
'base command' as first parameter:

try-run-opt = $(shell set -e;           \
        TMP="$(TMPOUT).$$$$.tmp";       \
        TMPO="$(TMPOUT).$$$$.o";        \
        if ($(1) $(2)) >/dev/null 2>&1; \
        then echo "$(2)";               \
        elif [ -n "${3}" ] && ($(1) $(3)) >/dev/null 2>&1;      \
        then echo "$(3)";               \
        else echo "";                   \
        fi;                             \
        rm -f "$$TMP" "$$TMPO")

__cc-option = $(call try-run-opt,\
        $(1) -Werror $(2) -c -x c /dev/null -o "$$TMP",$(3),$(4))

try-run-opt assumes that is is valid to append an option to the end
of the base command.

For consistency we'd probably want to adapt other suitable xx-option
macros as well.

Does this look reasonable to you?

> cc-option-3 = $(call cc-option,$(1),$(call cc-option,$(2),$(3)))
> 
> evaluates the inner $(call cc-option,) first.
> 
> This works a bit differently from our expectation.
> 
> 
> For example, let's consider the following case.
> 
>  $(call cc-option-3,-Oz,-Os,-O2)
> 
> 
> I think we generally expect -Oz, -Os are tested in this order.
> (If -Oz is supported by the compiler, the test for -Os will be skipped.)
> 
> 
> In fact, cc-option-3 tests  -Os, -Oz in this order
> because inner cc-option is evaluated before the outer one.
> The test for -Os may or may not be necessary.

I agree, running the check for the alternative options always is not
desirable.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web