Message ID | CAN_72e10vHGWwmovq_ra7FKE9EQgo-T+r8AavwFErkEV9Hnuww@mail.gmail.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
On Tue, Jul 18, 2017 at 5:59 PM, Pavel Roskin <plroskin@gmail.com> wrote: > The option argument is parsed into major, minor and patchlevel versions, > which are defined as __GNUC__, __GNUC_MINOR__, and __GNUC_PATCHLEVEL__ in > the preprocessor. > > One possible use is running sparse compiled with the lastest gcc compiler > on a Linux kernel that doesn't support that compiler. I am curious, can you just invoke sparse with -D__GNUC__=1 -D__GNUC_MINOR__=2 to do the same thing? The current __GNUC__ was a weak define it is suitable for overriding if you wants to. Chris -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Jul 18, 2017 at 4:35 PM, Christopher Li <sparse@chrisli.org> wrote: > On Tue, Jul 18, 2017 at 5:59 PM, Pavel Roskin <plroskin@gmail.com> wrote: >> The option argument is parsed into major, minor and patchlevel versions, >> which are defined as __GNUC__, __GNUC_MINOR__, and __GNUC_PATCHLEVEL__ in >> the preprocessor. >> >> One possible use is running sparse compiled with the lastest gcc compiler >> on a Linux kernel that doesn't support that compiler. > > I am curious, can you just invoke sparse with -D__GNUC__=1 -D__GNUC_MINOR__=2 > to do the same thing? > > The current __GNUC__ was a weak define it is suitable for overriding > if you wants to. Yes, that works! I wish I thought of it earlier and did not waste time writing that patch. That option may still be useful if sparse attempts to imitate the behavior of specific gcc versions (in addition to the defines).
On Tue, Jul 18, 2017 at 7:46 PM, Pavel Roskin <plroskin@gmail.com> wrote: > Yes, that works! I wish I thought of it earlier and did not waste time > writing that patch. > > That option may still be useful if sparse attempts to imitate the > behavior of specific gcc versions (in addition to the defines). I will skip the patch for now. Yes it is more convenient to give one command line options and it set 3 macros. I am not sure the complexity justify it. When you specify the gcc version, there is also implicit version specific behavior go with it. I can see user file bugs said I give sparse gcc version X, but gcc has macro Y in X. That is not the case with sparse, that is a bug. I don't want to give the user false impression that sparse can set a gcc version and simulate the gcc version specific behavior. It is simpler just put the version specific macro into a header file and ask sparse to include it. You should be able to add that to command line as well. Chris -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, Jul 19, 2017 at 6:07 AM, Christopher Li <sparse@chrisli.org> wrote: > When you specify the gcc version, there is also implicit version > specific behavior > go with it. I can see user file bugs said I give sparse gcc version X, > but gcc has > macro Y in X. That is not the case with sparse, that is a bug. I don't > want to give > the user false impression that sparse can set a gcc version and simulate the gcc > version specific behavior. Makes sense. > It is simpler just put the version specific macro into a header file and ask > sparse to include it. You should be able to add that to command line as well. > > Chris I did not realize that sparse supports -include. It turns out it does, which is even better than specifying three defines. I don't see any references to -D or -include in the sparse manual page. I think they should be documented.
On Wed, Jul 19, 2017 at 1:27 PM, Pavel Roskin <plroskin@gmail.com> wrote: > > I did not realize that sparse supports -include. It turns out it does, > which is even better than specifying three defines. > > I don't see any references to -D or -include in the sparse manual > page. I think they should be documented. It is kind of expected due to usage of cgcc. cgcc expect to be run like gcc but with one extra step of sparse check checking on it. In order to duplicate the gcc behavior on macro, sparse will need to accept most of the gcc preprocessor command line options. As for the document, patch are welcome :-) Chris -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/lib.c b/lib.c index ce66a81..aff6862 100644 --- a/lib.c +++ b/lib.c @@ -24,6 +24,7 @@ */ #include <ctype.h> #include <fcntl.h> +#include <limits.h> #include <stdarg.h> #include <stddef.h> #include <stdio.h> @@ -831,10 +832,54 @@ static char **handle_base_dir(char *arg, char **next) return next; } +static char **handle_gcc_version(char *arg, char **next) +{ + unsigned long gcc_major_ul, gcc_minor_ul = 0, gcc_patchlevel_ul = 0; + char *gcc_version, *p; + + gcc_version = *++next; + if (!gcc_version) + die("missing argument for -gcc-version option"); + + gcc_major_ul = strtoul(gcc_version, &p, 10); + if (gcc_major_ul > INT_MAX) + die("bad gcc major version"); + + if (*p == '\0') + goto good; + else if (*p != '.') + die("bad character after gcc major version"); + + gcc_minor_ul = strtoul(p + 1, &p, 10); + if (gcc_minor_ul > INT_MAX) + die("bad gcc minor version"); + + if (*p == '\0') + goto good; + else if (*p != '.') + die("bad character after gcc minor version"); + + gcc_patchlevel_ul = strtoul(p + 1, &p, 10); + if (gcc_patchlevel_ul > INT_MAX) + die("bad gcc patchlevel version"); + + if (*p != '\0') + die("bad character after gcc patchlevel version"); + +good: + gcc_major = gcc_major_ul; + gcc_minor = gcc_minor_ul; + gcc_patchlevel = gcc_patchlevel_ul; + + return next; +} + static char **handle_switch_g(char *arg, char **next) { if (!strcmp (arg, "gcc-base-dir")) return handle_base_dir(arg, next); + else if (!strcmp (arg, "gcc-version")) + return handle_gcc_version(arg, next); return next; } diff --git a/sparse.1 b/sparse.1 index b79c587..9f2c52d 100644 --- a/sparse.1 +++ b/sparse.1 @@ -355,6 +355,13 @@ Look for system headers in the multiarch subdirectory \fIdir\fR. The \fIdir\fR name would normally take the form of the target's normalized GNU triplet. (e.g. i386-linux-gnu). . +.TP +.B \-gcc-version \fIversion\fR +Simulate behavior of gcc of the specified version. At this time, this +switch only affects macros \fI__GNUC__\fR, \fI__GNUC_MINOR__\fR, and +\fI__GNUC_PATCHLEVEL__\fR. The default value is the version of gcc that +compiled sparse, or \fI2.95.0\fR if that information is missing. +. .SH DEBUG OPTIONS .TP
The option argument is parsed into major, minor and patchlevel versions, which are defined as __GNUC__, __GNUC_MINOR__, and __GNUC_PATCHLEVEL__ in the preprocessor. One possible use is running sparse compiled with the lastest gcc compiler on a Linux kernel that doesn't support that compiler. Signed-off-by: Pavel Roskin <pavel.roskin@virginorbit.com> --- lib.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ sparse.1 | 7 +++++++ 2 files changed, 52 insertions(+) .B \-fdump-linearize[=only]