diff mbox

[34/34] checkpatch: Warn about usage of __DATE__, __TIME__ and __TIMESTAMP__

Message ID 1302015561-21047-35-git-send-email-mmarek@suse.cz (mailing list archive)
State New, archived
Headers show

Commit Message

Michal Marek April 5, 2011, 2:59 p.m. UTC
The __TIME__ and __DATE__ macros are evil. Every C textbook mentions
them, but forgets to add the tiny detail that they make sure that your
code will never result in the same binary. __TIMESTAMP__ is a bit more
sane, but again produces noise as soon as you switch branches back and
forth, or apply a patch and revert it.

Cc: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>
---
 scripts/checkpatch.pl |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

Comments

Michal Marek May 26, 2011, 11:39 a.m. UTC | #1
On 5.4.2011 16:59, Michal Marek wrote:
> The __TIME__ and __DATE__ macros are evil. Every C textbook mentions
> them, but forgets to add the tiny detail that they make sure that your
> code will never result in the same binary. __TIMESTAMP__ is a bit more
> sane, but again produces noise as soon as you switch branches back and
> forth, or apply a patch and revert it.
> 
> Cc: Andy Whitcroft <apw@canonical.com>
> Signed-off-by: Michal Marek <mmarek@suse.cz>
> ---
>  scripts/checkpatch.pl |    5 +++++
>  1 files changed, 5 insertions(+), 0 deletions(-)

Hi Andy,

any comments about this patch?

Thanks,
Michal


> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 4c0383d..dbcdf04 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -2804,6 +2804,11 @@ sub process {
>  			WARN("__func__ should be used instead of gcc specific __FUNCTION__\n"  . $herecurr);
>  		}
>  
> +# check for pointless usage of __TIME__ and friends
> +		if ($line =~ /\b__(TIME|DATE|TIMESTAMP)__\b/) {
> +			WARN("Usage of __$1__ should be avoided to keep the build deterministic\n" . $herecurr);
> +		}
> +
>  # check for semaphores initialized locked
>  		if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
>  			WARN("consider using a completion\n" . $herecurr);

--
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
Andy Whitcroft May 26, 2011, 12:42 p.m. UTC | #2
On Tue, Apr 05, 2011 at 04:59:21PM +0200, Michal Marek wrote:
> The __TIME__ and __DATE__ macros are evil. Every C textbook mentions
> them, but forgets to add the tiny detail that they make sure that your
> code will never result in the same binary. __TIMESTAMP__ is a bit more
> sane, but again produces noise as soon as you switch branches back and
> forth, or apply a patch and revert it.
> 
> Cc: Andy Whitcroft <apw@canonical.com>
> Signed-off-by: Michal Marek <mmarek@suse.cz>
> ---
>  scripts/checkpatch.pl |    5 +++++
>  1 files changed, 5 insertions(+), 0 deletions(-)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 4c0383d..dbcdf04 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -2804,6 +2804,11 @@ sub process {
>  			WARN("__func__ should be used instead of gcc specific __FUNCTION__\n"  . $herecurr);
>  		}
>  
> +# check for pointless usage of __TIME__ and friends
> +		if ($line =~ /\b__(TIME|DATE|TIMESTAMP)__\b/) {
> +			WARN("Usage of __$1__ should be avoided to keep the build deterministic\n" . $herecurr);
> +		}
> +
>  # check for semaphores initialized locked
>  		if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
>  			WARN("consider using a completion\n" . $herecurr);
> -- 
> 1.7.4.1

Looks reasonable to me.

-apw
--
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/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4c0383d..dbcdf04 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2804,6 +2804,11 @@  sub process {
 			WARN("__func__ should be used instead of gcc specific __FUNCTION__\n"  . $herecurr);
 		}
 
+# check for pointless usage of __TIME__ and friends
+		if ($line =~ /\b__(TIME|DATE|TIMESTAMP)__\b/) {
+			WARN("Usage of __$1__ should be avoided to keep the build deterministic\n" . $herecurr);
+		}
+
 # check for semaphores initialized locked
 		if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
 			WARN("consider using a completion\n" . $herecurr);