diff mbox

Makefile: Unset stack-protector gcc flag if it is not supported

Message ID 1391793327-9578-1-git-send-email-markos.chandras@imgtec.com (mailing list archive)
State New, archived
Headers show

Commit Message

Markos Chandras Feb. 7, 2014, 5:15 p.m. UTC
In case the compiler does not support the stack-protector option,
unset the flag to avoid build failures. Printing a warning is enough
to let the user know that this flag will not be used.
Fixes the following build problem when using a toolchain which does
not support the -fstack-protector-strong flag:

Makefile:614: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG:
-fstack-protector-strong not supported by compiler
mips-linux-gnu-gcc: error: unrecognized command line option
'-fstack-protector-strong'
scripts/Makefile.build:308: recipe for target 'scripts/mod/empty.o' failed
make[2]: *** [scripts/mod/empty.o] Error 1
make[2]: *** Waiting for unfinished jobs....
scripts/Makefile.build:455: recipe for target 'scripts/mod' failed

Cc: Michal Marek <mmarek@suse.cz>
Cc: linux-kbuild@vger.kernel.org
Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)

Comments

Markos Chandras Feb. 13, 2014, 11:04 a.m. UTC | #1
On 02/07/2014 05:15 PM, Markos Chandras wrote:
> In case the compiler does not support the stack-protector option,
> unset the flag to avoid build failures. Printing a warning is enough
> to let the user know that this flag will not be used.
> Fixes the following build problem when using a toolchain which does
> not support the -fstack-protector-strong flag:
>
> Makefile:614: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG:
> -fstack-protector-strong not supported by compiler
> mips-linux-gnu-gcc: error: unrecognized command line option
> '-fstack-protector-strong'
> scripts/Makefile.build:308: recipe for target 'scripts/mod/empty.o' failed
> make[2]: *** [scripts/mod/empty.o] Error 1
> make[2]: *** Waiting for unfinished jobs....
> scripts/Makefile.build:455: recipe for target 'scripts/mod' failed
>
> Cc: Michal Marek <mmarek@suse.cz>
> Cc: linux-kbuild@vger.kernel.org
> Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
> ---
>   Makefile | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/Makefile b/Makefile
> index 606ef7c..63a5333 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -607,12 +607,14 @@ ifdef CONFIG_CC_STACKPROTECTOR_REGULAR
>     ifeq ($(call cc-option, $(stackp-flag)),)
>       $(warning Cannot use CONFIG_CC_STACKPROTECTOR: \
>   	      -fstack-protector not supported by compiler))
> +    stackp-flag :=
>     endif
>   else ifdef CONFIG_CC_STACKPROTECTOR_STRONG
>     stackp-flag := -fstack-protector-strong
>     ifeq ($(call cc-option, $(stackp-flag)),)
>       $(warning Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: \
>   	      -fstack-protector-strong not supported by compiler)
> +    stackp-flag :=
>     endif
>   else
>     # Force off for distro compilers that enable stack protector by default.
>
Hi,

ping?
Markos Chandras Feb. 20, 2014, 12:46 p.m. UTC | #2
On 02/07/2014 05:15 PM, Markos Chandras wrote:
> In case the compiler does not support the stack-protector option,
> unset the flag to avoid build failures. Printing a warning is enough
> to let the user know that this flag will not be used.
> Fixes the following build problem when using a toolchain which does
> not support the -fstack-protector-strong flag:
>
> Makefile:614: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG:
> -fstack-protector-strong not supported by compiler
> mips-linux-gnu-gcc: error: unrecognized command line option
> '-fstack-protector-strong'
> scripts/Makefile.build:308: recipe for target 'scripts/mod/empty.o' failed
> make[2]: *** [scripts/mod/empty.o] Error 1
> make[2]: *** Waiting for unfinished jobs....
> scripts/Makefile.build:455: recipe for target 'scripts/mod' failed
>
> Cc: Michal Marek <mmarek@suse.cz>
> Cc: linux-kbuild@vger.kernel.org
> Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
> ---
>   Makefile | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/Makefile b/Makefile
> index 606ef7c..63a5333 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -607,12 +607,14 @@ ifdef CONFIG_CC_STACKPROTECTOR_REGULAR
>     ifeq ($(call cc-option, $(stackp-flag)),)
>       $(warning Cannot use CONFIG_CC_STACKPROTECTOR: \
>   	      -fstack-protector not supported by compiler))
> +    stackp-flag :=
>     endif
>   else ifdef CONFIG_CC_STACKPROTECTOR_STRONG
>     stackp-flag := -fstack-protector-strong
>     ifeq ($(call cc-option, $(stackp-flag)),)
>       $(warning Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: \
>   	      -fstack-protector-strong not supported by compiler)
> +    stackp-flag :=
>     endif
>   else
>     # Force off for distro compilers that enable stack protector by default.
>

