MISRA D4.10 requires to have proper header guards in place in all header
files. Add header guards for generated asm generic headers as well.
Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
diff --git a/xen/scripts/Makefile.asm-generic b/xen/scripts/Makefile.asm-generic
index b0d356bfa3..a44844bed0 100644
--- a/xen/scripts/Makefile.asm-generic
+++ b/xen/scripts/Makefile.asm-generic
@@ -32,7 +32,12 @@ old-headers := $(wildcard $(obj)/*.h)
unwanted := $(filter-out $(generic-y) $(generated-y),$(old-headers))
quiet_cmd_wrap = WRAP $@
- cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
+ cmd_wrap = \
+ upper=$$(echo $*.h | tr a-z A-Z | tr '/.' '__'); \
+ printf "\#ifndef ASM_GENERIC_$${upper}\n" > $@; \
+ printf "\#define ASM_GENERIC_$${upper}\n" >> $@; \
+ printf "\#include <asm-generic/$*.h>\n" >> $@; \
+ printf "\#endif /* ASM_GENERIC_$${upper} */\n" >> $@
quiet_cmd_remove = REMOVE $(unwanted)
cmd_remove = rm -f $(unwanted)
On 05.06.2025 01:09, Stefano Stabellini wrote:
> --- a/xen/scripts/Makefile.asm-generic
> +++ b/xen/scripts/Makefile.asm-generic
> @@ -32,7 +32,12 @@ old-headers := $(wildcard $(obj)/*.h)
> unwanted := $(filter-out $(generic-y) $(generated-y),$(old-headers))
>
> quiet_cmd_wrap = WRAP $@
> - cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
> + cmd_wrap = \
> + upper=$$(echo $*.h | tr a-z A-Z | tr '/.' '__'); \
> + printf "\#ifndef ASM_GENERIC_$${upper}\n" > $@; \
> + printf "\#define ASM_GENERIC_$${upper}\n" >> $@; \
> + printf "\#include <asm-generic/$*.h>\n" >> $@; \
> + printf "\#endif /* ASM_GENERIC_$${upper} */\n" >> $@
I'm curious: In what is now a0f56da94c3e I had to resort to "define" to
get the rule to work (including a correct .*.cmd being generated). I
can't claim I actually understood why things didn't work the "simple
macro" way, and hence it's unclear to me whether the way it's done here
will work with all make versions.
One further difference to that other commit: If make is interrupted in
the middle of any of these printf-s, an incomplete file may remain. The
cmd_xlat_h rule specifically uses "mv -f $@.new $@" to cover that corner
case.
Finally - is ASM_GENERIC_$${upper} actually correct? Isn't that the
guard that ought to be used _in_ asm-generic/$*.h?
Jan
On Thu, 5 Jun 2025, Jan Beulich wrote:
> On 05.06.2025 01:09, Stefano Stabellini wrote:
> > --- a/xen/scripts/Makefile.asm-generic
> > +++ b/xen/scripts/Makefile.asm-generic
> > @@ -32,7 +32,12 @@ old-headers := $(wildcard $(obj)/*.h)
> > unwanted := $(filter-out $(generic-y) $(generated-y),$(old-headers))
> >
> > quiet_cmd_wrap = WRAP $@
> > - cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
> > + cmd_wrap = \
> > + upper=$$(echo $*.h | tr a-z A-Z | tr '/.' '__'); \
> > + printf "\#ifndef ASM_GENERIC_$${upper}\n" > $@; \
> > + printf "\#define ASM_GENERIC_$${upper}\n" >> $@; \
> > + printf "\#include <asm-generic/$*.h>\n" >> $@; \
> > + printf "\#endif /* ASM_GENERIC_$${upper} */\n" >> $@
>
> I'm curious: In what is now a0f56da94c3e I had to resort to "define" to
> get the rule to work (including a correct .*.cmd being generated). I
> can't claim I actually understood why things didn't work the "simple
> macro" way, and hence it's unclear to me whether the way it's done here
> will work with all make versions.
This works:
cmd_xlat_h = \
printf "\#ifndef COMPAT_XLAT_H\n" >$@.new; \
printf "\#define COMPAT_XLAT_H\n" >>$@.new; \
cat $(filter %.h,$^) >>$@.new; \
printf "" >>$@.new; \
printf "\#endif /* COMPAT_XLAT_H */\n" >>$@.new; \
mv -f $@.new $@
I made these changes:
- tab instead of spaces
- printf instead of echo
- escape # and add \n
> One further difference to that other commit: If make is interrupted in
> the middle of any of these printf-s, an incomplete file may remain. The
> cmd_xlat_h rule specifically uses "mv -f $@.new $@" to cover that corner
> case.
Good point I can fix it
> Finally - is ASM_GENERIC_$${upper} actually correct? Isn't that the
> guard that ought to be used _in_ asm-generic/$*.h?
You are right
On 06.06.2025 02:07, Stefano Stabellini wrote:
> On Thu, 5 Jun 2025, Jan Beulich wrote:
>> On 05.06.2025 01:09, Stefano Stabellini wrote:
>>> --- a/xen/scripts/Makefile.asm-generic
>>> +++ b/xen/scripts/Makefile.asm-generic
>>> @@ -32,7 +32,12 @@ old-headers := $(wildcard $(obj)/*.h)
>>> unwanted := $(filter-out $(generic-y) $(generated-y),$(old-headers))
>>>
>>> quiet_cmd_wrap = WRAP $@
>>> - cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
>>> + cmd_wrap = \
>>> + upper=$$(echo $*.h | tr a-z A-Z | tr '/.' '__'); \
>>> + printf "\#ifndef ASM_GENERIC_$${upper}\n" > $@; \
>>> + printf "\#define ASM_GENERIC_$${upper}\n" >> $@; \
>>> + printf "\#include <asm-generic/$*.h>\n" >> $@; \
>>> + printf "\#endif /* ASM_GENERIC_$${upper} */\n" >> $@
>>
>> I'm curious: In what is now a0f56da94c3e I had to resort to "define" to
>> get the rule to work (including a correct .*.cmd being generated). I
>> can't claim I actually understood why things didn't work the "simple
>> macro" way, and hence it's unclear to me whether the way it's done here
>> will work with all make versions.
>
> This works:
>
> cmd_xlat_h = \
> printf "\#ifndef COMPAT_XLAT_H\n" >$@.new; \
> printf "\#define COMPAT_XLAT_H\n" >>$@.new; \
> cat $(filter %.h,$^) >>$@.new; \
> printf "" >>$@.new; \
> printf "\#endif /* COMPAT_XLAT_H */\n" >>$@.new; \
> mv -f $@.new $@
>
> I made these changes:
> - tab instead of spaces
> - printf instead of echo
> - escape # and add \n
Hmm, out of these I guess it were the un-escaped #-es then. In your rule
I think the simpler "echo" would also be preferable.
Jan
© 2016 - 2025 Red Hat, Inc.