Ping again?
Richard Weinberger Feb. 20, 2014, 12:53 p.m. UTC | #3
On Thu, Feb 20, 2014 at 1:46 PM, Markos Chandras
<Markos.Chandras@imgtec.com> wrote:
> On 02/07/2014 05:15 PM, Markos Chandras wrote:
>>
>> In case the compiler does not support the stack-protector option,
>> unset the flag to avoid build failures. Printing a warning is enough
>> to let the user know that this flag will not be used.
>> Fixes the following build problem when using a toolchain which does
>> not support the -fstack-protector-strong flag:
>>
>> Makefile:614: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG:
>> -fstack-protector-strong not supported by compiler
>> mips-linux-gnu-gcc: error: unrecognized command line option
>> '-fstack-protector-strong'
>> scripts/Makefile.build:308: recipe for target 'scripts/mod/empty.o' failed
>> make[2]: *** [scripts/mod/empty.o] Error 1
>> make[2]: *** Waiting for unfinished jobs....
>> scripts/Makefile.build:455: recipe for target 'scripts/mod' failed
>>
>> Cc: Michal Marek <mmarek@suse.cz>
>> Cc: linux-kbuild@vger.kernel.org
>> Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
>> ---
>>   Makefile | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/Makefile b/Makefile
>> index 606ef7c..63a5333 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -607,12 +607,14 @@ ifdef CONFIG_CC_STACKPROTECTOR_REGULAR
>>     ifeq ($(call cc-option, $(stackp-flag)),)
>>       $(warning Cannot use CONFIG_CC_STACKPROTECTOR: \
>>               -fstack-protector not supported by compiler))
>> +    stackp-flag :=
>>     endif
>>   else ifdef CONFIG_CC_STACKPROTECTOR_STRONG
>>     stackp-flag := -fstack-protector-strong
>>     ifeq ($(call cc-option, $(stackp-flag)),)
>>       $(warning Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: \
>>               -fstack-protector-strong not supported by compiler)
>> +    stackp-flag :=
>>     endif
>>   else
>>     # Force off for distro compilers that enable stack protector by
>> default.
>>
>
> Ping again?

This is by design. We want the build fail if
CONFIG_CC_STACKPROTECTOR_STRONG is set
but the toolchain does not support it.
Otherwise we could end up with a kernel without stackprotector even if
the config symbol is set.
Markos Chandras Feb. 20, 2014, 1:53 p.m. UTC | #4
On 02/20/2014 12:53 PM, Richard Weinberger wrote:
> On Thu, Feb 20, 2014 at 1:46 PM, Markos Chandras
> <Markos.Chandras@imgtec.com> wrote:
>> On 02/07/2014 05:15 PM, Markos Chandras wrote:
>>>
>>> In case the compiler does not support the stack-protector option,
>>> unset the flag to avoid build failures. Printing a warning is enough
>>> to let the user know that this flag will not be used.
>>> Fixes the following build problem when using a toolchain which does
>>> not support the -fstack-protector-strong flag:
>>>
>>> Makefile:614: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG:
>>> -fstack-protector-strong not supported by compiler
>>> mips-linux-gnu-gcc: error: unrecognized command line option
>>> '-fstack-protector-strong'
>>> scripts/Makefile.build:308: recipe for target 'scripts/mod/empty.o' failed
>>> make[2]: *** [scripts/mod/empty.o] Error 1
>>> make[2]: *** Waiting for unfinished jobs....
>>> scripts/Makefile.build:455: recipe for target 'scripts/mod' failed
>>>
>>> Cc: Michal Marek <mmarek@suse.cz>
>>> Cc: linux-kbuild@vger.kernel.org
>>> Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
>>> ---
>>>    Makefile | 2 ++
>>>    1 file changed, 2 insertions(+)
>>>
>>> diff --git a/Makefile b/Makefile
>>> index 606ef7c..63a5333 100644
>>> --- a/Makefile
>>> +++ b/Makefile
>>> @@ -607,12 +607,14 @@ ifdef CONFIG_CC_STACKPROTECTOR_REGULAR
>>>      ifeq ($(call cc-option, $(stackp-flag)),)
>>>        $(warning Cannot use CONFIG_CC_STACKPROTECTOR: \
>>>                -fstack-protector not supported by compiler))
>>> +    stackp-flag :=
>>>      endif
>>>    else ifdef CONFIG_CC_STACKPROTECTOR_STRONG
>>>      stackp-flag := -fstack-protector-strong
>>>      ifeq ($(call cc-option, $(stackp-flag)),)
>>>        $(warning Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: \
>>>                -fstack-protector-strong not supported by compiler)
>>> +    stackp-flag :=
>>>      endif
>>>    else
>>>      # Force off for distro compilers that enable stack protector by
>>> default.
>>>
>>
>> Ping again?
>
> This is by design. We want the build fail if
> CONFIG_CC_STACKPROTECTOR_STRONG is set
> but the toolchain does not support it.
> Otherwise we could end up with a kernel without stackprotector even if
> the config symbol is set.
>

Hi Richard,

Then maybe the $(warning...) should be converted to $(error...)?
Because it's not really a warning if the build failure is expected to 
happen.
Richard Weinberger Feb. 20, 2014, 1:57 p.m. UTC | #5
Am 20.02.2014 14:53, schrieb Markos Chandras:
> On 02/20/2014 12:53 PM, Richard Weinberger wrote:
>> On Thu, Feb 20, 2014 at 1:46 PM, Markos Chandras
>> <Markos.Chandras@imgtec.com> wrote:
>>> On 02/07/2014 05:15 PM, Markos Chandras wrote:
>>>>
>>>> In case the compiler does not support the stack-protector option,
>>>> unset the flag to avoid build failures. Printing a warning is enough
>>>> to let the user know that this flag will not be used.
>>>> Fixes the following build problem when using a toolchain which does
>>>> not support the -fstack-protector-strong flag:
>>>>
>>>> Makefile:614: Cannot use CONFIG_CC_STACKPROTECTOR_STRONG:
>>>> -fstack-protector-strong not supported by compiler
>>>> mips-linux-gnu-gcc: error: unrecognized command line option
>>>> '-fstack-protector-strong'
>>>> scripts/Makefile.build:308: recipe for target 'scripts/mod/empty.o' failed
>>>> make[2]: *** [scripts/mod/empty.o] Error 1
>>>> make[2]: *** Waiting for unfinished jobs....
>>>> scripts/Makefile.build:455: recipe for target 'scripts/mod' failed
>>>>
>>>> Cc: Michal Marek <mmarek@suse.cz>
>>>> Cc: linux-kbuild@vger.kernel.org
>>>> Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
>>>> ---
>>>>    Makefile | 2 ++
>>>>    1 file changed, 2 insertions(+)
>>>>
>>>> diff --git a/Makefile b/Makefile
>>>> index 606ef7c..63a5333 100644
>>>> --- a/Makefile
>>>> +++ b/Makefile
>>>> @@ -607,12 +607,14 @@ ifdef CONFIG_CC_STACKPROTECTOR_REGULAR
>>>>      ifeq ($(call cc-option, $(stackp-flag)),)
>>>>        $(warning Cannot use CONFIG_CC_STACKPROTECTOR: \
>>>>                -fstack-protector not supported by compiler))
>>>> +    stackp-flag :=
>>>>      endif
>>>>    else ifdef CONFIG_CC_STACKPROTECTOR_STRONG
>>>>      stackp-flag := -fstack-protector-strong
>>>>      ifeq ($(call cc-option, $(stackp-flag)),)
>>>>        $(warning Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: \
>>>>                -fstack-protector-strong not supported by compiler)
>>>> +    stackp-flag :=
>>>>      endif
>>>>    else
>>>>      # Force off for distro compilers that enable stack protector by
>>>> default.
>>>>
>>>
>>> Ping again?
>>
>> This is by design. We want the build fail if
>> CONFIG_CC_STACKPROTECTOR_STRONG is set
>> but the toolchain does not support it.
>> Otherwise we could end up with a kernel without stackprotector even if
>> the config symbol is set.
>>
> 
> Hi Richard,
> 
> Then maybe the $(warning...) should be converted to $(error...)?
> Because it's not really a warning if the build failure is expected to happen.

No. This would break silentoldconfig.

Thanks,
//richard
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/Makefile b/Makefile
index 606ef7c..63a5333 100644
--- a/Makefile
+++ b/Makefile
@@ -607,12 +607,14 @@  ifdef CONFIG_CC_STACKPROTECTOR_REGULAR
   ifeq ($(call cc-option, $(stackp-flag)),)
     $(warning Cannot use CONFIG_CC_STACKPROTECTOR: \
 	      -fstack-protector not supported by compiler))
+    stackp-flag :=
   endif
 else ifdef CONFIG_CC_STACKPROTECTOR_STRONG
   stackp-flag := -fstack-protector-strong
   ifeq ($(call cc-option, $(stackp-flag)),)
     $(warning Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: \
 	      -fstack-protector-strong not supported by compiler)
+    stackp-flag :=
   endif
 else
   # Force off for distro compilers that enable stack protector by default.