diff options
Diffstat (limited to 'scripts')
30 files changed, 1310 insertions, 825 deletions
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index c67e73ecd5be..ed2773edfe71 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include | |||
| @@ -149,6 +149,12 @@ ld-option = $(call try-run,\ | |||
| 149 | # $(Q)$(MAKE) $(build)=dir | 149 | # $(Q)$(MAKE) $(build)=dir |
| 150 | build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj | 150 | build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj |
| 151 | 151 | ||
| 152 | ### | ||
| 153 | # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.modbuiltin obj= | ||
| 154 | # Usage: | ||
| 155 | # $(Q)$(MAKE) $(modbuiltin)=dir | ||
| 156 | modbuiltin := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.modbuiltin obj | ||
| 157 | |||
| 152 | # Prefix -I with $(srctree) if it is not an absolute path. | 158 | # Prefix -I with $(srctree) if it is not an absolute path. |
| 153 | # skip if -I has no parameter | 159 | # skip if -I has no parameter |
| 154 | addtree = $(if $(patsubst -I%,%,$(1)), \ | 160 | addtree = $(if $(patsubst -I%,%,$(1)), \ |
diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 341b58902ffc..0b94d2fa3a88 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build | |||
| @@ -207,6 +207,7 @@ endif | |||
| 207 | 207 | ||
| 208 | ifdef CONFIG_FTRACE_MCOUNT_RECORD | 208 | ifdef CONFIG_FTRACE_MCOUNT_RECORD |
| 209 | cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \ | 209 | cmd_record_mcount = set -e ; perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \ |
| 210 | "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \ | ||
| 210 | "$(if $(CONFIG_64BIT),64,32)" \ | 211 | "$(if $(CONFIG_64BIT),64,32)" \ |
| 211 | "$(OBJDUMP)" "$(OBJCOPY)" "$(CC)" "$(LD)" "$(NM)" "$(RM)" "$(MV)" \ | 212 | "$(OBJDUMP)" "$(OBJCOPY)" "$(CC)" "$(LD)" "$(NM)" "$(RM)" "$(MV)" \ |
| 212 | "$(if $(part-of-module),1,0)" "$(@)"; | 213 | "$(if $(part-of-module),1,0)" "$(@)"; |
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index ffdafb26f539..f9bdf264473d 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib | |||
| @@ -127,6 +127,11 @@ _c_flags += $(if $(patsubst n%,, \ | |||
| 127 | $(CFLAGS_GCOV)) | 127 | $(CFLAGS_GCOV)) |
| 128 | endif | 128 | endif |
| 129 | 129 | ||
| 130 | ifdef CONFIG_SYMBOL_PREFIX | ||
| 131 | _cpp_flags += -DSYMBOL_PREFIX=$(patsubst "%",%,$(CONFIG_SYMBOL_PREFIX)) | ||
| 132 | endif | ||
| 133 | |||
| 134 | |||
| 130 | # If building the kernel in a separate objtree expand all occurrences | 135 | # If building the kernel in a separate objtree expand all occurrences |
| 131 | # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/'). | 136 | # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/'). |
| 132 | 137 | ||
| @@ -208,14 +213,19 @@ cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -f -9 > $@) || \ | |||
| 208 | 213 | ||
| 209 | # Bzip2 and LZMA do not include size in file... so we have to fake that; | 214 | # Bzip2 and LZMA do not include size in file... so we have to fake that; |
| 210 | # append the size as a 32-bit littleendian number as gzip does. | 215 | # append the size as a 32-bit littleendian number as gzip does. |
| 211 | size_append = /bin/echo -ne $(shell \ | 216 | size_append = printf $(shell \ |
| 212 | dec_size=0; \ | 217 | dec_size=0; \ |
| 213 | for F in $1; do \ | 218 | for F in $1; do \ |
| 214 | fsize=$$(stat -c "%s" $$F); \ | 219 | fsize=$$(stat -c "%s" $$F); \ |
| 215 | dec_size=$$(expr $$dec_size + $$fsize); \ | 220 | dec_size=$$(expr $$dec_size + $$fsize); \ |
| 216 | done; \ | 221 | done; \ |
| 217 | printf "%08x" $$dec_size | \ | 222 | printf "%08x\n" $$dec_size | \ |
| 218 | sed 's/\(..\)\(..\)\(..\)\(..\)/\\\\x\4\\\\x\3\\\\x\2\\\\x\1/g' \ | 223 | sed 's/\(..\)/\1 /g' | { \ |
| 224 | read ch0 ch1 ch2 ch3; \ | ||
| 225 | for ch in $$ch3 $$ch2 $$ch1 $$ch0; do \ | ||
| 226 | printf '%s%03o' '\\' $$((0x$$ch)); \ | ||
| 227 | done; \ | ||
| 228 | } \ | ||
| 219 | ) | 229 | ) |
| 220 | 230 | ||
| 221 | quiet_cmd_bzip2 = BZIP2 $@ | 231 | quiet_cmd_bzip2 = BZIP2 $@ |
| @@ -230,3 +240,8 @@ quiet_cmd_lzma = LZMA $@ | |||
| 230 | cmd_lzma = (cat $(filter-out FORCE,$^) | \ | 240 | cmd_lzma = (cat $(filter-out FORCE,$^) | \ |
| 231 | lzma -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ | 241 | lzma -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ |
| 232 | (rm -f $@ ; false) | 242 | (rm -f $@ ; false) |
| 243 | |||
| 244 | quiet_cmd_lzo = LZO $@ | ||
| 245 | cmd_lzo = (cat $(filter-out FORCE,$^) | \ | ||
| 246 | lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \ | ||
| 247 | (rm -f $@ ; false) | ||
diff --git a/scripts/Makefile.modbuiltin b/scripts/Makefile.modbuiltin new file mode 100644 index 000000000000..102a276f6eea --- /dev/null +++ b/scripts/Makefile.modbuiltin | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | # ========================================================================== | ||
| 2 | # Generating modules.builtin | ||
| 3 | # ========================================================================== | ||
| 4 | |||
| 5 | src := $(obj) | ||
| 6 | |||
| 7 | PHONY := __modbuiltin | ||
| 8 | __modbuiltin: | ||
| 9 | |||
| 10 | -include include/config/auto.conf | ||
| 11 | # tristate.conf sets tristate variables to uppercase 'Y' or 'M' | ||
| 12 | # That way, we get the list of built-in modules in obj-Y | ||
| 13 | -include include/config/tristate.conf | ||
| 14 | |||
| 15 | include scripts/Kbuild.include | ||
| 16 | |||
| 17 | # The filename Kbuild has precedence over Makefile | ||
| 18 | kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) | ||
| 19 | kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile) | ||
| 20 | include $(kbuild-file) | ||
| 21 | |||
| 22 | include scripts/Makefile.lib | ||
| 23 | __subdir-Y := $(patsubst %/,%,$(filter %/, $(obj-Y))) | ||
| 24 | subdir-Y += $(__subdir-Y) | ||
| 25 | subdir-ym := $(sort $(subdir-y) $(subdir-Y) $(subdir-m)) | ||
| 26 | subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) | ||
| 27 | obj-Y := $(addprefix $(obj)/,$(obj-Y)) | ||
| 28 | |||
| 29 | modbuiltin-subdirs := $(patsubst %,%/modules.builtin, $(subdir-ym)) | ||
| 30 | modbuiltin-mods := $(filter %.ko, $(obj-Y:.o=.ko)) | ||
| 31 | modbuiltin-target := $(obj)/modules.builtin | ||
| 32 | |||
| 33 | __modbuiltin: $(modbuiltin-target) $(subdir-ym) | ||
| 34 | @: | ||
| 35 | |||
| 36 | $(modbuiltin-target): $(subdir-ym) FORCE | ||
| 37 | $(Q)(for m in $(modbuiltin-mods); do echo kernel/$$m; done; \ | ||
| 38 | cat /dev/null $(modbuiltin-subdirs)) > $@ | ||
| 39 | |||
| 40 | PHONY += FORCE | ||
| 41 | |||
| 42 | FORCE: | ||
| 43 | |||
| 44 | # Descending | ||
| 45 | # --------------------------------------------------------------------------- | ||
| 46 | |||
| 47 | PHONY += $(subdir-ym) | ||
| 48 | $(subdir-ym): | ||
| 49 | $(Q)$(MAKE) $(modbuiltin)=$@ | ||
| 50 | |||
| 51 | |||
| 52 | # Declare the contents of the .PHONY variable as phony. We keep that | ||
| 53 | # information in a variable se we can use it in if_changed and friends. | ||
| 54 | |||
| 55 | .PHONY: $(PHONY) | ||
diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 6bf21f83837d..ea26b23de082 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c | |||
| @@ -16,15 +16,15 @@ | |||
| 16 | * tells make when to remake a file. | 16 | * tells make when to remake a file. |
| 17 | * | 17 | * |
| 18 | * To use this list as-is however has the drawback that virtually | 18 | * To use this list as-is however has the drawback that virtually |
| 19 | * every file in the kernel includes <linux/autoconf.h>. | 19 | * every file in the kernel includes autoconf.h. |
| 20 | * | 20 | * |
| 21 | * If the user re-runs make *config, linux/autoconf.h will be | 21 | * If the user re-runs make *config, autoconf.h will be |
| 22 | * regenerated. make notices that and will rebuild every file which | 22 | * regenerated. make notices that and will rebuild every file which |
| 23 | * includes autoconf.h, i.e. basically all files. This is extremely | 23 | * includes autoconf.h, i.e. basically all files. This is extremely |
| 24 | * annoying if the user just changed CONFIG_HIS_DRIVER from n to m. | 24 | * annoying if the user just changed CONFIG_HIS_DRIVER from n to m. |
| 25 | * | 25 | * |
| 26 | * So we play the same trick that "mkdep" played before. We replace | 26 | * So we play the same trick that "mkdep" played before. We replace |
| 27 | * the dependency on linux/autoconf.h by a dependency on every config | 27 | * the dependency on autoconf.h by a dependency on every config |
| 28 | * option which is mentioned in any of the listed prequisites. | 28 | * option which is mentioned in any of the listed prequisites. |
| 29 | * | 29 | * |
| 30 | * kconfig populates a tree in include/config/ with an empty file | 30 | * kconfig populates a tree in include/config/ with an empty file |
| @@ -73,7 +73,7 @@ | |||
| 73 | * cmd_<target> = <cmdline> | 73 | * cmd_<target> = <cmdline> |
| 74 | * | 74 | * |
| 75 | * and then basically copies the .<target>.d file to stdout, in the | 75 | * and then basically copies the .<target>.d file to stdout, in the |
| 76 | * process filtering out the dependency on linux/autoconf.h and adding | 76 | * process filtering out the dependency on autoconf.h and adding |
| 77 | * dependencies on include/config/my/option.h for every | 77 | * dependencies on include/config/my/option.h for every |
| 78 | * CONFIG_MY_OPTION encountered in any of the prequisites. | 78 | * CONFIG_MY_OPTION encountered in any of the prequisites. |
| 79 | * | 79 | * |
| @@ -324,7 +324,7 @@ static void parse_dep_file(void *map, size_t len) | |||
| 324 | p++; | 324 | p++; |
| 325 | } | 325 | } |
| 326 | memcpy(s, m, p-m); s[p-m] = 0; | 326 | memcpy(s, m, p-m); s[p-m] = 0; |
| 327 | if (strrcmp(s, "include/linux/autoconf.h") && | 327 | if (strrcmp(s, "include/generated/autoconf.h") && |
| 328 | strrcmp(s, "arch/um/include/uml-config.h") && | 328 | strrcmp(s, "arch/um/include/uml-config.h") && |
| 329 | strrcmp(s, ".ver")) { | 329 | strrcmp(s, ".ver")) { |
| 330 | printf(" %s \\\n", s); | 330 | printf(" %s \\\n", s); |
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index bc4114f1ab30..3257d3d96767 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | #!/usr/bin/perl -w | 1 | #!/usr/bin/perl -w |
| 2 | # (c) 2001, Dave Jones. <davej@redhat.com> (the file handling bit) | 2 | # (c) 2001, Dave Jones. (the file handling bit) |
| 3 | # (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit) | 3 | # (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit) |
| 4 | # (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite) | 4 | # (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite) |
| 5 | # (c) 2008,2009, Andy Whitcroft <apw@canonical.com> | 5 | # (c) 2008,2009, Andy Whitcroft <apw@canonical.com> |
diff --git a/scripts/genksyms/keywords.c_shipped b/scripts/genksyms/keywords.c_shipped index 287467a2e8c7..8060e06798b3 100644 --- a/scripts/genksyms/keywords.c_shipped +++ b/scripts/genksyms/keywords.c_shipped | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* ANSI-C code produced by gperf version 3.0.3 */ | 1 | /* ANSI-C code produced by gperf version 3.0.4 */ |
| 2 | /* Command-line: gperf -L ANSI-C -a -C -E -g -H is_reserved_hash -k '1,3,$' -N is_reserved_word -p -t scripts/genksyms/keywords.gperf */ | 2 | /* Command-line: gperf -L ANSI-C -a -C -E -g -H is_reserved_hash -k '1,3,$' -N is_reserved_word -p -t scripts/genksyms/keywords.gperf */ |
| 3 | 3 | ||
| 4 | #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ | 4 | #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ |
| @@ -34,7 +34,7 @@ struct resword; | |||
| 34 | static const struct resword *is_reserved_word(register const char *str, register unsigned int len); | 34 | static const struct resword *is_reserved_word(register const char *str, register unsigned int len); |
| 35 | #line 5 "scripts/genksyms/keywords.gperf" | 35 | #line 5 "scripts/genksyms/keywords.gperf" |
| 36 | struct resword { const char *name; int token; }; | 36 | struct resword { const char *name; int token; }; |
| 37 | /* maximum key range = 62, duplicates = 0 */ | 37 | /* maximum key range = 64, duplicates = 0 */ |
| 38 | 38 | ||
| 39 | #ifdef __GNUC__ | 39 | #ifdef __GNUC__ |
| 40 | __inline | 40 | __inline |
| @@ -48,39 +48,39 @@ is_reserved_hash (register const char *str, register unsigned int len) | |||
| 48 | { | 48 | { |
| 49 | static const unsigned char asso_values[] = | 49 | static const unsigned char asso_values[] = |
| 50 | { | 50 | { |
| 51 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 51 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 52 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 52 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 53 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 53 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 54 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 54 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 55 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 55 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 56 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 56 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 57 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 5, | 57 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 0, |
| 58 | 65, 65, 65, 65, 65, 65, 35, 65, 65, 65, | 58 | 67, 67, 67, 67, 67, 67, 15, 67, 67, 67, |
| 59 | 0, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 59 | 0, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 60 | 65, 65, 65, 65, 65, 0, 65, 0, 65, 5, | 60 | 67, 67, 67, 67, 67, 0, 67, 0, 67, 5, |
| 61 | 20, 15, 10, 30, 65, 15, 65, 65, 20, 0, | 61 | 25, 20, 15, 30, 67, 15, 67, 67, 10, 0, |
| 62 | 10, 35, 20, 65, 10, 5, 0, 10, 5, 65, | 62 | 10, 40, 20, 67, 10, 5, 0, 10, 15, 67, |
| 63 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 63 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 64 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 64 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 65 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 65 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 66 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 66 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 67 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 67 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 68 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 68 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 69 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 69 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 70 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 70 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 71 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 71 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 72 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 72 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 73 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 73 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 74 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 74 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 75 | 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | 75 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, |
| 76 | 65, 65, 65, 65, 65, 65 | 76 | 67, 67, 67, 67, 67, 67 |
| 77 | }; | 77 | }; |
| 78 | return len + asso_values[(unsigned char)str[2]] + asso_values[(unsigned char)str[0]] + asso_values[(unsigned char)str[len - 1]]; | 78 | return len + asso_values[(unsigned char)str[2]] + asso_values[(unsigned char)str[0]] + asso_values[(unsigned char)str[len - 1]]; |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | #ifdef __GNUC__ | 81 | #ifdef __GNUC__ |
| 82 | __inline | 82 | __inline |
| 83 | #ifdef __GNUC_STDC_INLINE__ | 83 | #if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__ |
| 84 | __attribute__ ((__gnu_inline__)) | 84 | __attribute__ ((__gnu_inline__)) |
| 85 | #endif | 85 | #endif |
| 86 | #endif | 86 | #endif |
| @@ -89,116 +89,119 @@ is_reserved_word (register const char *str, register unsigned int len) | |||
| 89 | { | 89 | { |
| 90 | enum | 90 | enum |
| 91 | { | 91 | { |
| 92 | TOTAL_KEYWORDS = 43, | 92 | TOTAL_KEYWORDS = 45, |
| 93 | MIN_WORD_LENGTH = 3, | 93 | MIN_WORD_LENGTH = 3, |
| 94 | MAX_WORD_LENGTH = 24, | 94 | MAX_WORD_LENGTH = 24, |
| 95 | MIN_HASH_VALUE = 3, | 95 | MIN_HASH_VALUE = 3, |
| 96 | MAX_HASH_VALUE = 64 | 96 | MAX_HASH_VALUE = 66 |
| 97 | }; | 97 | }; |
| 98 | 98 | ||
| 99 | static const struct resword wordlist[] = | 99 | static const struct resword wordlist[] = |
| 100 | { | 100 | { |
| 101 | {""}, {""}, {""}, | 101 | {""}, {""}, {""}, |
| 102 | #line 28 "scripts/genksyms/keywords.gperf" | 102 | #line 30 "scripts/genksyms/keywords.gperf" |
| 103 | {"asm", ASM_KEYW}, | 103 | {"asm", ASM_KEYW}, |
| 104 | {""}, | 104 | {""}, |
| 105 | #line 10 "scripts/genksyms/keywords.gperf" | 105 | #line 12 "scripts/genksyms/keywords.gperf" |
| 106 | {"__asm", ASM_KEYW}, | 106 | {"__asm", ASM_KEYW}, |
| 107 | {""}, | 107 | {""}, |
| 108 | #line 11 "scripts/genksyms/keywords.gperf" | 108 | #line 13 "scripts/genksyms/keywords.gperf" |
| 109 | {"__asm__", ASM_KEYW}, | 109 | {"__asm__", ASM_KEYW}, |
| 110 | {""}, {""}, | 110 | {""}, {""}, |
| 111 | #line 54 "scripts/genksyms/keywords.gperf" | 111 | #line 56 "scripts/genksyms/keywords.gperf" |
| 112 | {"__typeof__", TYPEOF_KEYW}, | 112 | {"__typeof__", TYPEOF_KEYW}, |
| 113 | {""}, | 113 | {""}, |
| 114 | #line 14 "scripts/genksyms/keywords.gperf" | 114 | #line 16 "scripts/genksyms/keywords.gperf" |
| 115 | {"__const", CONST_KEYW}, | 115 | {"__const", CONST_KEYW}, |
| 116 | #line 13 "scripts/genksyms/keywords.gperf" | ||
| 117 | {"__attribute__", ATTRIBUTE_KEYW}, | ||
| 118 | #line 15 "scripts/genksyms/keywords.gperf" | 116 | #line 15 "scripts/genksyms/keywords.gperf" |
| 117 | {"__attribute__", ATTRIBUTE_KEYW}, | ||
| 118 | #line 17 "scripts/genksyms/keywords.gperf" | ||
| 119 | {"__const__", CONST_KEYW}, | 119 | {"__const__", CONST_KEYW}, |
| 120 | #line 20 "scripts/genksyms/keywords.gperf" | 120 | #line 22 "scripts/genksyms/keywords.gperf" |
| 121 | {"__signed__", SIGNED_KEYW}, | 121 | {"__signed__", SIGNED_KEYW}, |
| 122 | #line 46 "scripts/genksyms/keywords.gperf" | 122 | #line 48 "scripts/genksyms/keywords.gperf" |
| 123 | {"static", STATIC_KEYW}, | 123 | {"static", STATIC_KEYW}, |
| 124 | #line 22 "scripts/genksyms/keywords.gperf" | 124 | {""}, |
| 125 | {"__volatile__", VOLATILE_KEYW}, | 125 | #line 43 "scripts/genksyms/keywords.gperf" |
| 126 | #line 41 "scripts/genksyms/keywords.gperf" | ||
| 127 | {"int", INT_KEYW}, | 126 | {"int", INT_KEYW}, |
| 128 | #line 34 "scripts/genksyms/keywords.gperf" | 127 | #line 36 "scripts/genksyms/keywords.gperf" |
| 129 | {"char", CHAR_KEYW}, | 128 | {"char", CHAR_KEYW}, |
| 130 | #line 35 "scripts/genksyms/keywords.gperf" | 129 | #line 37 "scripts/genksyms/keywords.gperf" |
| 131 | {"const", CONST_KEYW}, | 130 | {"const", CONST_KEYW}, |
| 132 | #line 47 "scripts/genksyms/keywords.gperf" | 131 | #line 49 "scripts/genksyms/keywords.gperf" |
| 133 | {"struct", STRUCT_KEYW}, | 132 | {"struct", STRUCT_KEYW}, |
| 134 | #line 26 "scripts/genksyms/keywords.gperf" | 133 | #line 28 "scripts/genksyms/keywords.gperf" |
| 135 | {"__restrict__", RESTRICT_KEYW}, | 134 | {"__restrict__", RESTRICT_KEYW}, |
| 136 | #line 27 "scripts/genksyms/keywords.gperf" | 135 | #line 29 "scripts/genksyms/keywords.gperf" |
| 137 | {"restrict", RESTRICT_KEYW}, | 136 | {"restrict", RESTRICT_KEYW}, |
| 138 | #line 25 "scripts/genksyms/keywords.gperf" | 137 | #line 9 "scripts/genksyms/keywords.gperf" |
| 139 | {"_restrict", RESTRICT_KEYW}, | 138 | {"EXPORT_SYMBOL_GPL_FUTURE", EXPORT_SYMBOL_KEYW}, |
| 140 | #line 18 "scripts/genksyms/keywords.gperf" | 139 | #line 20 "scripts/genksyms/keywords.gperf" |
| 141 | {"__inline__", INLINE_KEYW}, | 140 | {"__inline__", INLINE_KEYW}, |
| 142 | #line 12 "scripts/genksyms/keywords.gperf" | ||
| 143 | {"__attribute", ATTRIBUTE_KEYW}, | ||
| 144 | {""}, | 141 | {""}, |
| 145 | #line 16 "scripts/genksyms/keywords.gperf" | 142 | #line 24 "scripts/genksyms/keywords.gperf" |
| 143 | {"__volatile__", VOLATILE_KEYW}, | ||
| 144 | #line 7 "scripts/genksyms/keywords.gperf" | ||
| 145 | {"EXPORT_SYMBOL", EXPORT_SYMBOL_KEYW}, | ||
| 146 | #line 27 "scripts/genksyms/keywords.gperf" | ||
| 147 | {"_restrict", RESTRICT_KEYW}, | ||
| 148 | {""}, | ||
| 149 | #line 14 "scripts/genksyms/keywords.gperf" | ||
| 150 | {"__attribute", ATTRIBUTE_KEYW}, | ||
| 151 | #line 8 "scripts/genksyms/keywords.gperf" | ||
| 152 | {"EXPORT_SYMBOL_GPL", EXPORT_SYMBOL_KEYW}, | ||
| 153 | #line 18 "scripts/genksyms/keywords.gperf" | ||
| 146 | {"__extension__", EXTENSION_KEYW}, | 154 | {"__extension__", EXTENSION_KEYW}, |
| 147 | #line 37 "scripts/genksyms/keywords.gperf" | 155 | #line 39 "scripts/genksyms/keywords.gperf" |
| 148 | {"enum", ENUM_KEYW}, | 156 | {"enum", ENUM_KEYW}, |
| 149 | #line 21 "scripts/genksyms/keywords.gperf" | 157 | #line 10 "scripts/genksyms/keywords.gperf" |
| 150 | {"__volatile", VOLATILE_KEYW}, | 158 | {"EXPORT_UNUSED_SYMBOL", EXPORT_SYMBOL_KEYW}, |
| 151 | #line 38 "scripts/genksyms/keywords.gperf" | 159 | #line 40 "scripts/genksyms/keywords.gperf" |
| 152 | {"extern", EXTERN_KEYW}, | 160 | {"extern", EXTERN_KEYW}, |
| 153 | {""}, | 161 | {""}, |
| 154 | #line 19 "scripts/genksyms/keywords.gperf" | 162 | #line 21 "scripts/genksyms/keywords.gperf" |
| 155 | {"__signed", SIGNED_KEYW}, | 163 | {"__signed", SIGNED_KEYW}, |
| 156 | #line 9 "scripts/genksyms/keywords.gperf" | 164 | #line 11 "scripts/genksyms/keywords.gperf" |
| 157 | {"EXPORT_SYMBOL_GPL_FUTURE", EXPORT_SYMBOL_KEYW}, | 165 | {"EXPORT_UNUSED_SYMBOL_GPL", EXPORT_SYMBOL_KEYW}, |
| 158 | {""}, | 166 | #line 51 "scripts/genksyms/keywords.gperf" |
| 159 | #line 53 "scripts/genksyms/keywords.gperf" | 167 | {"union", UNION_KEYW}, |
| 168 | #line 55 "scripts/genksyms/keywords.gperf" | ||
| 160 | {"typeof", TYPEOF_KEYW}, | 169 | {"typeof", TYPEOF_KEYW}, |
| 161 | #line 48 "scripts/genksyms/keywords.gperf" | 170 | #line 50 "scripts/genksyms/keywords.gperf" |
| 162 | {"typedef", TYPEDEF_KEYW}, | 171 | {"typedef", TYPEDEF_KEYW}, |
| 163 | #line 17 "scripts/genksyms/keywords.gperf" | 172 | #line 19 "scripts/genksyms/keywords.gperf" |
| 164 | {"__inline", INLINE_KEYW}, | 173 | {"__inline", INLINE_KEYW}, |
| 165 | #line 33 "scripts/genksyms/keywords.gperf" | 174 | #line 35 "scripts/genksyms/keywords.gperf" |
| 166 | {"auto", AUTO_KEYW}, | 175 | {"auto", AUTO_KEYW}, |
| 167 | #line 49 "scripts/genksyms/keywords.gperf" | 176 | #line 23 "scripts/genksyms/keywords.gperf" |
| 168 | {"union", UNION_KEYW}, | 177 | {"__volatile", VOLATILE_KEYW}, |
| 169 | {""}, {""}, | ||
| 170 | #line 50 "scripts/genksyms/keywords.gperf" | ||
| 171 | {"unsigned", UNSIGNED_KEYW}, | ||
| 172 | #line 51 "scripts/genksyms/keywords.gperf" | ||
| 173 | {"void", VOID_KEYW}, | ||
| 174 | #line 44 "scripts/genksyms/keywords.gperf" | ||
| 175 | {"short", SHORT_KEYW}, | ||
| 176 | {""}, {""}, | 178 | {""}, {""}, |
| 177 | #line 52 "scripts/genksyms/keywords.gperf" | 179 | #line 52 "scripts/genksyms/keywords.gperf" |
| 178 | {"volatile", VOLATILE_KEYW}, | 180 | {"unsigned", UNSIGNED_KEYW}, |
| 179 | {""}, | ||
| 180 | #line 39 "scripts/genksyms/keywords.gperf" | ||
| 181 | {"float", FLOAT_KEYW}, | ||
| 182 | #line 36 "scripts/genksyms/keywords.gperf" | ||
| 183 | {"double", DOUBLE_KEYW}, | ||
| 184 | {""}, | 181 | {""}, |
| 185 | #line 7 "scripts/genksyms/keywords.gperf" | 182 | #line 46 "scripts/genksyms/keywords.gperf" |
| 186 | {"EXPORT_SYMBOL", EXPORT_SYMBOL_KEYW}, | 183 | {"short", SHORT_KEYW}, |
| 187 | {""}, {""}, | 184 | #line 42 "scripts/genksyms/keywords.gperf" |
| 188 | #line 40 "scripts/genksyms/keywords.gperf" | ||
| 189 | {"inline", INLINE_KEYW}, | 185 | {"inline", INLINE_KEYW}, |
| 190 | #line 8 "scripts/genksyms/keywords.gperf" | ||
| 191 | {"EXPORT_SYMBOL_GPL", EXPORT_SYMBOL_KEYW}, | ||
| 192 | #line 43 "scripts/genksyms/keywords.gperf" | ||
| 193 | {"register", REGISTER_KEYW}, | ||
| 194 | {""}, | 186 | {""}, |
| 195 | #line 24 "scripts/genksyms/keywords.gperf" | 187 | #line 54 "scripts/genksyms/keywords.gperf" |
| 188 | {"volatile", VOLATILE_KEYW}, | ||
| 189 | #line 44 "scripts/genksyms/keywords.gperf" | ||
| 190 | {"long", LONG_KEYW}, | ||
| 191 | #line 26 "scripts/genksyms/keywords.gperf" | ||
| 196 | {"_Bool", BOOL_KEYW}, | 192 | {"_Bool", BOOL_KEYW}, |
| 197 | #line 45 "scripts/genksyms/keywords.gperf" | ||
| 198 | {"signed", SIGNED_KEYW}, | ||
| 199 | {""}, {""}, | 193 | {""}, {""}, |
| 200 | #line 42 "scripts/genksyms/keywords.gperf" | 194 | #line 45 "scripts/genksyms/keywords.gperf" |
| 201 | {"long", LONG_KEYW} | 195 | {"register", REGISTER_KEYW}, |
| 196 | #line 53 "scripts/genksyms/keywords.gperf" | ||
| 197 | {"void", VOID_KEYW}, | ||
| 198 | #line 41 "scripts/genksyms/keywords.gperf" | ||
| 199 | {"float", FLOAT_KEYW}, | ||
| 200 | #line 38 "scripts/genksyms/keywords.gperf" | ||
| 201 | {"double", DOUBLE_KEYW}, | ||
| 202 | {""}, {""}, {""}, {""}, | ||
| 203 | #line 47 "scripts/genksyms/keywords.gperf" | ||
| 204 | {"signed", SIGNED_KEYW} | ||
| 202 | }; | 205 | }; |
| 203 | 206 | ||
| 204 | if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) | 207 | if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) |
diff --git a/scripts/genksyms/keywords.gperf b/scripts/genksyms/keywords.gperf index 8fe977a4d57b..e6349acb6f2f 100644 --- a/scripts/genksyms/keywords.gperf +++ b/scripts/genksyms/keywords.gperf | |||
| @@ -7,6 +7,8 @@ struct resword { const char *name; int token; } | |||
| 7 | EXPORT_SYMBOL, EXPORT_SYMBOL_KEYW | 7 | EXPORT_SYMBOL, EXPORT_SYMBOL_KEYW |
| 8 | EXPORT_SYMBOL_GPL, EXPORT_SYMBOL_KEYW | 8 | EXPORT_SYMBOL_GPL, EXPORT_SYMBOL_KEYW |
| 9 | EXPORT_SYMBOL_GPL_FUTURE, EXPORT_SYMBOL_KEYW | 9 | EXPORT_SYMBOL_GPL_FUTURE, EXPORT_SYMBOL_KEYW |
| 10 | EXPORT_UNUSED_SYMBOL, EXPORT_SYMBOL_KEYW | ||
| 11 | EXPORT_UNUSED_SYMBOL_GPL, EXPORT_SYMBOL_KEYW | ||
| 10 | __asm, ASM_KEYW | 12 | __asm, ASM_KEYW |
| 11 | __asm__, ASM_KEYW | 13 | __asm__, ASM_KEYW |
| 12 | __attribute, ATTRIBUTE_KEYW | 14 | __attribute, ATTRIBUTE_KEYW |
diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl index 81a67a458e78..090f24839700 100755 --- a/scripts/get_maintainer.pl +++ b/scripts/get_maintainer.pl | |||
| @@ -13,7 +13,7 @@ | |||
| 13 | use strict; | 13 | use strict; |
| 14 | 14 | ||
| 15 | my $P = $0; | 15 | my $P = $0; |
| 16 | my $V = '0.21'; | 16 | my $V = '0.23'; |
| 17 | 17 | ||
| 18 | use Getopt::Long qw(:config no_auto_abbrev); | 18 | use Getopt::Long qw(:config no_auto_abbrev); |
| 19 | 19 | ||
| @@ -23,16 +23,19 @@ my $email_usename = 1; | |||
| 23 | my $email_maintainer = 1; | 23 | my $email_maintainer = 1; |
| 24 | my $email_list = 1; | 24 | my $email_list = 1; |
| 25 | my $email_subscriber_list = 0; | 25 | my $email_subscriber_list = 0; |
| 26 | my $email_git = 1; | ||
| 27 | my $email_git_penguin_chiefs = 0; | 26 | my $email_git_penguin_chiefs = 0; |
| 27 | my $email_git = 1; | ||
| 28 | my $email_git_blame = 0; | ||
| 28 | my $email_git_min_signatures = 1; | 29 | my $email_git_min_signatures = 1; |
| 29 | my $email_git_max_maintainers = 5; | 30 | my $email_git_max_maintainers = 5; |
| 30 | my $email_git_min_percent = 5; | 31 | my $email_git_min_percent = 5; |
| 31 | my $email_git_since = "1-year-ago"; | 32 | my $email_git_since = "1-year-ago"; |
| 32 | my $email_git_blame = 0; | 33 | my $email_hg_since = "-365"; |
| 33 | my $email_remove_duplicates = 1; | 34 | my $email_remove_duplicates = 1; |
| 34 | my $output_multiline = 1; | 35 | my $output_multiline = 1; |
| 35 | my $output_separator = ", "; | 36 | my $output_separator = ", "; |
| 37 | my $output_roles = 0; | ||
| 38 | my $output_rolestats = 0; | ||
| 36 | my $scm = 0; | 39 | my $scm = 0; |
| 37 | my $web = 0; | 40 | my $web = 0; |
| 38 | my $subsystem = 0; | 41 | my $subsystem = 0; |
| @@ -64,21 +67,52 @@ my $penguin_chiefs = "\(" . join("|",@penguin_chief_names) . "\)"; | |||
| 64 | my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])"; | 67 | my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])"; |
| 65 | my $rfc822_char = '[\\000-\\377]'; | 68 | my $rfc822_char = '[\\000-\\377]'; |
| 66 | 69 | ||
| 70 | # VCS command support: class-like functions and strings | ||
| 71 | |||
| 72 | my %VCS_cmds; | ||
| 73 | |||
| 74 | my %VCS_cmds_git = ( | ||
| 75 | "execute_cmd" => \&git_execute_cmd, | ||
| 76 | "available" => '(which("git") ne "") && (-d ".git")', | ||
| 77 | "find_signers_cmd" => "git log --since=\$email_git_since -- \$file", | ||
| 78 | "find_commit_signers_cmd" => "git log -1 \$commit", | ||
| 79 | "blame_range_cmd" => "git blame -l -L \$diff_start,+\$diff_length \$file", | ||
| 80 | "blame_file_cmd" => "git blame -l \$file", | ||
| 81 | "commit_pattern" => "^commit [0-9a-f]{40,40}", | ||
| 82 | "blame_commit_pattern" => "^([0-9a-f]+) " | ||
| 83 | ); | ||
| 84 | |||
| 85 | my %VCS_cmds_hg = ( | ||
| 86 | "execute_cmd" => \&hg_execute_cmd, | ||
| 87 | "available" => '(which("hg") ne "") && (-d ".hg")', | ||
| 88 | "find_signers_cmd" => | ||
| 89 | "hg log --date=\$email_hg_since" . | ||
| 90 | " --template='commit {node}\\n{desc}\\n' -- \$file", | ||
| 91 | "find_commit_signers_cmd" => "hg log --template='{desc}\\n' -r \$commit", | ||
| 92 | "blame_range_cmd" => "", # not supported | ||
| 93 | "blame_file_cmd" => "hg blame -c \$file", | ||
| 94 | "commit_pattern" => "^commit [0-9a-f]{40,40}", | ||
| 95 | "blame_commit_pattern" => "^([0-9a-f]+):" | ||
| 96 | ); | ||
| 97 | |||
| 67 | if (!GetOptions( | 98 | if (!GetOptions( |
| 68 | 'email!' => \$email, | 99 | 'email!' => \$email, |
| 69 | 'git!' => \$email_git, | 100 | 'git!' => \$email_git, |
| 101 | 'git-blame!' => \$email_git_blame, | ||
| 70 | 'git-chief-penguins!' => \$email_git_penguin_chiefs, | 102 | 'git-chief-penguins!' => \$email_git_penguin_chiefs, |
| 71 | 'git-min-signatures=i' => \$email_git_min_signatures, | 103 | 'git-min-signatures=i' => \$email_git_min_signatures, |
| 72 | 'git-max-maintainers=i' => \$email_git_max_maintainers, | 104 | 'git-max-maintainers=i' => \$email_git_max_maintainers, |
| 73 | 'git-min-percent=i' => \$email_git_min_percent, | 105 | 'git-min-percent=i' => \$email_git_min_percent, |
| 74 | 'git-since=s' => \$email_git_since, | 106 | 'git-since=s' => \$email_git_since, |
| 75 | 'git-blame!' => \$email_git_blame, | 107 | 'hg-since=s' => \$email_hg_since, |
| 76 | 'remove-duplicates!' => \$email_remove_duplicates, | 108 | 'remove-duplicates!' => \$email_remove_duplicates, |
| 77 | 'm!' => \$email_maintainer, | 109 | 'm!' => \$email_maintainer, |
| 78 | 'n!' => \$email_usename, | 110 | 'n!' => \$email_usename, |
| 79 | 'l!' => \$email_list, | 111 | 'l!' => \$email_list, |
| 80 | 's!' => \$email_subscriber_list, | 112 | 's!' => \$email_subscriber_list, |
| 81 | 'multiline!' => \$output_multiline, | 113 | 'multiline!' => \$output_multiline, |
| 114 | 'roles!' => \$output_roles, | ||
| 115 | 'rolestats!' => \$output_rolestats, | ||
| 82 | 'separator=s' => \$output_separator, | 116 | 'separator=s' => \$output_separator, |
| 83 | 'subsystem!' => \$subsystem, | 117 | 'subsystem!' => \$subsystem, |
| 84 | 'status!' => \$status, | 118 | 'status!' => \$status, |
| @@ -90,8 +124,7 @@ if (!GetOptions( | |||
| 90 | 'v|version' => \$version, | 124 | 'v|version' => \$version, |
| 91 | 'h|help' => \$help, | 125 | 'h|help' => \$help, |
| 92 | )) { | 126 | )) { |
| 93 | usage(); | 127 | die "$P: invalid argument - use --help if necessary\n"; |
| 94 | die "$P: invalid argument\n"; | ||
| 95 | } | 128 | } |
| 96 | 129 | ||
| 97 | if ($help != 0) { | 130 | if ($help != 0) { |
| @@ -113,6 +146,10 @@ if ($output_separator ne ", ") { | |||
| 113 | $output_multiline = 0; | 146 | $output_multiline = 0; |
| 114 | } | 147 | } |
| 115 | 148 | ||
| 149 | if ($output_rolestats) { | ||
| 150 | $output_roles = 1; | ||
| 151 | } | ||
| 152 | |||
| 116 | my $selections = $email + $scm + $status + $subsystem + $web; | 153 | my $selections = $email + $scm + $status + $subsystem + $web; |
| 117 | if ($selections == 0) { | 154 | if ($selections == 0) { |
| 118 | usage(); | 155 | usage(); |
| @@ -175,7 +212,7 @@ if ($email_remove_duplicates) { | |||
| 175 | next if ($line =~ m/^\s*$/); | 212 | next if ($line =~ m/^\s*$/); |
| 176 | 213 | ||
| 177 | my ($name, $address) = parse_email($line); | 214 | my ($name, $address) = parse_email($line); |
| 178 | $line = format_email($name, $address); | 215 | $line = format_email($name, $address, $email_usename); |
| 179 | 216 | ||
| 180 | next if ($line =~ m/^\s*$/); | 217 | next if ($line =~ m/^\s*$/); |
| 181 | 218 | ||
| @@ -207,12 +244,10 @@ foreach my $file (@ARGV) { | |||
| 207 | push(@files, $file); | 244 | push(@files, $file); |
| 208 | if (-f $file && $keywords) { | 245 | if (-f $file && $keywords) { |
| 209 | open(FILE, "<$file") or die "$P: Can't open ${file}\n"; | 246 | open(FILE, "<$file") or die "$P: Can't open ${file}\n"; |
| 210 | while (<FILE>) { | 247 | my $text = do { local($/) ; <FILE> }; |
| 211 | my $patch_line = $_; | 248 | foreach my $line (keys %keyword_hash) { |
| 212 | foreach my $line (keys %keyword_hash) { | 249 | if ($text =~ m/$keyword_hash{$line}/x) { |
| 213 | if ($patch_line =~ m/^.*$keyword_hash{$line}/x) { | 250 | push(@keyword_tvi, $line); |
| 214 | push(@keyword_tvi, $line); | ||
| 215 | } | ||
| 216 | } | 251 | } |
| 217 | } | 252 | } |
| 218 | close(FILE); | 253 | close(FILE); |
| @@ -261,54 +296,64 @@ my @status = (); | |||
| 261 | 296 | ||
| 262 | foreach my $file (@files) { | 297 | foreach my $file (@files) { |
| 263 | 298 | ||
| 264 | #Do not match excluded file patterns | 299 | my %hash; |
| 265 | 300 | my $tvi = find_first_section(); | |
| 266 | my $exclude = 0; | 301 | while ($tvi < @typevalue) { |
| 267 | foreach my $line (@typevalue) { | 302 | my $start = find_starting_index($tvi); |
| 268 | if ($line =~ m/^(\C):\s*(.*)/) { | 303 | my $end = find_ending_index($tvi); |
| 269 | my $type = $1; | 304 | my $exclude = 0; |
| 270 | my $value = $2; | 305 | my $i; |
| 271 | if ($type eq 'X') { | ||
| 272 | if (file_match_pattern($file, $value)) { | ||
| 273 | $exclude = 1; | ||
| 274 | last; | ||
| 275 | } | ||
| 276 | } | ||
| 277 | } | ||
| 278 | } | ||
| 279 | 306 | ||
| 280 | if (!$exclude) { | 307 | #Do not match excluded file patterns |
| 281 | my $tvi = 0; | 308 | |
| 282 | my %hash; | 309 | for ($i = $start; $i < $end; $i++) { |
| 283 | foreach my $line (@typevalue) { | 310 | my $line = $typevalue[$i]; |
| 284 | if ($line =~ m/^(\C):\s*(.*)/) { | 311 | if ($line =~ m/^(\C):\s*(.*)/) { |
| 285 | my $type = $1; | 312 | my $type = $1; |
| 286 | my $value = $2; | 313 | my $value = $2; |
| 287 | if ($type eq 'F') { | 314 | if ($type eq 'X') { |
| 288 | if (file_match_pattern($file, $value)) { | 315 | if (file_match_pattern($file, $value)) { |
| 289 | my $value_pd = ($value =~ tr@/@@); | 316 | $exclude = 1; |
| 290 | my $file_pd = ($file =~ tr@/@@); | ||
| 291 | $value_pd++ if (substr($value,-1,1) ne "/"); | ||
| 292 | if ($pattern_depth == 0 || | ||
| 293 | (($file_pd - $value_pd) < $pattern_depth)) { | ||
| 294 | $hash{$tvi} = $value_pd; | ||
| 295 | } | ||
| 296 | } | 317 | } |
| 297 | } | 318 | } |
| 298 | } | 319 | } |
| 299 | $tvi++; | ||
| 300 | } | 320 | } |
| 301 | foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) { | 321 | |
| 302 | add_categories($line); | 322 | if (!$exclude) { |
| 323 | for ($i = $start; $i < $end; $i++) { | ||
| 324 | my $line = $typevalue[$i]; | ||
| 325 | if ($line =~ m/^(\C):\s*(.*)/) { | ||
| 326 | my $type = $1; | ||
| 327 | my $value = $2; | ||
| 328 | if ($type eq 'F') { | ||
| 329 | if (file_match_pattern($file, $value)) { | ||
| 330 | my $value_pd = ($value =~ tr@/@@); | ||
| 331 | my $file_pd = ($file =~ tr@/@@); | ||
| 332 | $value_pd++ if (substr($value,-1,1) ne "/"); | ||
| 333 | if ($pattern_depth == 0 || | ||
| 334 | (($file_pd - $value_pd) < $pattern_depth)) { | ||
| 335 | $hash{$tvi} = $value_pd; | ||
| 336 | } | ||
| 337 | } | ||
| 338 | } | ||
| 339 | } | ||
| 340 | } | ||
| 303 | } | 341 | } |
| 342 | |||
| 343 | $tvi += ($end - $start); | ||
| 344 | |||
| 345 | } | ||
| 346 | |||
| 347 | foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) { | ||
| 348 | add_categories($line); | ||
| 304 | } | 349 | } |
| 305 | 350 | ||
| 306 | if ($email && $email_git) { | 351 | if ($email && $email_git) { |
| 307 | recent_git_signoffs($file); | 352 | vcs_file_signoffs($file); |
| 308 | } | 353 | } |
| 309 | 354 | ||
| 310 | if ($email && $email_git_blame) { | 355 | if ($email && $email_git_blame) { |
| 311 | git_assign_blame($file); | 356 | vcs_file_blame($file); |
| 312 | } | 357 | } |
| 313 | } | 358 | } |
| 314 | 359 | ||
| @@ -324,11 +369,11 @@ if ($email) { | |||
| 324 | if ($chief =~ m/^(.*):(.*)/) { | 369 | if ($chief =~ m/^(.*):(.*)/) { |
| 325 | my $email_address; | 370 | my $email_address; |
| 326 | 371 | ||
| 327 | $email_address = format_email($1, $2); | 372 | $email_address = format_email($1, $2, $email_usename); |
| 328 | if ($email_git_penguin_chiefs) { | 373 | if ($email_git_penguin_chiefs) { |
| 329 | push(@email_to, $email_address); | 374 | push(@email_to, [$email_address, 'chief penguin']); |
| 330 | } else { | 375 | } else { |
| 331 | @email_to = grep(!/${email_address}/, @email_to); | 376 | @email_to = grep($_->[0] !~ /${email_address}/, @email_to); |
| 332 | } | 377 | } |
| 333 | } | 378 | } |
| 334 | } | 379 | } |
| @@ -342,7 +387,7 @@ if ($email || $email_list) { | |||
| 342 | if ($email_list) { | 387 | if ($email_list) { |
| 343 | @to = (@to, @list_to); | 388 | @to = (@to, @list_to); |
| 344 | } | 389 | } |
| 345 | output(uniq(@to)); | 390 | output(merge_email(@to)); |
| 346 | } | 391 | } |
| 347 | 392 | ||
| 348 | if ($scm) { | 393 | if ($scm) { |
| @@ -398,13 +443,16 @@ MAINTAINER field selection options: | |||
| 398 | --git-min-signatures => number of signatures required (default: 1) | 443 | --git-min-signatures => number of signatures required (default: 1) |
| 399 | --git-max-maintainers => maximum maintainers to add (default: 5) | 444 | --git-max-maintainers => maximum maintainers to add (default: 5) |
| 400 | --git-min-percent => minimum percentage of commits required (default: 5) | 445 | --git-min-percent => minimum percentage of commits required (default: 5) |
| 401 | --git-since => git history to use (default: 1-year-ago) | ||
| 402 | --git-blame => use git blame to find modified commits for patch or file | 446 | --git-blame => use git blame to find modified commits for patch or file |
| 447 | --git-since => git history to use (default: 1-year-ago) | ||
| 448 | --hg-since => hg history to use (default: -365) | ||
| 403 | --m => include maintainer(s) if any | 449 | --m => include maintainer(s) if any |
| 404 | --n => include name 'Full Name <addr\@domain.tld>' | 450 | --n => include name 'Full Name <addr\@domain.tld>' |
| 405 | --l => include list(s) if any | 451 | --l => include list(s) if any |
| 406 | --s => include subscriber only list(s) if any | 452 | --s => include subscriber only list(s) if any |
| 407 | --remove-duplicates => minimize duplicate email names/addresses | 453 | --remove-duplicates => minimize duplicate email names/addresses |
| 454 | --roles => show roles (status:subsystem, git-signer, list, etc...) | ||
| 455 | --rolestats => show roles and statistics (commits/total_commits, %) | ||
| 408 | --scm => print SCM tree(s) if any | 456 | --scm => print SCM tree(s) if any |
| 409 | --status => print status if any | 457 | --status => print status if any |
| 410 | --subsystem => print subsystem name if any | 458 | --subsystem => print subsystem name if any |
| @@ -430,11 +478,24 @@ Notes: | |||
| 430 | directory are examined as git recurses directories. | 478 | directory are examined as git recurses directories. |
| 431 | Any specified X: (exclude) pattern matches are _not_ ignored. | 479 | Any specified X: (exclude) pattern matches are _not_ ignored. |
| 432 | Used with "--nogit", directory is used as a pattern match, | 480 | Used with "--nogit", directory is used as a pattern match, |
| 433 | no individual file within the directory or subdirectory | 481 | no individual file within the directory or subdirectory |
| 434 | is matched. | 482 | is matched. |
| 435 | Used with "--git-blame", does not iterate all files in directory | 483 | Used with "--git-blame", does not iterate all files in directory |
| 436 | Using "--git-blame" is slow and may add old committers and authors | 484 | Using "--git-blame" is slow and may add old committers and authors |
| 437 | that are no longer active maintainers to the output. | 485 | that are no longer active maintainers to the output. |
| 486 | Using "--roles" or "--rolestats" with git send-email --cc-cmd or any | ||
| 487 | other automated tools that expect only ["name"] <email address> | ||
| 488 | may not work because of additional output after <email address>. | ||
| 489 | Using "--rolestats" and "--git-blame" shows the #/total=% commits, | ||
| 490 | not the percentage of the entire file authored. # of commits is | ||
| 491 | not a good measure of amount of code authored. 1 major commit may | ||
| 492 | contain a thousand lines, 5 trivial commits may modify a single line. | ||
| 493 | If git is not installed, but mercurial (hg) is installed and an .hg | ||
| 494 | repository exists, the following options apply to mercurial: | ||
| 495 | --git, | ||
| 496 | --git-min-signatures, --git-max-maintainers, --git-min-percent, and | ||
| 497 | --git-blame | ||
| 498 | Use --hg-since not --git-since to control date selection | ||
| 438 | EOT | 499 | EOT |
| 439 | } | 500 | } |
| 440 | 501 | ||
| @@ -493,7 +554,7 @@ sub parse_email { | |||
| 493 | } | 554 | } |
| 494 | 555 | ||
| 495 | sub format_email { | 556 | sub format_email { |
| 496 | my ($name, $address) = @_; | 557 | my ($name, $address, $usename) = @_; |
| 497 | 558 | ||
| 498 | my $formatted_email; | 559 | my $formatted_email; |
| 499 | 560 | ||
| @@ -506,11 +567,11 @@ sub format_email { | |||
| 506 | $name = "\"$name\""; | 567 | $name = "\"$name\""; |
| 507 | } | 568 | } |
| 508 | 569 | ||
| 509 | if ($email_usename) { | 570 | if ($usename) { |
| 510 | if ("$name" eq "") { | 571 | if ("$name" eq "") { |
| 511 | $formatted_email = "$address"; | 572 | $formatted_email = "$address"; |
| 512 | } else { | 573 | } else { |
| 513 | $formatted_email = "$name <${address}>"; | 574 | $formatted_email = "$name <$address>"; |
| 514 | } | 575 | } |
| 515 | } else { | 576 | } else { |
| 516 | $formatted_email = $address; | 577 | $formatted_email = $address; |
| @@ -519,6 +580,20 @@ sub format_email { | |||
| 519 | return $formatted_email; | 580 | return $formatted_email; |
| 520 | } | 581 | } |
| 521 | 582 | ||
| 583 | sub find_first_section { | ||
| 584 | my $index = 0; | ||
| 585 | |||
| 586 | while ($index < @typevalue) { | ||
| 587 | my $tv = $typevalue[$index]; | ||
| 588 | if (($tv =~ m/^(\C):\s*(.*)/)) { | ||
| 589 | last; | ||
| 590 | } | ||
| 591 | $index++; | ||
| 592 | } | ||
| 593 | |||
| 594 | return $index; | ||
| 595 | } | ||
| 596 | |||
| 522 | sub find_starting_index { | 597 | sub find_starting_index { |
| 523 | my ($index) = @_; | 598 | my ($index) = @_; |
| 524 | 599 | ||
| @@ -547,6 +622,71 @@ sub find_ending_index { | |||
| 547 | return $index; | 622 | return $index; |
| 548 | } | 623 | } |
| 549 | 624 | ||
| 625 | sub get_maintainer_role { | ||
| 626 | my ($index) = @_; | ||
| 627 | |||
| 628 | my $i; | ||
| 629 | my $start = find_starting_index($index); | ||
| 630 | my $end = find_ending_index($index); | ||
| 631 | |||
| 632 | my $role; | ||
| 633 | my $subsystem = $typevalue[$start]; | ||
| 634 | if (length($subsystem) > 20) { | ||
| 635 | $subsystem = substr($subsystem, 0, 17); | ||
| 636 | $subsystem =~ s/\s*$//; | ||
| 637 | $subsystem = $subsystem . "..."; | ||
| 638 | } | ||
| 639 | |||
| 640 | for ($i = $start + 1; $i < $end; $i++) { | ||
| 641 | my $tv = $typevalue[$i]; | ||
| 642 | if ($tv =~ m/^(\C):\s*(.*)/) { | ||
| 643 | my $ptype = $1; | ||
| 644 | my $pvalue = $2; | ||
| 645 | if ($ptype eq "S") { | ||
| 646 | $role = $pvalue; | ||
| 647 | } | ||
| 648 | } | ||
| 649 | } | ||
| 650 | |||
| 651 | $role = lc($role); | ||
| 652 | if ($role eq "supported") { | ||
| 653 | $role = "supporter"; | ||
| 654 | } elsif ($role eq "maintained") { | ||
| 655 | $role = "maintainer"; | ||
| 656 | } elsif ($role eq "odd fixes") { | ||
| 657 | $role = "odd fixer"; | ||
| 658 | } elsif ($role eq "orphan") { | ||
| 659 | $role = "orphan minder"; | ||
| 660 | } elsif ($role eq "obsolete") { | ||
| 661 | $role = "obsolete minder"; | ||
| 662 | } elsif ($role eq "buried alive in reporters") { | ||
| 663 | $role = "chief penguin"; | ||
| 664 | } | ||
| 665 | |||
| 666 | return $role . ":" . $subsystem; | ||
| 667 | } | ||
| 668 | |||
| 669 | sub get_list_role { | ||
| 670 | my ($index) = @_; | ||
| 671 | |||
| 672 | my $i; | ||
| 673 | my $start = find_starting_index($index); | ||
| 674 | my $end = find_ending_index($index); | ||
| 675 | |||
| 676 | my $subsystem = $typevalue[$start]; | ||
| 677 | if (length($subsystem) > 20) { | ||
| 678 | $subsystem = substr($subsystem, 0, 17); | ||
| 679 | $subsystem =~ s/\s*$//; | ||
| 680 | $subsystem = $subsystem . "..."; | ||
| 681 | } | ||
| 682 | |||
| 683 | if ($subsystem eq "THE REST") { | ||
| 684 | $subsystem = ""; | ||
| 685 | } | ||
| 686 | |||
| 687 | return $subsystem; | ||
| 688 | } | ||
| 689 | |||
| 550 | sub add_categories { | 690 | sub add_categories { |
| 551 | my ($index) = @_; | 691 | my ($index) = @_; |
| 552 | 692 | ||
| @@ -564,17 +704,22 @@ sub add_categories { | |||
| 564 | if ($ptype eq "L") { | 704 | if ($ptype eq "L") { |
| 565 | my $list_address = $pvalue; | 705 | my $list_address = $pvalue; |
| 566 | my $list_additional = ""; | 706 | my $list_additional = ""; |
| 707 | my $list_role = get_list_role($i); | ||
| 708 | |||
| 709 | if ($list_role ne "") { | ||
| 710 | $list_role = ":" . $list_role; | ||
| 711 | } | ||
| 567 | if ($list_address =~ m/([^\s]+)\s+(.*)$/) { | 712 | if ($list_address =~ m/([^\s]+)\s+(.*)$/) { |
| 568 | $list_address = $1; | 713 | $list_address = $1; |
| 569 | $list_additional = $2; | 714 | $list_additional = $2; |
| 570 | } | 715 | } |
| 571 | if ($list_additional =~ m/subscribers-only/) { | 716 | if ($list_additional =~ m/subscribers-only/) { |
| 572 | if ($email_subscriber_list) { | 717 | if ($email_subscriber_list) { |
| 573 | push(@list_to, $list_address); | 718 | push(@list_to, [$list_address, "subscriber list${list_role}"]); |
| 574 | } | 719 | } |
| 575 | } else { | 720 | } else { |
| 576 | if ($email_list) { | 721 | if ($email_list) { |
| 577 | push(@list_to, $list_address); | 722 | push(@list_to, [$list_address, "open list${list_role}"]); |
| 578 | } | 723 | } |
| 579 | } | 724 | } |
| 580 | } elsif ($ptype eq "M") { | 725 | } elsif ($ptype eq "M") { |
| @@ -585,13 +730,14 @@ sub add_categories { | |||
| 585 | if ($tv =~ m/^(\C):\s*(.*)/) { | 730 | if ($tv =~ m/^(\C):\s*(.*)/) { |
| 586 | if ($1 eq "P") { | 731 | if ($1 eq "P") { |
| 587 | $name = $2; | 732 | $name = $2; |
| 588 | $pvalue = format_email($name, $address); | 733 | $pvalue = format_email($name, $address, $email_usename); |
| 589 | } | 734 | } |
| 590 | } | 735 | } |
| 591 | } | 736 | } |
| 592 | } | 737 | } |
| 593 | if ($email_maintainer) { | 738 | if ($email_maintainer) { |
| 594 | push_email_addresses($pvalue); | 739 | my $role = get_maintainer_role($i); |
| 740 | push_email_addresses($pvalue, $role); | ||
| 595 | } | 741 | } |
| 596 | } elsif ($ptype eq "T") { | 742 | } elsif ($ptype eq "T") { |
| 597 | push(@scm, $pvalue); | 743 | push(@scm, $pvalue); |
| @@ -618,7 +764,7 @@ sub email_inuse { | |||
| 618 | } | 764 | } |
| 619 | 765 | ||
| 620 | sub push_email_address { | 766 | sub push_email_address { |
| 621 | my ($line) = @_; | 767 | my ($line, $role) = @_; |
| 622 | 768 | ||
| 623 | my ($name, $address) = parse_email($line); | 769 | my ($name, $address) = parse_email($line); |
| 624 | 770 | ||
| @@ -627,9 +773,9 @@ sub push_email_address { | |||
| 627 | } | 773 | } |
| 628 | 774 | ||
| 629 | if (!$email_remove_duplicates) { | 775 | if (!$email_remove_duplicates) { |
| 630 | push(@email_to, format_email($name, $address)); | 776 | push(@email_to, [format_email($name, $address, $email_usename), $role]); |
| 631 | } elsif (!email_inuse($name, $address)) { | 777 | } elsif (!email_inuse($name, $address)) { |
| 632 | push(@email_to, format_email($name, $address)); | 778 | push(@email_to, [format_email($name, $address, $email_usename), $role]); |
| 633 | $email_hash_name{$name}++; | 779 | $email_hash_name{$name}++; |
| 634 | $email_hash_address{$address}++; | 780 | $email_hash_address{$address}++; |
| 635 | } | 781 | } |
| @@ -638,24 +784,52 @@ sub push_email_address { | |||
| 638 | } | 784 | } |
| 639 | 785 | ||
| 640 | sub push_email_addresses { | 786 | sub push_email_addresses { |
| 641 | my ($address) = @_; | 787 | my ($address, $role) = @_; |
| 642 | 788 | ||
| 643 | my @address_list = (); | 789 | my @address_list = (); |
| 644 | 790 | ||
| 645 | if (rfc822_valid($address)) { | 791 | if (rfc822_valid($address)) { |
| 646 | push_email_address($address); | 792 | push_email_address($address, $role); |
| 647 | } elsif (@address_list = rfc822_validlist($address)) { | 793 | } elsif (@address_list = rfc822_validlist($address)) { |
| 648 | my $array_count = shift(@address_list); | 794 | my $array_count = shift(@address_list); |
| 649 | while (my $entry = shift(@address_list)) { | 795 | while (my $entry = shift(@address_list)) { |
| 650 | push_email_address($entry); | 796 | push_email_address($entry, $role); |
| 651 | } | 797 | } |
| 652 | } else { | 798 | } else { |
| 653 | if (!push_email_address($address)) { | 799 | if (!push_email_address($address, $role)) { |
| 654 | warn("Invalid MAINTAINERS address: '" . $address . "'\n"); | 800 | warn("Invalid MAINTAINERS address: '" . $address . "'\n"); |
| 655 | } | 801 | } |
| 656 | } | 802 | } |
| 657 | } | 803 | } |
| 658 | 804 | ||
| 805 | sub add_role { | ||
| 806 | my ($line, $role) = @_; | ||
| 807 | |||
| 808 | my ($name, $address) = parse_email($line); | ||
| 809 | my $email = format_email($name, $address, $email_usename); | ||
| 810 | |||
| 811 | foreach my $entry (@email_to) { | ||
| 812 | if ($email_remove_duplicates) { | ||
| 813 | my ($entry_name, $entry_address) = parse_email($entry->[0]); | ||
| 814 | if ($name eq $entry_name || $address eq $entry_address) { | ||
| 815 | if ($entry->[1] eq "") { | ||
| 816 | $entry->[1] = "$role"; | ||
| 817 | } else { | ||
| 818 | $entry->[1] = "$entry->[1],$role"; | ||
| 819 | } | ||
| 820 | } | ||
| 821 | } else { | ||
| 822 | if ($email eq $entry->[0]) { | ||
| 823 | if ($entry->[1] eq "") { | ||
| 824 | $entry->[1] = "$role"; | ||
| 825 | } else { | ||
| 826 | $entry->[1] = "$entry->[1],$role"; | ||
| 827 | } | ||
| 828 | } | ||
| 829 | } | ||
| 830 | } | ||
| 831 | } | ||
| 832 | |||
| 659 | sub which { | 833 | sub which { |
| 660 | my ($bin) = @_; | 834 | my ($bin) = @_; |
| 661 | 835 | ||
| @@ -669,7 +843,7 @@ sub which { | |||
| 669 | } | 843 | } |
| 670 | 844 | ||
| 671 | sub mailmap { | 845 | sub mailmap { |
| 672 | my @lines = @_; | 846 | my (@lines) = @_; |
| 673 | my %hash; | 847 | my %hash; |
| 674 | 848 | ||
| 675 | foreach my $line (@lines) { | 849 | foreach my $line (@lines) { |
| @@ -678,14 +852,14 @@ sub mailmap { | |||
| 678 | $hash{$name} = $address; | 852 | $hash{$name} = $address; |
| 679 | } elsif ($address ne $hash{$name}) { | 853 | } elsif ($address ne $hash{$name}) { |
| 680 | $address = $hash{$name}; | 854 | $address = $hash{$name}; |
| 681 | $line = format_email($name, $address); | 855 | $line = format_email($name, $address, $email_usename); |
| 682 | } | 856 | } |
| 683 | if (exists($mailmap{$name})) { | 857 | if (exists($mailmap{$name})) { |
| 684 | my $obj = $mailmap{$name}; | 858 | my $obj = $mailmap{$name}; |
| 685 | foreach my $map_address (@$obj) { | 859 | foreach my $map_address (@$obj) { |
| 686 | if (($map_address eq $address) && | 860 | if (($map_address eq $address) && |
| 687 | ($map_address ne $hash{$name})) { | 861 | ($map_address ne $hash{$name})) { |
| 688 | $line = format_email($name, $hash{$name}); | 862 | $line = format_email($name, $hash{$name}, $email_usename); |
| 689 | } | 863 | } |
| 690 | } | 864 | } |
| 691 | } | 865 | } |
| @@ -694,34 +868,38 @@ sub mailmap { | |||
| 694 | return @lines; | 868 | return @lines; |
| 695 | } | 869 | } |
| 696 | 870 | ||
| 697 | sub recent_git_signoffs { | 871 | sub git_execute_cmd { |
| 698 | my ($file) = @_; | 872 | my ($cmd) = @_; |
| 699 | |||
| 700 | my $sign_offs = ""; | ||
| 701 | my $cmd = ""; | ||
| 702 | my $output = ""; | ||
| 703 | my $count = 0; | ||
| 704 | my @lines = (); | 873 | my @lines = (); |
| 705 | my %hash; | ||
| 706 | my $total_sign_offs; | ||
| 707 | 874 | ||
| 708 | if (which("git") eq "") { | 875 | my $output = `$cmd`; |
| 709 | warn("$P: git not found. Add --nogit to options?\n"); | 876 | $output =~ s/^\s*//gm; |
| 710 | return; | 877 | @lines = split("\n", $output); |
| 711 | } | ||
| 712 | if (!(-d ".git")) { | ||
| 713 | warn("$P: .git directory not found. Use a git repository for better results.\n"); | ||
| 714 | warn("$P: perhaps 'git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git'\n"); | ||
| 715 | return; | ||
| 716 | } | ||
| 717 | 878 | ||
| 718 | $cmd = "git log --since=${email_git_since} -- ${file}"; | 879 | return @lines; |
| 880 | } | ||
| 719 | 881 | ||
| 720 | $output = `${cmd}`; | 882 | sub hg_execute_cmd { |
| 721 | $output =~ s/^\s*//gm; | 883 | my ($cmd) = @_; |
| 884 | my @lines = (); | ||
| 722 | 885 | ||
| 886 | my $output = `$cmd`; | ||
| 723 | @lines = split("\n", $output); | 887 | @lines = split("\n", $output); |
| 724 | 888 | ||
| 889 | return @lines; | ||
| 890 | } | ||
| 891 | |||
| 892 | sub vcs_find_signers { | ||
| 893 | my ($cmd) = @_; | ||
| 894 | my @lines = (); | ||
| 895 | my $commits; | ||
| 896 | |||
| 897 | @lines = &{$VCS_cmds{"execute_cmd"}}($cmd); | ||
| 898 | |||
| 899 | my $pattern = $VCS_cmds{"commit_pattern"}; | ||
| 900 | |||
| 901 | $commits = grep(/$pattern/, @lines); # of commits | ||
| 902 | |||
| 725 | @lines = grep(/^[-_ a-z]+by:.*\@.*$/i, @lines); | 903 | @lines = grep(/^[-_ a-z]+by:.*\@.*$/i, @lines); |
| 726 | if (!$email_git_penguin_chiefs) { | 904 | if (!$email_git_penguin_chiefs) { |
| 727 | @lines = grep(!/${penguin_chiefs}/i, @lines); | 905 | @lines = grep(!/${penguin_chiefs}/i, @lines); |
| @@ -729,111 +907,183 @@ sub recent_git_signoffs { | |||
| 729 | # cut -f2- -d":" | 907 | # cut -f2- -d":" |
| 730 | s/.*:\s*(.+)\s*/$1/ for (@lines); | 908 | s/.*:\s*(.+)\s*/$1/ for (@lines); |
| 731 | 909 | ||
| 732 | $total_sign_offs = @lines; | 910 | ## Reformat email addresses (with names) to avoid badly written signatures |
| 733 | 911 | ||
| 734 | if ($email_remove_duplicates) { | 912 | foreach my $line (@lines) { |
| 735 | @lines = mailmap(@lines); | 913 | my ($name, $address) = parse_email($line); |
| 914 | $line = format_email($name, $address, 1); | ||
| 736 | } | 915 | } |
| 737 | 916 | ||
| 738 | @lines = sort(@lines); | 917 | return ($commits, @lines); |
| 739 | |||
| 740 | # uniq -c | ||
| 741 | $hash{$_}++ for @lines; | ||
| 742 | |||
| 743 | # sort -rn | ||
| 744 | foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) { | ||
| 745 | my $sign_offs = $hash{$line}; | ||
| 746 | $count++; | ||
| 747 | last if ($sign_offs < $email_git_min_signatures || | ||
| 748 | $count > $email_git_max_maintainers || | ||
| 749 | $sign_offs * 100 / $total_sign_offs < $email_git_min_percent); | ||
| 750 | push_email_address($line); | ||
| 751 | } | ||
| 752 | } | 918 | } |
| 753 | 919 | ||
| 754 | sub save_commits { | 920 | sub vcs_save_commits { |
| 755 | my ($cmd, @commits) = @_; | 921 | my ($cmd) = @_; |
| 756 | my $output; | ||
| 757 | my @lines = (); | 922 | my @lines = (); |
| 923 | my @commits = (); | ||
| 758 | 924 | ||
| 759 | $output = `${cmd}`; | 925 | @lines = &{$VCS_cmds{"execute_cmd"}}($cmd); |
| 760 | 926 | ||
| 761 | @lines = split("\n", $output); | ||
| 762 | foreach my $line (@lines) { | 927 | foreach my $line (@lines) { |
| 763 | if ($line =~ m/^(\w+) /) { | 928 | if ($line =~ m/$VCS_cmds{"blame_commit_pattern"}/) { |
| 764 | push (@commits, $1); | 929 | push(@commits, $1); |
| 765 | } | 930 | } |
| 766 | } | 931 | } |
| 932 | |||
| 767 | return @commits; | 933 | return @commits; |
| 768 | } | 934 | } |
| 769 | 935 | ||
| 770 | sub git_assign_blame { | 936 | sub vcs_blame { |
| 771 | my ($file) = @_; | 937 | my ($file) = @_; |
| 772 | |||
| 773 | my @lines = (); | ||
| 774 | my @commits = (); | ||
| 775 | my $cmd; | 938 | my $cmd; |
| 776 | my $output; | 939 | my @commits = (); |
| 777 | my %hash; | 940 | |
| 778 | my $total_sign_offs; | 941 | return @commits if (!(-f $file)); |
| 779 | my $count; | 942 | |
| 943 | if (@range && $VCS_cmds{"blame_range_cmd"} eq "") { | ||
| 944 | my @all_commits = (); | ||
| 945 | |||
| 946 | $cmd = $VCS_cmds{"blame_file_cmd"}; | ||
| 947 | $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd | ||
| 948 | @all_commits = vcs_save_commits($cmd); | ||
| 780 | 949 | ||
| 781 | if (@range) { | ||
| 782 | foreach my $file_range_diff (@range) { | 950 | foreach my $file_range_diff (@range) { |
| 783 | next if (!($file_range_diff =~ m/(.+):(.+):(.+)/)); | 951 | next if (!($file_range_diff =~ m/(.+):(.+):(.+)/)); |
| 784 | my $diff_file = $1; | 952 | my $diff_file = $1; |
| 785 | my $diff_start = $2; | 953 | my $diff_start = $2; |
| 786 | my $diff_length = $3; | 954 | my $diff_length = $3; |
| 787 | next if (!("$file" eq "$diff_file")); | 955 | next if ("$file" ne "$diff_file"); |
| 788 | $cmd = "git blame -l -L $diff_start,+$diff_length $file"; | 956 | for (my $i = $diff_start; $i < $diff_start + $diff_length; $i++) { |
| 789 | @commits = save_commits($cmd, @commits); | 957 | push(@commits, $all_commits[$i]); |
| 958 | } | ||
| 790 | } | 959 | } |
| 791 | } else { | 960 | } elsif (@range) { |
| 792 | if (-f $file) { | 961 | foreach my $file_range_diff (@range) { |
| 793 | $cmd = "git blame -l $file"; | 962 | next if (!($file_range_diff =~ m/(.+):(.+):(.+)/)); |
| 794 | @commits = save_commits($cmd, @commits); | 963 | my $diff_file = $1; |
| 964 | my $diff_start = $2; | ||
| 965 | my $diff_length = $3; | ||
| 966 | next if ("$file" ne "$diff_file"); | ||
| 967 | $cmd = $VCS_cmds{"blame_range_cmd"}; | ||
| 968 | $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd | ||
| 969 | push(@commits, vcs_save_commits($cmd)); | ||
| 795 | } | 970 | } |
| 971 | } else { | ||
| 972 | $cmd = $VCS_cmds{"blame_file_cmd"}; | ||
| 973 | $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd | ||
| 974 | @commits = vcs_save_commits($cmd); | ||
| 796 | } | 975 | } |
| 797 | 976 | ||
| 798 | $total_sign_offs = 0; | 977 | return @commits; |
| 799 | @commits = uniq(@commits); | 978 | } |
| 800 | foreach my $commit (@commits) { | ||
| 801 | $cmd = "git log -1 ${commit}"; | ||
| 802 | 979 | ||
| 803 | $output = `${cmd}`; | 980 | my $printed_novcs = 0; |
| 804 | $output =~ s/^\s*//gm; | 981 | sub vcs_exists { |
| 805 | @lines = split("\n", $output); | 982 | %VCS_cmds = %VCS_cmds_git; |
| 983 | return 1 if eval $VCS_cmds{"available"}; | ||
| 984 | %VCS_cmds = %VCS_cmds_hg; | ||
| 985 | return 1 if eval $VCS_cmds{"available"}; | ||
| 986 | %VCS_cmds = (); | ||
| 987 | if (!$printed_novcs) { | ||
| 988 | warn("$P: No supported VCS found. Add --nogit to options?\n"); | ||
| 989 | warn("Using a git repository produces better results.\n"); | ||
| 990 | warn("Try Linus Torvalds' latest git repository using:\n"); | ||
| 991 | warn("git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git\n"); | ||
| 992 | $printed_novcs = 1; | ||
| 993 | } | ||
| 994 | return 0; | ||
| 995 | } | ||
| 806 | 996 | ||
| 807 | @lines = grep(/^[-_ a-z]+by:.*\@.*$/i, @lines); | 997 | sub vcs_assign { |
| 808 | if (!$email_git_penguin_chiefs) { | 998 | my ($role, $divisor, @lines) = @_; |
| 809 | @lines = grep(!/${penguin_chiefs}/i, @lines); | ||
| 810 | } | ||
| 811 | 999 | ||
| 812 | # cut -f2- -d":" | 1000 | my %hash; |
| 813 | s/.*:\s*(.+)\s*/$1/ for (@lines); | 1001 | my $count = 0; |
| 814 | 1002 | ||
| 815 | $total_sign_offs += @lines; | 1003 | return if (@lines <= 0); |
| 816 | 1004 | ||
| 817 | if ($email_remove_duplicates) { | 1005 | if ($divisor <= 0) { |
| 818 | @lines = mailmap(@lines); | 1006 | warn("Bad divisor in " . (caller(0))[3] . ": $divisor\n"); |
| 819 | } | 1007 | $divisor = 1; |
| 1008 | } | ||
| 820 | 1009 | ||
| 821 | $hash{$_}++ for @lines; | 1010 | if ($email_remove_duplicates) { |
| 1011 | @lines = mailmap(@lines); | ||
| 822 | } | 1012 | } |
| 823 | 1013 | ||
| 824 | $count = 0; | 1014 | @lines = sort(@lines); |
| 1015 | |||
| 1016 | # uniq -c | ||
| 1017 | $hash{$_}++ for @lines; | ||
| 1018 | |||
| 1019 | # sort -rn | ||
| 825 | foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) { | 1020 | foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) { |
| 826 | my $sign_offs = $hash{$line}; | 1021 | my $sign_offs = $hash{$line}; |
| 1022 | my $percent = $sign_offs * 100 / $divisor; | ||
| 1023 | |||
| 1024 | $percent = 100 if ($percent > 100); | ||
| 827 | $count++; | 1025 | $count++; |
| 828 | last if ($sign_offs < $email_git_min_signatures || | 1026 | last if ($sign_offs < $email_git_min_signatures || |
| 829 | $count > $email_git_max_maintainers || | 1027 | $count > $email_git_max_maintainers || |
| 830 | $sign_offs * 100 / $total_sign_offs < $email_git_min_percent); | 1028 | $percent < $email_git_min_percent); |
| 831 | push_email_address($line); | 1029 | push_email_address($line, ''); |
| 1030 | if ($output_rolestats) { | ||
| 1031 | my $fmt_percent = sprintf("%.0f", $percent); | ||
| 1032 | add_role($line, "$role:$sign_offs/$divisor=$fmt_percent%"); | ||
| 1033 | } else { | ||
| 1034 | add_role($line, $role); | ||
| 1035 | } | ||
| 1036 | } | ||
| 1037 | } | ||
| 1038 | |||
| 1039 | sub vcs_file_signoffs { | ||
| 1040 | my ($file) = @_; | ||
| 1041 | |||
| 1042 | my @signers = (); | ||
| 1043 | my $commits; | ||
| 1044 | |||
| 1045 | return if (!vcs_exists()); | ||
| 1046 | |||
| 1047 | my $cmd = $VCS_cmds{"find_signers_cmd"}; | ||
| 1048 | $cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd | ||
| 1049 | |||
| 1050 | ($commits, @signers) = vcs_find_signers($cmd); | ||
| 1051 | vcs_assign("commit_signer", $commits, @signers); | ||
| 1052 | } | ||
| 1053 | |||
| 1054 | sub vcs_file_blame { | ||
| 1055 | my ($file) = @_; | ||
| 1056 | |||
| 1057 | my @signers = (); | ||
| 1058 | my @commits = (); | ||
| 1059 | my $total_commits; | ||
| 1060 | |||
| 1061 | return if (!vcs_exists()); | ||
| 1062 | |||
| 1063 | @commits = vcs_blame($file); | ||
| 1064 | @commits = uniq(@commits); | ||
| 1065 | $total_commits = @commits; | ||
| 1066 | |||
| 1067 | foreach my $commit (@commits) { | ||
| 1068 | my $commit_count; | ||
| 1069 | my @commit_signers = (); | ||
| 1070 | |||
| 1071 | my $cmd = $VCS_cmds{"find_commit_signers_cmd"}; | ||
| 1072 | $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd | ||
| 1073 | |||
| 1074 | ($commit_count, @commit_signers) = vcs_find_signers($cmd); | ||
| 1075 | push(@signers, @commit_signers); | ||
| 1076 | } | ||
| 1077 | |||
| 1078 | if ($from_filename) { | ||
| 1079 | vcs_assign("commits", $total_commits, @signers); | ||
| 1080 | } else { | ||
| 1081 | vcs_assign("modified commits", $total_commits, @signers); | ||
| 832 | } | 1082 | } |
| 833 | } | 1083 | } |
| 834 | 1084 | ||
| 835 | sub uniq { | 1085 | sub uniq { |
| 836 | my @parms = @_; | 1086 | my (@parms) = @_; |
| 837 | 1087 | ||
| 838 | my %saw; | 1088 | my %saw; |
| 839 | @parms = grep(!$saw{$_}++, @parms); | 1089 | @parms = grep(!$saw{$_}++, @parms); |
| @@ -841,7 +1091,7 @@ sub uniq { | |||
| 841 | } | 1091 | } |
| 842 | 1092 | ||
| 843 | sub sort_and_uniq { | 1093 | sub sort_and_uniq { |
| 844 | my @parms = @_; | 1094 | my (@parms) = @_; |
| 845 | 1095 | ||
| 846 | my %saw; | 1096 | my %saw; |
| 847 | @parms = sort @parms; | 1097 | @parms = sort @parms; |
| @@ -849,8 +1099,27 @@ sub sort_and_uniq { | |||
| 849 | return @parms; | 1099 | return @parms; |
| 850 | } | 1100 | } |
| 851 | 1101 | ||
| 1102 | sub merge_email { | ||
| 1103 | my @lines; | ||
| 1104 | my %saw; | ||
| 1105 | |||
| 1106 | for (@_) { | ||
| 1107 | my ($address, $role) = @$_; | ||
| 1108 | if (!$saw{$address}) { | ||
| 1109 | if ($output_roles) { | ||
| 1110 | push(@lines, "$address ($role)"); | ||
| 1111 | } else { | ||
| 1112 | push(@lines, $address); | ||
| 1113 | } | ||
| 1114 | $saw{$address} = 1; | ||
| 1115 | } | ||
| 1116 | } | ||
| 1117 | |||
| 1118 | return @lines; | ||
| 1119 | } | ||
| 1120 | |||
| 852 | sub output { | 1121 | sub output { |
| 853 | my @parms = @_; | 1122 | my (@parms) = @_; |
| 854 | 1123 | ||
| 855 | if ($output_multiline) { | 1124 | if ($output_multiline) { |
| 856 | foreach my $line (@parms) { | 1125 | foreach my $line (@parms) { |
| @@ -947,11 +1216,9 @@ sub rfc822_validlist ($) { | |||
| 947 | if ($s =~ m/^(?:$rfc822re)?(?:,(?:$rfc822re)?)*$/so && | 1216 | if ($s =~ m/^(?:$rfc822re)?(?:,(?:$rfc822re)?)*$/so && |
| 948 | $s =~ m/^$rfc822_char*$/) { | 1217 | $s =~ m/^$rfc822_char*$/) { |
| 949 | while ($s =~ m/(?:^|,$rfc822_lwsp*)($rfc822re)/gos) { | 1218 | while ($s =~ m/(?:^|,$rfc822_lwsp*)($rfc822re)/gos) { |
| 950 | push @r, $1; | 1219 | push(@r, $1); |
| 951 | } | 1220 | } |
| 952 | return wantarray ? (scalar(@r), @r) : 1; | 1221 | return wantarray ? (scalar(@r), @r) : 1; |
| 953 | } | 1222 | } |
| 954 | else { | 1223 | return wantarray ? () : 0; |
| 955 | return wantarray ? () : 0; | ||
| 956 | } | ||
| 957 | } | 1224 | } |
diff --git a/scripts/headers.sh b/scripts/headers.sh index 0308ecc10d5b..1ddcdd38d97f 100755 --- a/scripts/headers.sh +++ b/scripts/headers.sh | |||
| @@ -8,8 +8,6 @@ do_command() | |||
| 8 | { | 8 | { |
| 9 | if [ -f ${srctree}/arch/$2/include/asm/Kbuild ]; then | 9 | if [ -f ${srctree}/arch/$2/include/asm/Kbuild ]; then |
| 10 | make ARCH=$2 KBUILD_HEADERS=$1 headers_$1 | 10 | make ARCH=$2 KBUILD_HEADERS=$1 headers_$1 |
| 11 | elif [ -f ${srctree}/include/asm-$2/Kbuild ]; then | ||
| 12 | make ARCH=$2 KBUILD_HEADERS=$1 headers_$1 | ||
| 13 | else | 11 | else |
| 14 | printf "Ignoring arch: %s\n" ${arch} | 12 | printf "Ignoring arch: %s\n" ${arch} |
| 15 | fi | 13 | fi |
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index 80599e3a7994..999e8a7d5bf7 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile | |||
| @@ -27,6 +27,7 @@ oldconfig: $(obj)/conf | |||
| 27 | $< -o $(Kconfig) | 27 | $< -o $(Kconfig) |
| 28 | 28 | ||
| 29 | silentoldconfig: $(obj)/conf | 29 | silentoldconfig: $(obj)/conf |
| 30 | $(Q)mkdir -p include/generated | ||
| 30 | $< -s $(Kconfig) | 31 | $< -s $(Kconfig) |
| 31 | 32 | ||
| 32 | localmodconfig: $(obj)/streamline_config.pl $(obj)/conf | 33 | localmodconfig: $(obj)/streamline_config.pl $(obj)/conf |
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index b55e72ff2fc6..c4dec80cfd8e 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c | |||
| @@ -677,7 +677,7 @@ int conf_write_autoconf(void) | |||
| 677 | struct symbol *sym; | 677 | struct symbol *sym; |
| 678 | const char *str; | 678 | const char *str; |
| 679 | const char *name; | 679 | const char *name; |
| 680 | FILE *out, *out_h; | 680 | FILE *out, *tristate, *out_h; |
| 681 | time_t now; | 681 | time_t now; |
| 682 | int i, l; | 682 | int i, l; |
| 683 | 683 | ||
| @@ -692,9 +692,16 @@ int conf_write_autoconf(void) | |||
| 692 | if (!out) | 692 | if (!out) |
| 693 | return 1; | 693 | return 1; |
| 694 | 694 | ||
| 695 | tristate = fopen(".tmpconfig_tristate", "w"); | ||
| 696 | if (!tristate) { | ||
| 697 | fclose(out); | ||
| 698 | return 1; | ||
| 699 | } | ||
| 700 | |||
| 695 | out_h = fopen(".tmpconfig.h", "w"); | 701 | out_h = fopen(".tmpconfig.h", "w"); |
| 696 | if (!out_h) { | 702 | if (!out_h) { |
| 697 | fclose(out); | 703 | fclose(out); |
| 704 | fclose(tristate); | ||
| 698 | return 1; | 705 | return 1; |
| 699 | } | 706 | } |
| 700 | 707 | ||
| @@ -707,6 +714,9 @@ int conf_write_autoconf(void) | |||
| 707 | "# %s" | 714 | "# %s" |
| 708 | "#\n", | 715 | "#\n", |
| 709 | sym_get_string_value(sym), ctime(&now)); | 716 | sym_get_string_value(sym), ctime(&now)); |
| 717 | fprintf(tristate, "#\n" | ||
| 718 | "# Automatically generated - do not edit\n" | ||
| 719 | "\n"); | ||
| 710 | fprintf(out_h, "/*\n" | 720 | fprintf(out_h, "/*\n" |
| 711 | " * Automatically generated C config: don't edit\n" | 721 | " * Automatically generated C config: don't edit\n" |
| 712 | " * Linux kernel version: %s\n" | 722 | " * Linux kernel version: %s\n" |
| @@ -727,10 +737,14 @@ int conf_write_autoconf(void) | |||
| 727 | break; | 737 | break; |
| 728 | case mod: | 738 | case mod: |
| 729 | fprintf(out, "CONFIG_%s=m\n", sym->name); | 739 | fprintf(out, "CONFIG_%s=m\n", sym->name); |
| 740 | fprintf(tristate, "CONFIG_%s=M\n", sym->name); | ||
| 730 | fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name); | 741 | fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name); |
| 731 | break; | 742 | break; |
| 732 | case yes: | 743 | case yes: |
| 733 | fprintf(out, "CONFIG_%s=y\n", sym->name); | 744 | fprintf(out, "CONFIG_%s=y\n", sym->name); |
| 745 | if (sym->type == S_TRISTATE) | ||
| 746 | fprintf(tristate, "CONFIG_%s=Y\n", | ||
| 747 | sym->name); | ||
| 734 | fprintf(out_h, "#define CONFIG_%s 1\n", sym->name); | 748 | fprintf(out_h, "#define CONFIG_%s 1\n", sym->name); |
| 735 | break; | 749 | break; |
| 736 | } | 750 | } |
| @@ -772,13 +786,19 @@ int conf_write_autoconf(void) | |||
| 772 | } | 786 | } |
| 773 | } | 787 | } |
| 774 | fclose(out); | 788 | fclose(out); |
| 789 | fclose(tristate); | ||
| 775 | fclose(out_h); | 790 | fclose(out_h); |
| 776 | 791 | ||
| 777 | name = getenv("KCONFIG_AUTOHEADER"); | 792 | name = getenv("KCONFIG_AUTOHEADER"); |
| 778 | if (!name) | 793 | if (!name) |
| 779 | name = "include/linux/autoconf.h"; | 794 | name = "include/generated/autoconf.h"; |
| 780 | if (rename(".tmpconfig.h", name)) | 795 | if (rename(".tmpconfig.h", name)) |
| 781 | return 1; | 796 | return 1; |
| 797 | name = getenv("KCONFIG_TRISTATE"); | ||
| 798 | if (!name) | ||
| 799 | name = "include/config/tristate.conf"; | ||
| 800 | if (rename(".tmpconfig_tristate", name)) | ||
| 801 | return 1; | ||
| 782 | name = conf_get_autoconfig_name(); | 802 | name = conf_get_autoconfig_name(); |
| 783 | /* | 803 | /* |
| 784 | * This must be the last step, kbuild has a dependency on auto.conf | 804 | * This must be the last step, kbuild has a dependency on auto.conf |
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c index d82953573588..8413cf38ed27 100644 --- a/scripts/kconfig/mconf.c +++ b/scripts/kconfig/mconf.c | |||
| @@ -213,7 +213,7 @@ load_config_help[] = N_( | |||
| 213 | "to modify that configuration.\n" | 213 | "to modify that configuration.\n" |
| 214 | "\n" | 214 | "\n" |
| 215 | "If you are uncertain, then you have probably never used alternate\n" | 215 | "If you are uncertain, then you have probably never used alternate\n" |
| 216 | "configuration files. You should therefor leave this blank to abort.\n"), | 216 | "configuration files. You should therefore leave this blank to abort.\n"), |
| 217 | save_config_text[] = N_( | 217 | save_config_text[] = N_( |
| 218 | "Enter a filename to which this configuration should be saved " | 218 | "Enter a filename to which this configuration should be saved " |
| 219 | "as an alternate. Leave blank to abort."), | 219 | "as an alternate. Leave blank to abort."), |
diff --git a/scripts/kernel-doc b/scripts/kernel-doc index ea9f8a58678f..241310e59cd6 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc | |||
| @@ -1852,10 +1852,17 @@ sub tracepoint_munge($) { | |||
| 1852 | my $tracepointname = 0; | 1852 | my $tracepointname = 0; |
| 1853 | my $tracepointargs = 0; | 1853 | my $tracepointargs = 0; |
| 1854 | 1854 | ||
| 1855 | if($prototype =~ m/TRACE_EVENT\((.*?),/) { | 1855 | if ($prototype =~ m/TRACE_EVENT\((.*?),/) { |
| 1856 | $tracepointname = $1; | 1856 | $tracepointname = $1; |
| 1857 | } | 1857 | } |
| 1858 | if($prototype =~ m/TP_PROTO\((.*?)\)/) { | 1858 | if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { |
| 1859 | $tracepointname = $1; | ||
| 1860 | } | ||
| 1861 | if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { | ||
| 1862 | $tracepointname = $2; | ||
| 1863 | } | ||
| 1864 | $tracepointname =~ s/^\s+//; #strip leading whitespace | ||
| 1865 | if ($prototype =~ m/TP_PROTO\((.*?)\)/) { | ||
| 1859 | $tracepointargs = $1; | 1866 | $tracepointargs = $1; |
| 1860 | } | 1867 | } |
| 1861 | if (($tracepointname eq 0) || ($tracepointargs eq 0)) { | 1868 | if (($tracepointname eq 0) || ($tracepointargs eq 0)) { |
| @@ -1920,7 +1927,9 @@ sub process_state3_function($$) { | |||
| 1920 | if ($prototype =~ /SYSCALL_DEFINE/) { | 1927 | if ($prototype =~ /SYSCALL_DEFINE/) { |
| 1921 | syscall_munge(); | 1928 | syscall_munge(); |
| 1922 | } | 1929 | } |
| 1923 | if ($prototype =~ /TRACE_EVENT/) { | 1930 | if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || |
| 1931 | $prototype =~ /DEFINE_SINGLE_EVENT/) | ||
| 1932 | { | ||
| 1924 | tracepoint_munge($file); | 1933 | tracepoint_munge($file); |
| 1925 | } | 1934 | } |
| 1926 | dump_function($prototype, $file); | 1935 | dump_function($prototype, $file); |
diff --git a/scripts/mkcompile_h b/scripts/mkcompile_h index bce3d0fe6fbd..23dbad80cce9 100755 --- a/scripts/mkcompile_h +++ b/scripts/mkcompile_h | |||
| @@ -14,7 +14,7 @@ vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; } | |||
| 14 | # So "sudo make install" won't change the "compiled by <user>" | 14 | # So "sudo make install" won't change the "compiled by <user>" |
| 15 | # do "compiled by root" | 15 | # do "compiled by root" |
| 16 | 16 | ||
| 17 | if [ -r $TARGET -a ! -O include/linux/autoconf.h ]; then | 17 | if [ -r $TARGET -a ! -O include/generated/autoconf.h ]; then |
| 18 | vecho " SKIPPED $TARGET" | 18 | vecho " SKIPPED $TARGET" |
| 19 | exit 0 | 19 | exit 0 |
| 20 | fi | 20 | fi |
diff --git a/scripts/mod/Makefile b/scripts/mod/Makefile index 11d69c35e5b4..ff954f8168c1 100644 --- a/scripts/mod/Makefile +++ b/scripts/mod/Makefile | |||
| @@ -8,7 +8,7 @@ modpost-objs := modpost.o file2alias.o sumversion.o | |||
| 8 | $(obj)/modpost.o $(obj)/file2alias.o $(obj)/sumversion.o: $(obj)/elfconfig.h | 8 | $(obj)/modpost.o $(obj)/file2alias.o $(obj)/sumversion.o: $(obj)/elfconfig.h |
| 9 | 9 | ||
| 10 | quiet_cmd_elfconfig = MKELF $@ | 10 | quiet_cmd_elfconfig = MKELF $@ |
| 11 | cmd_elfconfig = $(obj)/mk_elfconfig $(ARCH) < $< > $@ | 11 | cmd_elfconfig = $(obj)/mk_elfconfig < $< > $@ |
| 12 | 12 | ||
| 13 | $(obj)/elfconfig.h: $(obj)/empty.o $(obj)/mk_elfconfig FORCE | 13 | $(obj)/elfconfig.h: $(obj)/empty.o $(obj)/mk_elfconfig FORCE |
| 14 | $(call if_changed,elfconfig) | 14 | $(call if_changed,elfconfig) |
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 62a9025cdcc7..6f426afbc522 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c | |||
| @@ -104,7 +104,7 @@ static void device_id_check(const char *modname, const char *device_id, | |||
| 104 | static void do_usb_entry(struct usb_device_id *id, | 104 | static void do_usb_entry(struct usb_device_id *id, |
| 105 | unsigned int bcdDevice_initial, int bcdDevice_initial_digits, | 105 | unsigned int bcdDevice_initial, int bcdDevice_initial_digits, |
| 106 | unsigned char range_lo, unsigned char range_hi, | 106 | unsigned char range_lo, unsigned char range_hi, |
| 107 | struct module *mod) | 107 | unsigned char max, struct module *mod) |
| 108 | { | 108 | { |
| 109 | char alias[500]; | 109 | char alias[500]; |
| 110 | strcpy(alias, "usb:"); | 110 | strcpy(alias, "usb:"); |
| @@ -118,9 +118,22 @@ static void do_usb_entry(struct usb_device_id *id, | |||
| 118 | sprintf(alias + strlen(alias), "%0*X", | 118 | sprintf(alias + strlen(alias), "%0*X", |
| 119 | bcdDevice_initial_digits, bcdDevice_initial); | 119 | bcdDevice_initial_digits, bcdDevice_initial); |
| 120 | if (range_lo == range_hi) | 120 | if (range_lo == range_hi) |
| 121 | sprintf(alias + strlen(alias), "%u", range_lo); | 121 | sprintf(alias + strlen(alias), "%X", range_lo); |
| 122 | else if (range_lo > 0 || range_hi < 9) | 122 | else if (range_lo > 0 || range_hi < max) { |
| 123 | sprintf(alias + strlen(alias), "[%u-%u]", range_lo, range_hi); | 123 | if (range_lo > 0x9 || range_hi < 0xA) |
| 124 | sprintf(alias + strlen(alias), | ||
| 125 | "[%X-%X]", | ||
| 126 | range_lo, | ||
| 127 | range_hi); | ||
| 128 | else { | ||
| 129 | sprintf(alias + strlen(alias), | ||
| 130 | range_lo < 0x9 ? "[%X-9" : "[%X", | ||
| 131 | range_lo); | ||
| 132 | sprintf(alias + strlen(alias), | ||
| 133 | range_hi > 0xA ? "a-%X]" : "%X]", | ||
| 134 | range_lo); | ||
| 135 | } | ||
| 136 | } | ||
| 124 | if (bcdDevice_initial_digits < (sizeof(id->bcdDevice_lo) * 2 - 1)) | 137 | if (bcdDevice_initial_digits < (sizeof(id->bcdDevice_lo) * 2 - 1)) |
| 125 | strcat(alias, "*"); | 138 | strcat(alias, "*"); |
| 126 | 139 | ||
| @@ -147,10 +160,49 @@ static void do_usb_entry(struct usb_device_id *id, | |||
| 147 | "MODULE_ALIAS(\"%s\");\n", alias); | 160 | "MODULE_ALIAS(\"%s\");\n", alias); |
| 148 | } | 161 | } |
| 149 | 162 | ||
| 163 | /* Handles increment/decrement of BCD formatted integers */ | ||
| 164 | /* Returns the previous value, so it works like i++ or i-- */ | ||
| 165 | static unsigned int incbcd(unsigned int *bcd, | ||
| 166 | int inc, | ||
| 167 | unsigned char max, | ||
| 168 | size_t chars) | ||
| 169 | { | ||
| 170 | unsigned int init = *bcd, i, j; | ||
| 171 | unsigned long long c, dec = 0; | ||
| 172 | |||
| 173 | /* If bcd is not in BCD format, just increment */ | ||
| 174 | if (max > 0x9) { | ||
| 175 | *bcd += inc; | ||
| 176 | return init; | ||
| 177 | } | ||
| 178 | |||
| 179 | /* Convert BCD to Decimal */ | ||
| 180 | for (i=0 ; i < chars ; i++) { | ||
| 181 | c = (*bcd >> (i << 2)) & 0xf; | ||
| 182 | c = c > 9 ? 9 : c; /* force to bcd just in case */ | ||
| 183 | for (j=0 ; j < i ; j++) | ||
| 184 | c = c * 10; | ||
| 185 | dec += c; | ||
| 186 | } | ||
| 187 | |||
| 188 | /* Do our increment/decrement */ | ||
| 189 | dec += inc; | ||
| 190 | *bcd = 0; | ||
| 191 | |||
| 192 | /* Convert back to BCD */ | ||
| 193 | for (i=0 ; i < chars ; i++) { | ||
| 194 | for (c=1,j=0 ; j < i ; j++) | ||
| 195 | c = c * 10; | ||
| 196 | c = (dec / c) % 10; | ||
| 197 | *bcd += c << (i << 2); | ||
| 198 | } | ||
| 199 | return init; | ||
| 200 | } | ||
| 201 | |||
| 150 | static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod) | 202 | static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod) |
| 151 | { | 203 | { |
| 152 | unsigned int devlo, devhi; | 204 | unsigned int devlo, devhi; |
| 153 | unsigned char chi, clo; | 205 | unsigned char chi, clo, max; |
| 154 | int ndigits; | 206 | int ndigits; |
| 155 | 207 | ||
| 156 | id->match_flags = TO_NATIVE(id->match_flags); | 208 | id->match_flags = TO_NATIVE(id->match_flags); |
| @@ -162,6 +214,17 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod) | |||
| 162 | devhi = id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI ? | 214 | devhi = id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI ? |
| 163 | TO_NATIVE(id->bcdDevice_hi) : ~0x0U; | 215 | TO_NATIVE(id->bcdDevice_hi) : ~0x0U; |
| 164 | 216 | ||
| 217 | /* Figure out if this entry is in bcd or hex format */ | ||
| 218 | max = 0x9; /* Default to decimal format */ | ||
| 219 | for (ndigits = 0 ; ndigits < sizeof(id->bcdDevice_lo) * 2 ; ndigits++) { | ||
| 220 | clo = (devlo >> (ndigits << 2)) & 0xf; | ||
| 221 | chi = ((devhi > 0x9999 ? 0x9999 : devhi) >> (ndigits << 2)) & 0xf; | ||
| 222 | if (clo > max || chi > max) { | ||
| 223 | max = 0xf; | ||
| 224 | break; | ||
| 225 | } | ||
| 226 | } | ||
| 227 | |||
| 165 | /* | 228 | /* |
| 166 | * Some modules (visor) have empty slots as placeholder for | 229 | * Some modules (visor) have empty slots as placeholder for |
| 167 | * run-time specification that results in catch-all alias | 230 | * run-time specification that results in catch-all alias |
| @@ -173,21 +236,27 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod) | |||
| 173 | for (ndigits = sizeof(id->bcdDevice_lo) * 2 - 1; devlo <= devhi; ndigits--) { | 236 | for (ndigits = sizeof(id->bcdDevice_lo) * 2 - 1; devlo <= devhi; ndigits--) { |
| 174 | clo = devlo & 0xf; | 237 | clo = devlo & 0xf; |
| 175 | chi = devhi & 0xf; | 238 | chi = devhi & 0xf; |
| 176 | if (chi > 9) /* it's bcd not hex */ | 239 | if (chi > max) /* If we are in bcd mode, truncate if necessary */ |
| 177 | chi = 9; | 240 | chi = max; |
| 178 | devlo >>= 4; | 241 | devlo >>= 4; |
| 179 | devhi >>= 4; | 242 | devhi >>= 4; |
| 180 | 243 | ||
| 181 | if (devlo == devhi || !ndigits) { | 244 | if (devlo == devhi || !ndigits) { |
| 182 | do_usb_entry(id, devlo, ndigits, clo, chi, mod); | 245 | do_usb_entry(id, devlo, ndigits, clo, chi, max, mod); |
| 183 | break; | 246 | break; |
| 184 | } | 247 | } |
| 185 | 248 | ||
| 186 | if (clo > 0) | 249 | if (clo > 0x0) |
| 187 | do_usb_entry(id, devlo++, ndigits, clo, 9, mod); | 250 | do_usb_entry(id, |
| 188 | 251 | incbcd(&devlo, 1, max, | |
| 189 | if (chi < 9) | 252 | sizeof(id->bcdDevice_lo) * 2), |
| 190 | do_usb_entry(id, devhi--, ndigits, 0, chi, mod); | 253 | ndigits, clo, max, max, mod); |
| 254 | |||
| 255 | if (chi < max) | ||
| 256 | do_usb_entry(id, | ||
| 257 | incbcd(&devhi, -1, max, | ||
| 258 | sizeof(id->bcdDevice_lo) * 2), | ||
| 259 | ndigits, 0x0, chi, max, mod); | ||
| 191 | } | 260 | } |
| 192 | } | 261 | } |
| 193 | 262 | ||
diff --git a/scripts/mod/mk_elfconfig.c b/scripts/mod/mk_elfconfig.c index 6a96d47bd1e6..639bca7ba559 100644 --- a/scripts/mod/mk_elfconfig.c +++ b/scripts/mod/mk_elfconfig.c | |||
| @@ -9,9 +9,6 @@ main(int argc, char **argv) | |||
| 9 | unsigned char ei[EI_NIDENT]; | 9 | unsigned char ei[EI_NIDENT]; |
| 10 | union { short s; char c[2]; } endian_test; | 10 | union { short s; char c[2]; } endian_test; |
| 11 | 11 | ||
| 12 | if (argc != 2) { | ||
| 13 | fprintf(stderr, "Error: no arch\n"); | ||
| 14 | } | ||
| 15 | if (fread(ei, 1, EI_NIDENT, stdin) != EI_NIDENT) { | 12 | if (fread(ei, 1, EI_NIDENT, stdin) != EI_NIDENT) { |
| 16 | fprintf(stderr, "Error: input truncated\n"); | 13 | fprintf(stderr, "Error: input truncated\n"); |
| 17 | return 1; | 14 | return 1; |
| @@ -55,12 +52,6 @@ main(int argc, char **argv) | |||
| 55 | else | 52 | else |
| 56 | exit(1); | 53 | exit(1); |
| 57 | 54 | ||
| 58 | if ((strcmp(argv[1], "h8300") == 0) | ||
| 59 | || (strcmp(argv[1], "blackfin") == 0)) | ||
| 60 | printf("#define MODULE_SYMBOL_PREFIX \"_\"\n"); | ||
| 61 | else | ||
| 62 | printf("#define MODULE_SYMBOL_PREFIX \"\"\n"); | ||
| 63 | |||
| 64 | return 0; | 55 | return 0; |
| 65 | } | 56 | } |
| 66 | 57 | ||
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 801a16a17545..20923613467c 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c | |||
| @@ -15,8 +15,17 @@ | |||
| 15 | #include <stdio.h> | 15 | #include <stdio.h> |
| 16 | #include <ctype.h> | 16 | #include <ctype.h> |
| 17 | #include "modpost.h" | 17 | #include "modpost.h" |
| 18 | #include "../../include/generated/autoconf.h" | ||
| 18 | #include "../../include/linux/license.h" | 19 | #include "../../include/linux/license.h" |
| 19 | 20 | ||
| 21 | /* Some toolchains use a `_' prefix for all user symbols. */ | ||
| 22 | #ifdef CONFIG_SYMBOL_PREFIX | ||
| 23 | #define MODULE_SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX | ||
| 24 | #else | ||
| 25 | #define MODULE_SYMBOL_PREFIX "" | ||
| 26 | #endif | ||
| 27 | |||
| 28 | |||
| 20 | /* Are we using CONFIG_MODVERSIONS? */ | 29 | /* Are we using CONFIG_MODVERSIONS? */ |
| 21 | int modversions = 0; | 30 | int modversions = 0; |
| 22 | /* Warn about undefined symbols? (do so if we have vmlinux) */ | 31 | /* Warn about undefined symbols? (do so if we have vmlinux) */ |
| @@ -451,8 +460,6 @@ static int parse_elf(struct elf_info *info, const char *filename) | |||
| 451 | info->export_unused_gpl_sec = i; | 460 | info->export_unused_gpl_sec = i; |
| 452 | else if (strcmp(secname, "__ksymtab_gpl_future") == 0) | 461 | else if (strcmp(secname, "__ksymtab_gpl_future") == 0) |
| 453 | info->export_gpl_future_sec = i; | 462 | info->export_gpl_future_sec = i; |
| 454 | else if (strcmp(secname, "__markers_strings") == 0) | ||
| 455 | info->markers_strings_sec = i; | ||
| 456 | 463 | ||
| 457 | if (sechdrs[i].sh_type != SHT_SYMTAB) | 464 | if (sechdrs[i].sh_type != SHT_SYMTAB) |
| 458 | continue; | 465 | continue; |
| @@ -515,7 +522,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info, | |||
| 515 | break; | 522 | break; |
| 516 | case SHN_ABS: | 523 | case SHN_ABS: |
| 517 | /* CRC'd symbol */ | 524 | /* CRC'd symbol */ |
| 518 | if (memcmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) { | 525 | if (strncmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) { |
| 519 | crc = (unsigned int) sym->st_value; | 526 | crc = (unsigned int) sym->st_value; |
| 520 | sym_update_crc(symname + strlen(CRC_PFX), mod, crc, | 527 | sym_update_crc(symname + strlen(CRC_PFX), mod, crc, |
| 521 | export); | 528 | export); |
| @@ -559,7 +566,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info, | |||
| 559 | break; | 566 | break; |
| 560 | default: | 567 | default: |
| 561 | /* All exported symbols */ | 568 | /* All exported symbols */ |
| 562 | if (memcmp(symname, KSYMTAB_PFX, strlen(KSYMTAB_PFX)) == 0) { | 569 | if (strncmp(symname, KSYMTAB_PFX, strlen(KSYMTAB_PFX)) == 0) { |
| 563 | sym_add_exported(symname + strlen(KSYMTAB_PFX), mod, | 570 | sym_add_exported(symname + strlen(KSYMTAB_PFX), mod, |
| 564 | export); | 571 | export); |
| 565 | } | 572 | } |
| @@ -1509,62 +1516,6 @@ static void check_sec_ref(struct module *mod, const char *modname, | |||
| 1509 | } | 1516 | } |
| 1510 | } | 1517 | } |
| 1511 | 1518 | ||
| 1512 | static void get_markers(struct elf_info *info, struct module *mod) | ||
| 1513 | { | ||
| 1514 | const Elf_Shdr *sh = &info->sechdrs[info->markers_strings_sec]; | ||
| 1515 | const char *strings = (const char *) info->hdr + sh->sh_offset; | ||
| 1516 | const Elf_Sym *sym, *first_sym, *last_sym; | ||
| 1517 | size_t n; | ||
| 1518 | |||
| 1519 | if (!info->markers_strings_sec) | ||
| 1520 | return; | ||
| 1521 | |||
| 1522 | /* | ||
| 1523 | * First count the strings. We look for all the symbols defined | ||
| 1524 | * in the __markers_strings section named __mstrtab_*. For | ||
| 1525 | * these local names, the compiler puts a random .NNN suffix on, | ||
| 1526 | * so the names don't correspond exactly. | ||
| 1527 | */ | ||
| 1528 | first_sym = last_sym = NULL; | ||
| 1529 | n = 0; | ||
| 1530 | for (sym = info->symtab_start; sym < info->symtab_stop; sym++) | ||
| 1531 | if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT && | ||
| 1532 | sym->st_shndx == info->markers_strings_sec && | ||
| 1533 | !strncmp(info->strtab + sym->st_name, | ||
| 1534 | "__mstrtab_", sizeof "__mstrtab_" - 1)) { | ||
| 1535 | if (first_sym == NULL) | ||
| 1536 | first_sym = sym; | ||
| 1537 | last_sym = sym; | ||
| 1538 | ++n; | ||
| 1539 | } | ||
| 1540 | |||
| 1541 | if (n == 0) | ||
| 1542 | return; | ||
| 1543 | |||
| 1544 | /* | ||
| 1545 | * Now collect each name and format into a line for the output. | ||
| 1546 | * Lines look like: | ||
| 1547 | * marker_name vmlinux marker %s format %d | ||
| 1548 | * The format string after the second \t can use whitespace. | ||
| 1549 | */ | ||
| 1550 | mod->markers = NOFAIL(malloc(sizeof mod->markers[0] * n)); | ||
| 1551 | mod->nmarkers = n; | ||
| 1552 | |||
| 1553 | n = 0; | ||
| 1554 | for (sym = first_sym; sym <= last_sym; sym++) | ||
| 1555 | if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT && | ||
| 1556 | sym->st_shndx == info->markers_strings_sec && | ||
| 1557 | !strncmp(info->strtab + sym->st_name, | ||
| 1558 | "__mstrtab_", sizeof "__mstrtab_" - 1)) { | ||
| 1559 | const char *name = strings + sym->st_value; | ||
| 1560 | const char *fmt = strchr(name, '\0') + 1; | ||
| 1561 | char *line = NULL; | ||
| 1562 | asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt); | ||
| 1563 | NOFAIL(line); | ||
| 1564 | mod->markers[n++] = line; | ||
| 1565 | } | ||
| 1566 | } | ||
| 1567 | |||
| 1568 | static void read_symbols(char *modname) | 1519 | static void read_symbols(char *modname) |
| 1569 | { | 1520 | { |
| 1570 | const char *symname; | 1521 | const char *symname; |
| @@ -1620,8 +1571,6 @@ static void read_symbols(char *modname) | |||
| 1620 | get_src_version(modname, mod->srcversion, | 1571 | get_src_version(modname, mod->srcversion, |
| 1621 | sizeof(mod->srcversion)-1); | 1572 | sizeof(mod->srcversion)-1); |
| 1622 | 1573 | ||
| 1623 | get_markers(&info, mod); | ||
| 1624 | |||
| 1625 | parse_elf_finish(&info); | 1574 | parse_elf_finish(&info); |
| 1626 | 1575 | ||
| 1627 | /* Our trick to get versioning for module struct etc. - it's | 1576 | /* Our trick to get versioning for module struct etc. - it's |
| @@ -1976,96 +1925,6 @@ static void write_dump(const char *fname) | |||
| 1976 | write_if_changed(&buf, fname); | 1925 | write_if_changed(&buf, fname); |
| 1977 | } | 1926 | } |
| 1978 | 1927 | ||
| 1979 | static void add_marker(struct module *mod, const char *name, const char *fmt) | ||
| 1980 | { | ||
| 1981 | char *line = NULL; | ||
| 1982 | asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt); | ||
| 1983 | NOFAIL(line); | ||
| 1984 | |||
| 1985 | mod->markers = NOFAIL(realloc(mod->markers, ((mod->nmarkers + 1) * | ||
| 1986 | sizeof mod->markers[0]))); | ||
| 1987 | mod->markers[mod->nmarkers++] = line; | ||
| 1988 | } | ||
| 1989 | |||
| 1990 | static void read_markers(const char *fname) | ||
| 1991 | { | ||
| 1992 | unsigned long size, pos = 0; | ||
| 1993 | void *file = grab_file(fname, &size); | ||
| 1994 | char *line; | ||
| 1995 | |||
| 1996 | if (!file) /* No old markers, silently ignore */ | ||
| 1997 | return; | ||
| 1998 | |||
| 1999 | while ((line = get_next_line(&pos, file, size))) { | ||
| 2000 | char *marker, *modname, *fmt; | ||
| 2001 | struct module *mod; | ||
| 2002 | |||
| 2003 | marker = line; | ||
| 2004 | modname = strchr(marker, '\t'); | ||
| 2005 | if (!modname) | ||
| 2006 | goto fail; | ||
| 2007 | *modname++ = '\0'; | ||
| 2008 | fmt = strchr(modname, '\t'); | ||
| 2009 | if (!fmt) | ||
| 2010 | goto fail; | ||
| 2011 | *fmt++ = '\0'; | ||
| 2012 | if (*marker == '\0' || *modname == '\0') | ||
| 2013 | goto fail; | ||
| 2014 | |||
| 2015 | mod = find_module(modname); | ||
| 2016 | if (!mod) { | ||
| 2017 | mod = new_module(modname); | ||
| 2018 | mod->skip = 1; | ||
| 2019 | } | ||
| 2020 | if (is_vmlinux(modname)) { | ||
| 2021 | have_vmlinux = 1; | ||
| 2022 | mod->skip = 0; | ||
| 2023 | } | ||
| 2024 | |||
| 2025 | if (!mod->skip) | ||
| 2026 | add_marker(mod, marker, fmt); | ||
| 2027 | } | ||
| 2028 | release_file(file, size); | ||
| 2029 | return; | ||
| 2030 | fail: | ||
| 2031 | fatal("parse error in markers list file\n"); | ||
| 2032 | } | ||
| 2033 | |||
| 2034 | static int compare_strings(const void *a, const void *b) | ||
| 2035 | { | ||
| 2036 | return strcmp(*(const char **) a, *(const char **) b); | ||
| 2037 | } | ||
| 2038 | |||
| 2039 | static void write_markers(const char *fname) | ||
| 2040 | { | ||
| 2041 | struct buffer buf = { }; | ||
| 2042 | struct module *mod; | ||
| 2043 | size_t i; | ||
| 2044 | |||
| 2045 | for (mod = modules; mod; mod = mod->next) | ||
| 2046 | if ((!external_module || !mod->skip) && mod->markers != NULL) { | ||
| 2047 | /* | ||
| 2048 | * Sort the strings so we can skip duplicates when | ||
| 2049 | * we write them out. | ||
| 2050 | */ | ||
| 2051 | qsort(mod->markers, mod->nmarkers, | ||
| 2052 | sizeof mod->markers[0], &compare_strings); | ||
| 2053 | for (i = 0; i < mod->nmarkers; ++i) { | ||
| 2054 | char *line = mod->markers[i]; | ||
| 2055 | buf_write(&buf, line, strlen(line)); | ||
| 2056 | while (i + 1 < mod->nmarkers && | ||
| 2057 | !strcmp(mod->markers[i], | ||
| 2058 | mod->markers[i + 1])) | ||
| 2059 | free(mod->markers[i++]); | ||
| 2060 | free(mod->markers[i]); | ||
| 2061 | } | ||
| 2062 | free(mod->markers); | ||
| 2063 | mod->markers = NULL; | ||
| 2064 | } | ||
| 2065 | |||
| 2066 | write_if_changed(&buf, fname); | ||
| 2067 | } | ||
| 2068 | |||
| 2069 | struct ext_sym_list { | 1928 | struct ext_sym_list { |
| 2070 | struct ext_sym_list *next; | 1929 | struct ext_sym_list *next; |
| 2071 | const char *file; | 1930 | const char *file; |
| @@ -2077,8 +1936,6 @@ int main(int argc, char **argv) | |||
| 2077 | struct buffer buf = { }; | 1936 | struct buffer buf = { }; |
| 2078 | char *kernel_read = NULL, *module_read = NULL; | 1937 | char *kernel_read = NULL, *module_read = NULL; |
| 2079 | char *dump_write = NULL; | 1938 | char *dump_write = NULL; |
| 2080 | char *markers_read = NULL; | ||
| 2081 | char *markers_write = NULL; | ||
| 2082 | int opt; | 1939 | int opt; |
| 2083 | int err; | 1940 | int err; |
| 2084 | struct ext_sym_list *extsym_iter; | 1941 | struct ext_sym_list *extsym_iter; |
| @@ -2122,12 +1979,6 @@ int main(int argc, char **argv) | |||
| 2122 | case 'w': | 1979 | case 'w': |
| 2123 | warn_unresolved = 1; | 1980 | warn_unresolved = 1; |
| 2124 | break; | 1981 | break; |
| 2125 | case 'M': | ||
| 2126 | markers_write = optarg; | ||
| 2127 | break; | ||
| 2128 | case 'K': | ||
| 2129 | markers_read = optarg; | ||
| 2130 | break; | ||
| 2131 | default: | 1982 | default: |
| 2132 | exit(1); | 1983 | exit(1); |
| 2133 | } | 1984 | } |
| @@ -2182,11 +2033,5 @@ int main(int argc, char **argv) | |||
| 2182 | "'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n", | 2033 | "'make CONFIG_DEBUG_SECTION_MISMATCH=y'\n", |
| 2183 | sec_mismatch_count); | 2034 | sec_mismatch_count); |
| 2184 | 2035 | ||
| 2185 | if (markers_read) | ||
| 2186 | read_markers(markers_read); | ||
| 2187 | |||
| 2188 | if (markers_write) | ||
| 2189 | write_markers(markers_write); | ||
| 2190 | |||
| 2191 | return err; | 2036 | return err; |
| 2192 | } | 2037 | } |
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h index 09f58e33d227..be987a44f250 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h | |||
| @@ -112,8 +112,6 @@ struct module { | |||
| 112 | int has_init; | 112 | int has_init; |
| 113 | int has_cleanup; | 113 | int has_cleanup; |
| 114 | struct buffer dev_table_buf; | 114 | struct buffer dev_table_buf; |
| 115 | char **markers; | ||
| 116 | size_t nmarkers; | ||
| 117 | char srcversion[25]; | 115 | char srcversion[25]; |
| 118 | }; | 116 | }; |
| 119 | 117 | ||
| @@ -128,7 +126,6 @@ struct elf_info { | |||
| 128 | Elf_Section export_gpl_sec; | 126 | Elf_Section export_gpl_sec; |
| 129 | Elf_Section export_unused_gpl_sec; | 127 | Elf_Section export_unused_gpl_sec; |
| 130 | Elf_Section export_gpl_future_sec; | 128 | Elf_Section export_gpl_future_sec; |
| 131 | Elf_Section markers_strings_sec; | ||
| 132 | const char *strtab; | 129 | const char *strtab; |
| 133 | char *modinfo; | 130 | char *modinfo; |
| 134 | unsigned int modinfo_len; | 131 | unsigned int modinfo_len; |
diff --git a/scripts/package/Makefile b/scripts/package/Makefile index f67cc885c807..62fcc3a7f4d3 100644 --- a/scripts/package/Makefile +++ b/scripts/package/Makefile | |||
| @@ -77,9 +77,27 @@ clean-files += $(objtree)/binkernel.spec | |||
| 77 | 77 | ||
| 78 | # Deb target | 78 | # Deb target |
| 79 | # --------------------------------------------------------------------------- | 79 | # --------------------------------------------------------------------------- |
| 80 | quiet_cmd_builddeb = BUILDDEB | ||
| 81 | cmd_builddeb = set -e; \ | ||
| 82 | test `id -u` = 0 || \ | ||
| 83 | test -n "$(KBUILD_PKG_ROOTCMD)" || { \ | ||
| 84 | which fakeroot >/dev/null 2>&1 && \ | ||
| 85 | KBUILD_PKG_ROOTCMD="fakeroot -u"; \ | ||
| 86 | } || { \ | ||
| 87 | echo; \ | ||
| 88 | echo "builddeb must be run as root (or using fakeroot)."; \ | ||
| 89 | echo "KBUILD_PKG_ROOTCMD is unset and fakeroot not found."; \ | ||
| 90 | echo "Try setting KBUILD_PKG_ROOTCMD to a command to acquire"; \ | ||
| 91 | echo "root privileges (e.g., 'fakeroot -u' or 'sudo')."; \ | ||
| 92 | false; \ | ||
| 93 | } && \ | ||
| 94 | \ | ||
| 95 | $$KBUILD_PKG_ROOTCMD $(CONFIG_SHELL) \ | ||
| 96 | $(srctree)/scripts/package/builddeb | ||
| 97 | |||
| 80 | deb-pkg: FORCE | 98 | deb-pkg: FORCE |
| 81 | $(MAKE) KBUILD_SRC= | 99 | $(MAKE) KBUILD_SRC= |
| 82 | $(CONFIG_SHELL) $(srctree)/scripts/package/builddeb | 100 | $(call cmd,builddeb) |
| 83 | 101 | ||
| 84 | clean-dirs += $(objtree)/debian/ | 102 | clean-dirs += $(objtree)/debian/ |
| 85 | 103 | ||
diff --git a/scripts/package/buildtar b/scripts/package/buildtar index b1fd48db1640..51b2aa0acb82 100644 --- a/scripts/package/buildtar +++ b/scripts/package/buildtar | |||
| @@ -101,7 +101,11 @@ esac | |||
| 101 | # | 101 | # |
| 102 | ( | 102 | ( |
| 103 | cd "${tmpdir}" | 103 | cd "${tmpdir}" |
| 104 | tar cf - . | ${compress} > "${tarball}${file_ext}" | 104 | opts= |
| 105 | if tar --owner=root --group=root --help >/dev/null 2>&1; then | ||
| 106 | opts="--owner=root --group=root" | ||
| 107 | fi | ||
| 108 | tar cf - . $opts | ${compress} > "${tarball}${file_ext}" | ||
| 105 | ) | 109 | ) |
| 106 | 110 | ||
| 107 | echo "Tarball successfully created in ${tarball}${file_ext}" | 111 | echo "Tarball successfully created in ${tarball}${file_ext}" |
diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl index 090d300d7394..92f09fe9639e 100755 --- a/scripts/recordmcount.pl +++ b/scripts/recordmcount.pl | |||
| @@ -6,77 +6,93 @@ | |||
| 6 | # all the offsets to the calls to mcount. | 6 | # all the offsets to the calls to mcount. |
| 7 | # | 7 | # |
| 8 | # | 8 | # |
| 9 | # What we want to end up with is a section in vmlinux called | 9 | # What we want to end up with this is that each object file will have a |
| 10 | # __mcount_loc that contains a list of pointers to all the | 10 | # section called __mcount_loc that will hold the list of pointers to mcount |
| 11 | # call sites in the kernel that call mcount. Later on boot up, the kernel | 11 | # callers. After final linking, the vmlinux will have within .init.data the |
| 12 | # will read this list, save the locations and turn them into nops. | 12 | # list of all callers to mcount between __start_mcount_loc and __stop_mcount_loc. |
| 13 | # When tracing or profiling is later enabled, these locations will then | 13 | # Later on boot up, the kernel will read this list, save the locations and turn |
| 14 | # be converted back to pointers to some function. | 14 | # them into nops. When tracing or profiling is later enabled, these locations |
| 15 | # will then be converted back to pointers to some function. | ||
| 15 | # | 16 | # |
| 16 | # This is no easy feat. This script is called just after the original | 17 | # This is no easy feat. This script is called just after the original |
| 17 | # object is compiled and before it is linked. | 18 | # object is compiled and before it is linked. |
| 18 | # | 19 | # |
| 19 | # The references to the call sites are offsets from the section of text | 20 | # When parse this object file using 'objdump', the references to the call |
| 20 | # that the call site is in. Hence, all functions in a section that | 21 | # sites are offsets from the section that the call site is in. Hence, all |
| 21 | # has a call site to mcount, will have the offset from the beginning of | 22 | # functions in a section that has a call site to mcount, will have the |
| 22 | # the section and not the beginning of the function. | 23 | # offset from the beginning of the section and not the beginning of the |
| 24 | # function. | ||
| 25 | # | ||
| 26 | # But where this section will reside finally in vmlinx is undetermined at | ||
| 27 | # this point. So we can't use this kind of offsets to record the final | ||
| 28 | # address of this call site. | ||
| 29 | # | ||
| 30 | # The trick is to change the call offset referring the start of a section to | ||
| 31 | # referring a function symbol in this section. During the link step, 'ld' will | ||
| 32 | # compute the final address according to the information we record. | ||
| 23 | # | 33 | # |
| 24 | # The trick is to find a way to record the beginning of the section. | ||
| 25 | # The way we do this is to look at the first function in the section | ||
| 26 | # which will also be the location of that section after final link. | ||
| 27 | # e.g. | 34 | # e.g. |
| 28 | # | 35 | # |
| 29 | # .section ".sched.text", "ax" | 36 | # .section ".sched.text", "ax" |
| 30 | # .globl my_func | ||
| 31 | # my_func: | ||
| 32 | # [...] | 37 | # [...] |
| 33 | # call mcount (offset: 0x5) | 38 | # func1: |
| 39 | # [...] | ||
| 40 | # call mcount (offset: 0x10) | ||
| 34 | # [...] | 41 | # [...] |
| 35 | # ret | 42 | # ret |
| 36 | # other_func: | 43 | # .globl fun2 |
| 44 | # func2: (offset: 0x20) | ||
| 37 | # [...] | 45 | # [...] |
| 38 | # call mcount (offset: 0x1b) | 46 | # [...] |
| 47 | # ret | ||
| 48 | # func3: | ||
| 49 | # [...] | ||
| 50 | # call mcount (offset: 0x30) | ||
| 39 | # [...] | 51 | # [...] |
| 40 | # | 52 | # |
| 41 | # Both relocation offsets for the mcounts in the above example will be | 53 | # Both relocation offsets for the mcounts in the above example will be |
| 42 | # offset from .sched.text. If we make another file called tmp.s with: | 54 | # offset from .sched.text. If we choose global symbol func2 as a reference and |
| 55 | # make another file called tmp.s with the new offsets: | ||
| 43 | # | 56 | # |
| 44 | # .section __mcount_loc | 57 | # .section __mcount_loc |
| 45 | # .quad my_func + 0x5 | 58 | # .quad func2 - 0x10 |
| 46 | # .quad my_func + 0x1b | 59 | # .quad func2 + 0x10 |
| 47 | # | 60 | # |
| 48 | # We can then compile this tmp.s into tmp.o, and link it to the original | 61 | # We can then compile this tmp.s into tmp.o, and link it back to the original |
| 49 | # object. | 62 | # object. |
| 50 | # | 63 | # |
| 51 | # But this gets hard if my_func is not globl (a static function). | 64 | # In our algorithm, we will choose the first global function we meet in this |
| 52 | # In such a case we have: | 65 | # section as the reference. But this gets hard if there is no global functions |
| 66 | # in this section. In such a case we have to select a local one. E.g. func1: | ||
| 53 | # | 67 | # |
| 54 | # .section ".sched.text", "ax" | 68 | # .section ".sched.text", "ax" |
| 55 | # my_func: | 69 | # func1: |
| 56 | # [...] | 70 | # [...] |
| 57 | # call mcount (offset: 0x5) | 71 | # call mcount (offset: 0x10) |
| 58 | # [...] | 72 | # [...] |
| 59 | # ret | 73 | # ret |
| 60 | # other_func: | 74 | # func2: |
| 61 | # [...] | 75 | # [...] |
| 62 | # call mcount (offset: 0x1b) | 76 | # call mcount (offset: 0x20) |
| 63 | # [...] | 77 | # [...] |
| 78 | # .section "other.section" | ||
| 64 | # | 79 | # |
| 65 | # If we make the tmp.s the same as above, when we link together with | 80 | # If we make the tmp.s the same as above, when we link together with |
| 66 | # the original object, we will end up with two symbols for my_func: | 81 | # the original object, we will end up with two symbols for func1: |
| 67 | # one local, one global. After final compile, we will end up with | 82 | # one local, one global. After final compile, we will end up with |
| 68 | # an undefined reference to my_func. | 83 | # an undefined reference to func1 or a wrong reference to another global |
| 84 | # func1 in other files. | ||
| 69 | # | 85 | # |
| 70 | # Since local objects can reference local variables, we need to find | 86 | # Since local objects can reference local variables, we need to find |
| 71 | # a way to make tmp.o reference the local objects of the original object | 87 | # a way to make tmp.o reference the local objects of the original object |
| 72 | # file after it is linked together. To do this, we convert the my_func | 88 | # file after it is linked together. To do this, we convert func1 |
| 73 | # into a global symbol before linking tmp.o. Then after we link tmp.o | 89 | # into a global symbol before linking tmp.o. Then after we link tmp.o |
| 74 | # we will only have a single symbol for my_func that is global. | 90 | # we will only have a single symbol for func1 that is global. |
| 75 | # We can convert my_func back into a local symbol and we are done. | 91 | # We can convert func1 back into a local symbol and we are done. |
| 76 | # | 92 | # |
| 77 | # Here are the steps we take: | 93 | # Here are the steps we take: |
| 78 | # | 94 | # |
| 79 | # 1) Record all the local symbols by using 'nm' | 95 | # 1) Record all the local and weak symbols by using 'nm' |
| 80 | # 2) Use objdump to find all the call site offsets and sections for | 96 | # 2) Use objdump to find all the call site offsets and sections for |
| 81 | # mcount. | 97 | # mcount. |
| 82 | # 3) Compile the list into its own object. | 98 | # 3) Compile the list into its own object. |
| @@ -86,10 +102,8 @@ | |||
| 86 | # 6) Link together this new object with the list object. | 102 | # 6) Link together this new object with the list object. |
| 87 | # 7) Convert the local functions back to local symbols and rename | 103 | # 7) Convert the local functions back to local symbols and rename |
| 88 | # the result as the original object. | 104 | # the result as the original object. |
| 89 | # End. | ||
| 90 | # 8) Link the object with the list object. | 105 | # 8) Link the object with the list object. |
| 91 | # 9) Move the result back to the original object. | 106 | # 9) Move the result back to the original object. |
| 92 | # End. | ||
| 93 | # | 107 | # |
| 94 | 108 | ||
| 95 | use strict; | 109 | use strict; |
| @@ -99,17 +113,17 @@ $P =~ s@.*/@@g; | |||
| 99 | 113 | ||
| 100 | my $V = '0.1'; | 114 | my $V = '0.1'; |
| 101 | 115 | ||
| 102 | if ($#ARGV < 7) { | 116 | if ($#ARGV != 11) { |
| 103 | print "usage: $P arch bits objdump objcopy cc ld nm rm mv is_module inputfile\n"; | 117 | print "usage: $P arch endian bits objdump objcopy cc ld nm rm mv is_module inputfile\n"; |
| 104 | print "version: $V\n"; | 118 | print "version: $V\n"; |
| 105 | exit(1); | 119 | exit(1); |
| 106 | } | 120 | } |
| 107 | 121 | ||
| 108 | my ($arch, $bits, $objdump, $objcopy, $cc, | 122 | my ($arch, $endian, $bits, $objdump, $objcopy, $cc, |
| 109 | $ld, $nm, $rm, $mv, $is_module, $inputfile) = @ARGV; | 123 | $ld, $nm, $rm, $mv, $is_module, $inputfile) = @ARGV; |
| 110 | 124 | ||
| 111 | # This file refers to mcount and shouldn't be ftraced, so lets' ignore it | 125 | # This file refers to mcount and shouldn't be ftraced, so lets' ignore it |
| 112 | if ($inputfile eq "kernel/trace/ftrace.o") { | 126 | if ($inputfile =~ m,kernel/trace/ftrace\.o$,) { |
| 113 | exit(0); | 127 | exit(0); |
| 114 | } | 128 | } |
| 115 | 129 | ||
| @@ -119,6 +133,7 @@ my %text_sections = ( | |||
| 119 | ".sched.text" => 1, | 133 | ".sched.text" => 1, |
| 120 | ".spinlock.text" => 1, | 134 | ".spinlock.text" => 1, |
| 121 | ".irqentry.text" => 1, | 135 | ".irqentry.text" => 1, |
| 136 | ".text.unlikely" => 1, | ||
| 122 | ); | 137 | ); |
| 123 | 138 | ||
| 124 | $objdump = "objdump" if ((length $objdump) == 0); | 139 | $objdump = "objdump" if ((length $objdump) == 0); |
| @@ -137,13 +152,47 @@ my %weak; # List of weak functions | |||
| 137 | my %convert; # List of local functions used that needs conversion | 152 | my %convert; # List of local functions used that needs conversion |
| 138 | 153 | ||
| 139 | my $type; | 154 | my $type; |
| 140 | my $nm_regex; # Find the local functions (return function) | 155 | my $local_regex; # Match a local function (return function) |
| 156 | my $weak_regex; # Match a weak function (return function) | ||
| 141 | my $section_regex; # Find the start of a section | 157 | my $section_regex; # Find the start of a section |
| 142 | my $function_regex; # Find the name of a function | 158 | my $function_regex; # Find the name of a function |
| 143 | # (return offset and func name) | 159 | # (return offset and func name) |
| 144 | my $mcount_regex; # Find the call site to mcount (return offset) | 160 | my $mcount_regex; # Find the call site to mcount (return offset) |
| 145 | my $alignment; # The .align value to use for $mcount_section | 161 | my $alignment; # The .align value to use for $mcount_section |
| 146 | my $section_type; # Section header plus possible alignment command | 162 | my $section_type; # Section header plus possible alignment command |
| 163 | my $can_use_local = 0; # If we can use local function references | ||
| 164 | |||
| 165 | # Shut up recordmcount if user has older objcopy | ||
| 166 | my $quiet_recordmcount = ".tmp_quiet_recordmcount"; | ||
| 167 | my $print_warning = 1; | ||
| 168 | $print_warning = 0 if ( -f $quiet_recordmcount); | ||
| 169 | |||
| 170 | ## | ||
| 171 | # check_objcopy - whether objcopy supports --globalize-symbols | ||
| 172 | # | ||
| 173 | # --globalize-symbols came out in 2.17, we must test the version | ||
| 174 | # of objcopy, and if it is less than 2.17, then we can not | ||
| 175 | # record local functions. | ||
| 176 | sub check_objcopy | ||
| 177 | { | ||
| 178 | open (IN, "$objcopy --version |") or die "error running $objcopy"; | ||
| 179 | while (<IN>) { | ||
| 180 | if (/objcopy.*\s(\d+)\.(\d+)/) { | ||
| 181 | $can_use_local = 1 if ($1 > 2 || ($1 == 2 && $2 >= 17)); | ||
| 182 | last; | ||
| 183 | } | ||
| 184 | } | ||
| 185 | close (IN); | ||
| 186 | |||
| 187 | if (!$can_use_local && $print_warning) { | ||
| 188 | print STDERR "WARNING: could not find objcopy version or version " . | ||
| 189 | "is less than 2.17.\n" . | ||
| 190 | "\tLocal function references are disabled.\n"; | ||
| 191 | open (QUIET, ">$quiet_recordmcount"); | ||
| 192 | printf QUIET "Disables the warning from recordmcount.pl\n"; | ||
| 193 | close QUIET; | ||
| 194 | } | ||
| 195 | } | ||
| 147 | 196 | ||
| 148 | if ($arch eq "x86") { | 197 | if ($arch eq "x86") { |
| 149 | if ($bits == 64) { | 198 | if ($bits == 64) { |
| @@ -157,7 +206,8 @@ if ($arch eq "x86") { | |||
| 157 | # We base the defaults off of i386, the other archs may | 206 | # We base the defaults off of i386, the other archs may |
| 158 | # feel free to change them in the below if statements. | 207 | # feel free to change them in the below if statements. |
| 159 | # | 208 | # |
| 160 | $nm_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\S+)"; | 209 | $local_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\S+)"; |
| 210 | $weak_regex = "^[0-9a-fA-F]+\\s+([wW])\\s+(\\S+)"; | ||
| 161 | $section_regex = "Disassembly of section\\s+(\\S+):"; | 211 | $section_regex = "Disassembly of section\\s+(\\S+):"; |
| 162 | $function_regex = "^([0-9a-fA-F]+)\\s+<(.*?)>:"; | 212 | $function_regex = "^([0-9a-fA-F]+)\\s+<(.*?)>:"; |
| 163 | $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\smcount\$"; | 213 | $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\smcount\$"; |
| @@ -206,7 +256,7 @@ if ($arch eq "x86_64") { | |||
| 206 | $cc .= " -m32"; | 256 | $cc .= " -m32"; |
| 207 | 257 | ||
| 208 | } elsif ($arch eq "powerpc") { | 258 | } elsif ($arch eq "powerpc") { |
| 209 | $nm_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\.?\\S+)"; | 259 | $local_regex = "^[0-9a-fA-F]+\\s+t\\s+(\\.?\\S+)"; |
| 210 | $function_regex = "^([0-9a-fA-F]+)\\s+<(\\.?.*?)>:"; | 260 | $function_regex = "^([0-9a-fA-F]+)\\s+<(\\.?.*?)>:"; |
| 211 | $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s\\.?_mcount\$"; | 261 | $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s\\.?_mcount\$"; |
| 212 | 262 | ||
| @@ -245,6 +295,61 @@ if ($arch eq "x86_64") { | |||
| 245 | $ld .= " -m elf64_sparc"; | 295 | $ld .= " -m elf64_sparc"; |
| 246 | $cc .= " -m64"; | 296 | $cc .= " -m64"; |
| 247 | $objcopy .= " -O elf64-sparc"; | 297 | $objcopy .= " -O elf64-sparc"; |
| 298 | } elsif ($arch eq "mips") { | ||
| 299 | # To enable module support, we need to enable the -mlong-calls option | ||
| 300 | # of gcc for module, after using this option, we can not get the real | ||
| 301 | # offset of the calling to _mcount, but the offset of the lui | ||
| 302 | # instruction or the addiu one. herein, we record the address of the | ||
| 303 | # first one, and then we can replace this instruction by a branch | ||
| 304 | # instruction to jump over the profiling function to filter the | ||
| 305 | # indicated functions, or swith back to the lui instruction to trace | ||
| 306 | # them, which means dynamic tracing. | ||
| 307 | # | ||
| 308 | # c: 3c030000 lui v1,0x0 | ||
| 309 | # c: R_MIPS_HI16 _mcount | ||
| 310 | # c: R_MIPS_NONE *ABS* | ||
| 311 | # c: R_MIPS_NONE *ABS* | ||
| 312 | # 10: 64630000 daddiu v1,v1,0 | ||
| 313 | # 10: R_MIPS_LO16 _mcount | ||
| 314 | # 10: R_MIPS_NONE *ABS* | ||
| 315 | # 10: R_MIPS_NONE *ABS* | ||
| 316 | # 14: 03e0082d move at,ra | ||
| 317 | # 18: 0060f809 jalr v1 | ||
| 318 | # | ||
| 319 | # for the kernel: | ||
| 320 | # | ||
| 321 | # 10: 03e0082d move at,ra | ||
| 322 | # 14: 0c000000 jal 0 <loongson_halt> | ||
| 323 | # 14: R_MIPS_26 _mcount | ||
| 324 | # 14: R_MIPS_NONE *ABS* | ||
| 325 | # 14: R_MIPS_NONE *ABS* | ||
| 326 | # 18: 00020021 nop | ||
| 327 | if ($is_module eq "0") { | ||
| 328 | $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$"; | ||
| 329 | } else { | ||
| 330 | $mcount_regex = "^\\s*([0-9a-fA-F]+): R_MIPS_HI16\\s+_mcount\$"; | ||
| 331 | } | ||
| 332 | $objdump .= " -Melf-trad".$endian."mips "; | ||
| 333 | |||
| 334 | if ($endian eq "big") { | ||
| 335 | $endian = " -EB "; | ||
| 336 | $ld .= " -melf".$bits."btsmip"; | ||
| 337 | } else { | ||
| 338 | $endian = " -EL "; | ||
| 339 | $ld .= " -melf".$bits."ltsmip"; | ||
| 340 | } | ||
| 341 | |||
| 342 | $cc .= " -mno-abicalls -fno-pic -mabi=" . $bits . $endian; | ||
| 343 | $ld .= $endian; | ||
| 344 | |||
| 345 | if ($bits == 64) { | ||
| 346 | $function_regex = | ||
| 347 | "^([0-9a-fA-F]+)\\s+<(.|[^\$]L.*?|\$[^L].*?|[^\$][^L].*?)>:"; | ||
| 348 | $type = ".dword"; | ||
| 349 | } | ||
| 350 | } elsif ($arch eq "microblaze") { | ||
| 351 | # Microblaze calls '_mcount' instead of plain 'mcount'. | ||
| 352 | $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$"; | ||
| 248 | } else { | 353 | } else { |
| 249 | die "Arch $arch is not supported with CONFIG_FTRACE_MCOUNT_RECORD"; | 354 | die "Arch $arch is not supported with CONFIG_FTRACE_MCOUNT_RECORD"; |
| 250 | } | 355 | } |
| @@ -278,44 +383,17 @@ if ($filename =~ m,^(.*)(\.\S),) { | |||
| 278 | my $mcount_s = $dirname . "/.tmp_mc_" . $prefix . ".s"; | 383 | my $mcount_s = $dirname . "/.tmp_mc_" . $prefix . ".s"; |
| 279 | my $mcount_o = $dirname . "/.tmp_mc_" . $prefix . ".o"; | 384 | my $mcount_o = $dirname . "/.tmp_mc_" . $prefix . ".o"; |
| 280 | 385 | ||
| 281 | # | 386 | check_objcopy(); |
| 282 | # --globalize-symbols came out in 2.17, we must test the version | ||
| 283 | # of objcopy, and if it is less than 2.17, then we can not | ||
| 284 | # record local functions. | ||
| 285 | my $use_locals = 01; | ||
| 286 | my $local_warn_once = 0; | ||
| 287 | my $found_version = 0; | ||
| 288 | |||
| 289 | open (IN, "$objcopy --version |") || die "error running $objcopy"; | ||
| 290 | while (<IN>) { | ||
| 291 | if (/objcopy.*\s(\d+)\.(\d+)/) { | ||
| 292 | my $major = $1; | ||
| 293 | my $minor = $2; | ||
| 294 | |||
| 295 | $found_version = 1; | ||
| 296 | if ($major < 2 || | ||
| 297 | ($major == 2 && $minor < 17)) { | ||
| 298 | $use_locals = 0; | ||
| 299 | } | ||
| 300 | last; | ||
| 301 | } | ||
| 302 | } | ||
| 303 | close (IN); | ||
| 304 | |||
| 305 | if (!$found_version) { | ||
| 306 | print STDERR "WARNING: could not find objcopy version.\n" . | ||
| 307 | "\tDisabling local function references.\n"; | ||
| 308 | } | ||
| 309 | 387 | ||
| 310 | # | 388 | # |
| 311 | # Step 1: find all the local (static functions) and weak symbols. | 389 | # Step 1: find all the local (static functions) and weak symbols. |
| 312 | # 't' is local, 'w/W' is weak (we never use a weak function) | 390 | # 't' is local, 'w/W' is weak |
| 313 | # | 391 | # |
| 314 | open (IN, "$nm $inputfile|") || die "error running $nm"; | 392 | open (IN, "$nm $inputfile|") || die "error running $nm"; |
| 315 | while (<IN>) { | 393 | while (<IN>) { |
| 316 | if (/$nm_regex/) { | 394 | if (/$local_regex/) { |
| 317 | $locals{$1} = 1; | 395 | $locals{$1} = 1; |
| 318 | } elsif (/^[0-9a-fA-F]+\s+([wW])\s+(\S+)/) { | 396 | } elsif (/$weak_regex/) { |
| 319 | $weak{$2} = $1; | 397 | $weak{$2} = $1; |
| 320 | } | 398 | } |
| 321 | } | 399 | } |
| @@ -333,26 +411,20 @@ my $offset = 0; # offset of ref_func to section beginning | |||
| 333 | # | 411 | # |
| 334 | sub update_funcs | 412 | sub update_funcs |
| 335 | { | 413 | { |
| 336 | return if ($#offsets < 0); | 414 | return unless ($ref_func and @offsets); |
| 337 | 415 | ||
| 338 | defined($ref_func) || die "No function to reference"; | 416 | # Sanity check on weak function. A weak function may be overwritten by |
| 339 | 417 | # another function of the same name, making all these offsets incorrect. | |
| 340 | # A section only had a weak function, to represent it. | ||
| 341 | # Unfortunately, a weak function may be overwritten by another | ||
| 342 | # function of the same name, making all these offsets incorrect. | ||
| 343 | # To be safe, we simply print a warning and bail. | ||
| 344 | if (defined $weak{$ref_func}) { | 418 | if (defined $weak{$ref_func}) { |
| 345 | print STDERR | 419 | die "$inputfile: ERROR: referencing weak function" . |
| 346 | "$inputfile: WARNING: referencing weak function" . | ||
| 347 | " $ref_func for mcount\n"; | 420 | " $ref_func for mcount\n"; |
| 348 | return; | ||
| 349 | } | 421 | } |
| 350 | 422 | ||
| 351 | # is this function static? If so, note this fact. | 423 | # is this function static? If so, note this fact. |
| 352 | if (defined $locals{$ref_func}) { | 424 | if (defined $locals{$ref_func}) { |
| 353 | 425 | ||
| 354 | # only use locals if objcopy supports globalize-symbols | 426 | # only use locals if objcopy supports globalize-symbols |
| 355 | if (!$use_locals) { | 427 | if (!$can_use_local) { |
| 356 | return; | 428 | return; |
| 357 | } | 429 | } |
| 358 | $convert{$ref_func} = 1; | 430 | $convert{$ref_func} = 1; |
| @@ -378,9 +450,27 @@ open(IN, "$objdump -hdr $inputfile|") || die "error running $objdump"; | |||
| 378 | 450 | ||
| 379 | my $text; | 451 | my $text; |
| 380 | 452 | ||
| 453 | |||
| 454 | # read headers first | ||
| 381 | my $read_headers = 1; | 455 | my $read_headers = 1; |
| 382 | 456 | ||
| 383 | while (<IN>) { | 457 | while (<IN>) { |
| 458 | |||
| 459 | if ($read_headers && /$mcount_section/) { | ||
| 460 | # | ||
| 461 | # Somehow the make process can execute this script on an | ||
| 462 | # object twice. If it does, we would duplicate the mcount | ||
| 463 | # section and it will cause the function tracer self test | ||
| 464 | # to fail. Check if the mcount section exists, and if it does, | ||
| 465 | # warn and exit. | ||
| 466 | # | ||
| 467 | print STDERR "ERROR: $mcount_section already in $inputfile\n" . | ||
| 468 | "\tThis may be an indication that your build is corrupted.\n" . | ||
| 469 | "\tDelete $inputfile and try again. If the same object file\n" . | ||
| 470 | "\tstill causes an issue, then disable CONFIG_DYNAMIC_FTRACE.\n"; | ||
| 471 | exit(-1); | ||
| 472 | } | ||
| 473 | |||
| 384 | # is it a section? | 474 | # is it a section? |
| 385 | if (/$section_regex/) { | 475 | if (/$section_regex/) { |
| 386 | $read_headers = 0; | 476 | $read_headers = 0; |
| @@ -392,7 +482,7 @@ while (<IN>) { | |||
| 392 | $read_function = 0; | 482 | $read_function = 0; |
| 393 | } | 483 | } |
| 394 | # print out any recorded offsets | 484 | # print out any recorded offsets |
| 395 | update_funcs() if (defined($ref_func)); | 485 | update_funcs(); |
| 396 | 486 | ||
| 397 | # reset all markers and arrays | 487 | # reset all markers and arrays |
| 398 | $text_found = 0; | 488 | $text_found = 0; |
| @@ -421,21 +511,7 @@ while (<IN>) { | |||
| 421 | $offset = hex $1; | 511 | $offset = hex $1; |
| 422 | } | 512 | } |
| 423 | } | 513 | } |
| 424 | } elsif ($read_headers && /$mcount_section/) { | ||
| 425 | # | ||
| 426 | # Somehow the make process can execute this script on an | ||
| 427 | # object twice. If it does, we would duplicate the mcount | ||
| 428 | # section and it will cause the function tracer self test | ||
| 429 | # to fail. Check if the mcount section exists, and if it does, | ||
| 430 | # warn and exit. | ||
| 431 | # | ||
| 432 | print STDERR "ERROR: $mcount_section already in $inputfile\n" . | ||
| 433 | "\tThis may be an indication that your build is corrupted.\n" . | ||
| 434 | "\tDelete $inputfile and try again. If the same object file\n" . | ||
| 435 | "\tstill causes an issue, then disable CONFIG_DYNAMIC_FTRACE.\n"; | ||
| 436 | exit(-1); | ||
| 437 | } | 514 | } |
| 438 | |||
| 439 | # is this a call site to mcount? If so, record it to print later | 515 | # is this a call site to mcount? If so, record it to print later |
| 440 | if ($text_found && /$mcount_regex/) { | 516 | if ($text_found && /$mcount_regex/) { |
| 441 | $offsets[$#offsets + 1] = hex $1; | 517 | $offsets[$#offsets + 1] = hex $1; |
| @@ -443,7 +519,7 @@ while (<IN>) { | |||
| 443 | } | 519 | } |
| 444 | 520 | ||
| 445 | # dump out anymore offsets that may have been found | 521 | # dump out anymore offsets that may have been found |
| 446 | update_funcs() if (defined($ref_func)); | 522 | update_funcs(); |
| 447 | 523 | ||
| 448 | # If we did not find any mcount callers, we are done (do nothing). | 524 | # If we did not find any mcount callers, we are done (do nothing). |
| 449 | if (!$opened) { | 525 | if (!$opened) { |
diff --git a/scripts/selinux/Makefile b/scripts/selinux/Makefile index ca4b1ec01822..e8049da1831f 100644 --- a/scripts/selinux/Makefile +++ b/scripts/selinux/Makefile | |||
| @@ -1,2 +1,2 @@ | |||
| 1 | subdir-y := mdp | 1 | subdir-y := mdp genheaders |
| 2 | subdir- += mdp | 2 | subdir- += mdp genheaders |
diff --git a/scripts/selinux/genheaders/.gitignore b/scripts/selinux/genheaders/.gitignore new file mode 100644 index 000000000000..4c0b646ff8d5 --- /dev/null +++ b/scripts/selinux/genheaders/.gitignore | |||
| @@ -0,0 +1 @@ | |||
| genheaders | |||
diff --git a/scripts/selinux/genheaders/Makefile b/scripts/selinux/genheaders/Makefile new file mode 100644 index 000000000000..417b165008ee --- /dev/null +++ b/scripts/selinux/genheaders/Makefile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | hostprogs-y := genheaders | ||
| 2 | HOST_EXTRACFLAGS += -Isecurity/selinux/include | ||
| 3 | |||
| 4 | always := $(hostprogs-y) | ||
| 5 | clean-files := $(hostprogs-y) | ||
diff --git a/scripts/selinux/genheaders/genheaders.c b/scripts/selinux/genheaders/genheaders.c new file mode 100644 index 000000000000..24626968055d --- /dev/null +++ b/scripts/selinux/genheaders/genheaders.c | |||
| @@ -0,0 +1,118 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include <errno.h> | ||
| 6 | #include <ctype.h> | ||
| 7 | |||
| 8 | struct security_class_mapping { | ||
| 9 | const char *name; | ||
| 10 | const char *perms[sizeof(unsigned) * 8 + 1]; | ||
| 11 | }; | ||
| 12 | |||
| 13 | #include "classmap.h" | ||
| 14 | #include "initial_sid_to_string.h" | ||
| 15 | |||
| 16 | #define max(x, y) (((int)(x) > (int)(y)) ? x : y) | ||
| 17 | |||
| 18 | const char *progname; | ||
| 19 | |||
| 20 | static void usage(void) | ||
| 21 | { | ||
| 22 | printf("usage: %s flask.h av_permissions.h\n", progname); | ||
| 23 | exit(1); | ||
| 24 | } | ||
| 25 | |||
| 26 | static char *stoupperx(const char *s) | ||
| 27 | { | ||
| 28 | char *s2 = strdup(s); | ||
| 29 | char *p; | ||
| 30 | |||
| 31 | if (!s2) { | ||
| 32 | fprintf(stderr, "%s: out of memory\n", progname); | ||
| 33 | exit(3); | ||
| 34 | } | ||
| 35 | |||
| 36 | for (p = s2; *p; p++) | ||
| 37 | *p = toupper(*p); | ||
| 38 | return s2; | ||
| 39 | } | ||
| 40 | |||
| 41 | int main(int argc, char *argv[]) | ||
| 42 | { | ||
| 43 | int i, j, k; | ||
| 44 | int isids_len; | ||
| 45 | FILE *fout; | ||
| 46 | |||
| 47 | progname = argv[0]; | ||
| 48 | |||
| 49 | if (argc < 3) | ||
| 50 | usage(); | ||
| 51 | |||
| 52 | fout = fopen(argv[1], "w"); | ||
| 53 | if (!fout) { | ||
| 54 | fprintf(stderr, "Could not open %s for writing: %s\n", | ||
| 55 | argv[1], strerror(errno)); | ||
| 56 | exit(2); | ||
| 57 | } | ||
| 58 | |||
| 59 | for (i = 0; secclass_map[i].name; i++) { | ||
| 60 | struct security_class_mapping *map = &secclass_map[i]; | ||
| 61 | map->name = stoupperx(map->name); | ||
| 62 | for (j = 0; map->perms[j]; j++) | ||
| 63 | map->perms[j] = stoupperx(map->perms[j]); | ||
| 64 | } | ||
| 65 | |||
| 66 | isids_len = sizeof(initial_sid_to_string) / sizeof (char *); | ||
| 67 | for (i = 1; i < isids_len; i++) | ||
| 68 | initial_sid_to_string[i] = stoupperx(initial_sid_to_string[i]); | ||
| 69 | |||
| 70 | fprintf(fout, "/* This file is automatically generated. Do not edit. */\n"); | ||
| 71 | fprintf(fout, "#ifndef _SELINUX_FLASK_H_\n#define _SELINUX_FLASK_H_\n\n"); | ||
| 72 | |||
| 73 | for (i = 0; secclass_map[i].name; i++) { | ||
| 74 | struct security_class_mapping *map = &secclass_map[i]; | ||
| 75 | fprintf(fout, "#define SECCLASS_%s", map->name); | ||
| 76 | for (j = 0; j < max(1, 40 - strlen(map->name)); j++) | ||
| 77 | fprintf(fout, " "); | ||
| 78 | fprintf(fout, "%2d\n", i+1); | ||
| 79 | } | ||
| 80 | |||
| 81 | fprintf(fout, "\n"); | ||
| 82 | |||
| 83 | for (i = 1; i < isids_len; i++) { | ||
| 84 | char *s = initial_sid_to_string[i]; | ||
| 85 | fprintf(fout, "#define SECINITSID_%s", s); | ||
| 86 | for (j = 0; j < max(1, 40 - strlen(s)); j++) | ||
| 87 | fprintf(fout, " "); | ||
| 88 | fprintf(fout, "%2d\n", i); | ||
| 89 | } | ||
| 90 | fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1); | ||
| 91 | fprintf(fout, "\n#endif\n"); | ||
| 92 | fclose(fout); | ||
| 93 | |||
| 94 | fout = fopen(argv[2], "w"); | ||
| 95 | if (!fout) { | ||
| 96 | fprintf(stderr, "Could not open %s for writing: %s\n", | ||
| 97 | argv[2], strerror(errno)); | ||
| 98 | exit(4); | ||
| 99 | } | ||
| 100 | |||
| 101 | fprintf(fout, "/* This file is automatically generated. Do not edit. */\n"); | ||
| 102 | fprintf(fout, "#ifndef _SELINUX_AV_PERMISSIONS_H_\n#define _SELINUX_AV_PERMISSIONS_H_\n\n"); | ||
| 103 | |||
| 104 | for (i = 0; secclass_map[i].name; i++) { | ||
| 105 | struct security_class_mapping *map = &secclass_map[i]; | ||
| 106 | for (j = 0; map->perms[j]; j++) { | ||
| 107 | fprintf(fout, "#define %s__%s", map->name, | ||
| 108 | map->perms[j]); | ||
| 109 | for (k = 0; k < max(1, 40 - strlen(map->name) - strlen(map->perms[j])); k++) | ||
| 110 | fprintf(fout, " "); | ||
| 111 | fprintf(fout, "0x%08xUL\n", (1<<j)); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | fprintf(fout, "\n#endif\n"); | ||
| 116 | fclose(fout); | ||
| 117 | exit(0); | ||
| 118 | } | ||
diff --git a/scripts/selinux/mdp/mdp.c b/scripts/selinux/mdp/mdp.c index b4ced8562587..62b34ce1f50d 100644 --- a/scripts/selinux/mdp/mdp.c +++ b/scripts/selinux/mdp/mdp.c | |||
| @@ -29,86 +29,27 @@ | |||
| 29 | #include <unistd.h> | 29 | #include <unistd.h> |
| 30 | #include <string.h> | 30 | #include <string.h> |
| 31 | 31 | ||
| 32 | #include "flask.h" | ||
| 33 | |||
| 34 | static void usage(char *name) | 32 | static void usage(char *name) |
| 35 | { | 33 | { |
| 36 | printf("usage: %s [-m] policy_file context_file\n", name); | 34 | printf("usage: %s [-m] policy_file context_file\n", name); |
| 37 | exit(1); | 35 | exit(1); |
| 38 | } | 36 | } |
| 39 | 37 | ||
| 40 | static void find_common_name(char *cname, char *dest, int len) | 38 | /* Class/perm mapping support */ |
| 41 | { | 39 | struct security_class_mapping { |
| 42 | char *start, *end; | 40 | const char *name; |
| 43 | 41 | const char *perms[sizeof(unsigned) * 8 + 1]; | |
| 44 | start = strchr(cname, '_')+1; | ||
| 45 | end = strchr(start, '_'); | ||
| 46 | if (!start || !end || start-cname > len || end-start > len) { | ||
| 47 | printf("Error with commons defines\n"); | ||
| 48 | exit(1); | ||
| 49 | } | ||
| 50 | strncpy(dest, start, end-start); | ||
| 51 | dest[end-start] = '\0'; | ||
| 52 | } | ||
| 53 | |||
| 54 | #define S_(x) x, | ||
| 55 | static char *classlist[] = { | ||
| 56 | #include "class_to_string.h" | ||
| 57 | NULL | ||
| 58 | }; | 42 | }; |
| 59 | #undef S_ | ||
| 60 | 43 | ||
| 44 | #include "classmap.h" | ||
| 61 | #include "initial_sid_to_string.h" | 45 | #include "initial_sid_to_string.h" |
| 62 | 46 | ||
| 63 | #define TB_(x) char *x[] = { | ||
| 64 | #define TE_(x) NULL }; | ||
| 65 | #define S_(x) x, | ||
| 66 | #include "common_perm_to_string.h" | ||
| 67 | #undef TB_ | ||
| 68 | #undef TE_ | ||
| 69 | #undef S_ | ||
| 70 | |||
| 71 | struct common { | ||
| 72 | char *cname; | ||
| 73 | char **perms; | ||
| 74 | }; | ||
| 75 | struct common common[] = { | ||
| 76 | #define TB_(x) { #x, x }, | ||
| 77 | #define S_(x) | ||
| 78 | #define TE_(x) | ||
| 79 | #include "common_perm_to_string.h" | ||
| 80 | #undef TB_ | ||
| 81 | #undef TE_ | ||
| 82 | #undef S_ | ||
| 83 | }; | ||
| 84 | |||
| 85 | #define S_(x, y, z) {x, #y}, | ||
| 86 | struct av_inherit { | ||
| 87 | int class; | ||
| 88 | char *common; | ||
| 89 | }; | ||
| 90 | struct av_inherit av_inherit[] = { | ||
| 91 | #include "av_inherit.h" | ||
| 92 | }; | ||
| 93 | #undef S_ | ||
| 94 | |||
| 95 | #include "av_permissions.h" | ||
| 96 | #define S_(x, y, z) {x, y, z}, | ||
| 97 | struct av_perms { | ||
| 98 | int class; | ||
| 99 | int perm_i; | ||
| 100 | char *perm_s; | ||
| 101 | }; | ||
| 102 | struct av_perms av_perms[] = { | ||
| 103 | #include "av_perm_to_string.h" | ||
| 104 | }; | ||
| 105 | #undef S_ | ||
| 106 | |||
| 107 | int main(int argc, char *argv[]) | 47 | int main(int argc, char *argv[]) |
| 108 | { | 48 | { |
| 109 | int i, j, mls = 0; | 49 | int i, j, mls = 0; |
| 50 | int initial_sid_to_string_len; | ||
| 110 | char **arg, *polout, *ctxout; | 51 | char **arg, *polout, *ctxout; |
| 111 | int classlist_len, initial_sid_to_string_len; | 52 | |
| 112 | FILE *fout; | 53 | FILE *fout; |
| 113 | 54 | ||
| 114 | if (argc < 3) | 55 | if (argc < 3) |
| @@ -127,64 +68,25 @@ int main(int argc, char *argv[]) | |||
| 127 | usage(argv[0]); | 68 | usage(argv[0]); |
| 128 | } | 69 | } |
| 129 | 70 | ||
| 130 | classlist_len = sizeof(classlist) / sizeof(char *); | ||
| 131 | /* print out the classes */ | 71 | /* print out the classes */ |
| 132 | for (i=1; i < classlist_len; i++) { | 72 | for (i = 0; secclass_map[i].name; i++) |
| 133 | if(classlist[i]) | 73 | fprintf(fout, "class %s\n", secclass_map[i].name); |
| 134 | fprintf(fout, "class %s\n", classlist[i]); | ||
| 135 | else | ||
| 136 | fprintf(fout, "class user%d\n", i); | ||
| 137 | } | ||
| 138 | fprintf(fout, "\n"); | 74 | fprintf(fout, "\n"); |
| 139 | 75 | ||
| 140 | initial_sid_to_string_len = sizeof(initial_sid_to_string) / sizeof (char *); | 76 | initial_sid_to_string_len = sizeof(initial_sid_to_string) / sizeof (char *); |
| 141 | /* print out the sids */ | 77 | /* print out the sids */ |
| 142 | for (i=1; i < initial_sid_to_string_len; i++) | 78 | for (i = 1; i < initial_sid_to_string_len; i++) |
| 143 | fprintf(fout, "sid %s\n", initial_sid_to_string[i]); | 79 | fprintf(fout, "sid %s\n", initial_sid_to_string[i]); |
| 144 | fprintf(fout, "\n"); | 80 | fprintf(fout, "\n"); |
| 145 | 81 | ||
| 146 | /* print out the commons */ | ||
| 147 | for (i=0; i< sizeof(common)/sizeof(struct common); i++) { | ||
| 148 | char cname[101]; | ||
| 149 | find_common_name(common[i].cname, cname, 100); | ||
| 150 | cname[100] = '\0'; | ||
| 151 | fprintf(fout, "common %s\n{\n", cname); | ||
| 152 | for (j=0; common[i].perms[j]; j++) | ||
| 153 | fprintf(fout, "\t%s\n", common[i].perms[j]); | ||
| 154 | fprintf(fout, "}\n\n"); | ||
| 155 | } | ||
| 156 | fprintf(fout, "\n"); | ||
| 157 | |||
| 158 | /* print out the class permissions */ | 82 | /* print out the class permissions */ |
| 159 | for (i=1; i < classlist_len; i++) { | 83 | for (i = 0; secclass_map[i].name; i++) { |
| 160 | if (classlist[i]) { | 84 | struct security_class_mapping *map = &secclass_map[i]; |
| 161 | int firstperm = -1, numperms = 0; | 85 | fprintf(fout, "class %s\n", map->name); |
| 162 | 86 | fprintf(fout, "{\n"); | |
| 163 | fprintf(fout, "class %s\n", classlist[i]); | 87 | for (j = 0; map->perms[j]; j++) |
| 164 | /* does it inherit from a common? */ | 88 | fprintf(fout, "\t%s\n", map->perms[j]); |
| 165 | for (j=0; j < sizeof(av_inherit)/sizeof(struct av_inherit); j++) | 89 | fprintf(fout, "}\n\n"); |
| 166 | if (av_inherit[j].class == i) | ||
| 167 | fprintf(fout, "inherits %s\n", av_inherit[j].common); | ||
| 168 | |||
| 169 | for (j=0; j < sizeof(av_perms)/sizeof(struct av_perms); j++) { | ||
| 170 | if (av_perms[j].class == i) { | ||
| 171 | if (firstperm == -1) | ||
| 172 | firstperm = j; | ||
| 173 | numperms++; | ||
| 174 | } | ||
| 175 | } | ||
| 176 | if (!numperms) { | ||
| 177 | fprintf(fout, "\n"); | ||
| 178 | continue; | ||
| 179 | } | ||
| 180 | |||
| 181 | fprintf(fout, "{\n"); | ||
| 182 | /* print out the av_perms */ | ||
| 183 | for (j=0; j < numperms; j++) { | ||
| 184 | fprintf(fout, "\t%s\n", av_perms[firstperm+j].perm_s); | ||
| 185 | } | ||
| 186 | fprintf(fout, "}\n\n"); | ||
| 187 | } | ||
| 188 | } | 90 | } |
| 189 | fprintf(fout, "\n"); | 91 | fprintf(fout, "\n"); |
| 190 | 92 | ||
| @@ -197,31 +99,34 @@ int main(int argc, char *argv[]) | |||
| 197 | /* types, roles, and allows */ | 99 | /* types, roles, and allows */ |
| 198 | fprintf(fout, "type base_t;\n"); | 100 | fprintf(fout, "type base_t;\n"); |
| 199 | fprintf(fout, "role base_r types { base_t };\n"); | 101 | fprintf(fout, "role base_r types { base_t };\n"); |
| 200 | for (i=1; i < classlist_len; i++) { | 102 | for (i = 0; secclass_map[i].name; i++) |
| 201 | if (classlist[i]) | 103 | fprintf(fout, "allow base_t base_t:%s *;\n", |
| 202 | fprintf(fout, "allow base_t base_t:%s *;\n", classlist[i]); | 104 | secclass_map[i].name); |
| 203 | else | ||
| 204 | fprintf(fout, "allow base_t base_t:user%d *;\n", i); | ||
| 205 | } | ||
| 206 | fprintf(fout, "user user_u roles { base_r };\n"); | 105 | fprintf(fout, "user user_u roles { base_r };\n"); |
| 207 | fprintf(fout, "\n"); | 106 | fprintf(fout, "\n"); |
| 208 | 107 | ||
| 209 | /* default sids */ | 108 | /* default sids */ |
| 210 | for (i=1; i < initial_sid_to_string_len; i++) | 109 | for (i = 1; i < initial_sid_to_string_len; i++) |
| 211 | fprintf(fout, "sid %s user_u:base_r:base_t\n", initial_sid_to_string[i]); | 110 | fprintf(fout, "sid %s user_u:base_r:base_t\n", initial_sid_to_string[i]); |
| 212 | fprintf(fout, "\n"); | 111 | fprintf(fout, "\n"); |
| 213 | 112 | ||
| 214 | |||
| 215 | fprintf(fout, "fs_use_xattr ext2 user_u:base_r:base_t;\n"); | 113 | fprintf(fout, "fs_use_xattr ext2 user_u:base_r:base_t;\n"); |
| 216 | fprintf(fout, "fs_use_xattr ext3 user_u:base_r:base_t;\n"); | 114 | fprintf(fout, "fs_use_xattr ext3 user_u:base_r:base_t;\n"); |
| 115 | fprintf(fout, "fs_use_xattr ext4 user_u:base_r:base_t;\n"); | ||
| 217 | fprintf(fout, "fs_use_xattr jfs user_u:base_r:base_t;\n"); | 116 | fprintf(fout, "fs_use_xattr jfs user_u:base_r:base_t;\n"); |
| 218 | fprintf(fout, "fs_use_xattr xfs user_u:base_r:base_t;\n"); | 117 | fprintf(fout, "fs_use_xattr xfs user_u:base_r:base_t;\n"); |
| 219 | fprintf(fout, "fs_use_xattr reiserfs user_u:base_r:base_t;\n"); | 118 | fprintf(fout, "fs_use_xattr reiserfs user_u:base_r:base_t;\n"); |
| 119 | fprintf(fout, "fs_use_xattr jffs2 user_u:base_r:base_t;\n"); | ||
| 120 | fprintf(fout, "fs_use_xattr gfs2 user_u:base_r:base_t;\n"); | ||
| 121 | fprintf(fout, "fs_use_xattr lustre user_u:base_r:base_t;\n"); | ||
| 220 | 122 | ||
| 123 | fprintf(fout, "fs_use_task eventpollfs user_u:base_r:base_t;\n"); | ||
| 221 | fprintf(fout, "fs_use_task pipefs user_u:base_r:base_t;\n"); | 124 | fprintf(fout, "fs_use_task pipefs user_u:base_r:base_t;\n"); |
| 222 | fprintf(fout, "fs_use_task sockfs user_u:base_r:base_t;\n"); | 125 | fprintf(fout, "fs_use_task sockfs user_u:base_r:base_t;\n"); |
| 223 | 126 | ||
| 127 | fprintf(fout, "fs_use_trans mqueue user_u:base_r:base_t;\n"); | ||
| 224 | fprintf(fout, "fs_use_trans devpts user_u:base_r:base_t;\n"); | 128 | fprintf(fout, "fs_use_trans devpts user_u:base_r:base_t;\n"); |
| 129 | fprintf(fout, "fs_use_trans hugetlbfs user_u:base_r:base_t;\n"); | ||
| 225 | fprintf(fout, "fs_use_trans tmpfs user_u:base_r:base_t;\n"); | 130 | fprintf(fout, "fs_use_trans tmpfs user_u:base_r:base_t;\n"); |
| 226 | fprintf(fout, "fs_use_trans shm user_u:base_r:base_t;\n"); | 131 | fprintf(fout, "fs_use_trans shm user_u:base_r:base_t;\n"); |
| 227 | 132 | ||
diff --git a/scripts/tags.sh b/scripts/tags.sh index d52f7a01557c..1a0c44d7c4a7 100755 --- a/scripts/tags.sh +++ b/scripts/tags.sh | |||
| @@ -89,7 +89,13 @@ all_defconfigs() | |||
| 89 | 89 | ||
| 90 | docscope() | 90 | docscope() |
| 91 | { | 91 | { |
| 92 | (echo \-k; echo \-q; all_sources) > cscope.files | 92 | # always use absolute paths for cscope, as recommended by cscope |
| 93 | # upstream | ||
| 94 | case "$tree" in | ||
| 95 | /*) ;; | ||
| 96 | *) tree=$PWD/$tree ;; | ||
| 97 | esac | ||
| 98 | (cd /; echo \-k; echo \-q; all_sources) > cscope.files | ||
| 93 | cscope -b -f cscope.out | 99 | cscope -b -f cscope.out |
| 94 | } | 100 | } |
| 95 | 101 | ||
diff --git a/scripts/unifdef.c b/scripts/unifdef.c index 30d459fb0709..44d39785e50d 100644 --- a/scripts/unifdef.c +++ b/scripts/unifdef.c | |||
| @@ -1,13 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2002 - 2005 Tony Finch <dot@dotat.at>. All rights reserved. | 2 | * Copyright (c) 2002 - 2009 Tony Finch <dot@dotat.at> |
| 3 | * | ||
| 4 | * This code is derived from software contributed to Berkeley by Dave Yost. | ||
| 5 | * It was rewritten to support ANSI C by Tony Finch. The original version of | ||
| 6 | * unifdef carried the following copyright notice. None of its code remains | ||
| 7 | * in this version (though some of the names remain). | ||
| 8 | * | ||
| 9 | * Copyright (c) 1985, 1993 | ||
| 10 | * The Regents of the University of California. All rights reserved. | ||
| 11 | * | 3 | * |
| 12 | * Redistribution and use in source and binary forms, with or without | 4 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions | 5 | * modification, are permitted provided that the following conditions |
| @@ -31,23 +23,20 @@ | |||
| 31 | * SUCH DAMAGE. | 23 | * SUCH DAMAGE. |
| 32 | */ | 24 | */ |
| 33 | 25 | ||
| 34 | #include <sys/cdefs.h> | 26 | /* |
| 27 | * This code was derived from software contributed to Berkeley by Dave Yost. | ||
| 28 | * It was rewritten to support ANSI C by Tony Finch. The original version | ||
| 29 | * of unifdef carried the 4-clause BSD copyright licence. None of its code | ||
| 30 | * remains in this version (though some of the names remain) so it now | ||
| 31 | * carries a more liberal licence. | ||
| 32 | * | ||
| 33 | * The latest version is available from http://dotat.at/prog/unifdef | ||
| 34 | */ | ||
| 35 | 35 | ||
| 36 | #ifndef lint | 36 | static const char * const copyright[] = { |
| 37 | #if 0 | 37 | "@(#) Copyright (c) 2002 - 2009 Tony Finch <dot@dotat.at>\n", |
| 38 | static const char copyright[] = | 38 | "$dotat: unifdef/unifdef.c,v 1.190 2009/11/27 17:21:26 fanf2 Exp $", |
| 39 | "@(#) Copyright (c) 1985, 1993\n\ | 39 | }; |
| 40 | The Regents of the University of California. All rights reserved.\n"; | ||
| 41 | #endif | ||
| 42 | #ifdef __IDSTRING | ||
| 43 | __IDSTRING(Berkeley, "@(#)unifdef.c 8.1 (Berkeley) 6/6/93"); | ||
| 44 | __IDSTRING(NetBSD, "$NetBSD: unifdef.c,v 1.8 2000/07/03 02:51:36 matt Exp $"); | ||
| 45 | __IDSTRING(dotat, "$dotat: things/unifdef.c,v 1.171 2005/03/08 12:38:48 fanf2 Exp $"); | ||
| 46 | #endif | ||
| 47 | #endif /* not lint */ | ||
| 48 | #ifdef __FBSDID | ||
| 49 | __FBSDID("$FreeBSD: /repoman/r/ncvs/src/usr.bin/unifdef/unifdef.c,v 1.20 2005/05/21 09:55:09 ru Exp $"); | ||
| 50 | #endif | ||
| 51 | 40 | ||
| 52 | /* | 41 | /* |
| 53 | * unifdef - remove ifdef'ed lines | 42 | * unifdef - remove ifdef'ed lines |
| @@ -72,8 +61,6 @@ __FBSDID("$FreeBSD: /repoman/r/ncvs/src/usr.bin/unifdef/unifdef.c,v 1.20 2005/05 | |||
| 72 | #include <string.h> | 61 | #include <string.h> |
| 73 | #include <unistd.h> | 62 | #include <unistd.h> |
| 74 | 63 | ||
| 75 | size_t strlcpy(char *dst, const char *src, size_t siz); | ||
| 76 | |||
| 77 | /* types of input lines: */ | 64 | /* types of input lines: */ |
| 78 | typedef enum { | 65 | typedef enum { |
| 79 | LT_TRUEI, /* a true #if with ignore flag */ | 66 | LT_TRUEI, /* a true #if with ignore flag */ |
| @@ -90,6 +77,7 @@ typedef enum { | |||
| 90 | LT_DODGY_LAST = LT_DODGY + LT_ENDIF, | 77 | LT_DODGY_LAST = LT_DODGY + LT_ENDIF, |
| 91 | LT_PLAIN, /* ordinary line */ | 78 | LT_PLAIN, /* ordinary line */ |
| 92 | LT_EOF, /* end of file */ | 79 | LT_EOF, /* end of file */ |
| 80 | LT_ERROR, /* unevaluable #if */ | ||
| 93 | LT_COUNT | 81 | LT_COUNT |
| 94 | } Linetype; | 82 | } Linetype; |
| 95 | 83 | ||
| @@ -100,7 +88,7 @@ static char const * const linetype_name[] = { | |||
| 100 | "DODGY IF", "DODGY TRUE", "DODGY FALSE", | 88 | "DODGY IF", "DODGY TRUE", "DODGY FALSE", |
| 101 | "DODGY ELIF", "DODGY ELTRUE", "DODGY ELFALSE", | 89 | "DODGY ELIF", "DODGY ELTRUE", "DODGY ELFALSE", |
| 102 | "DODGY ELSE", "DODGY ENDIF", | 90 | "DODGY ELSE", "DODGY ENDIF", |
| 103 | "PLAIN", "EOF" | 91 | "PLAIN", "EOF", "ERROR" |
| 104 | }; | 92 | }; |
| 105 | 93 | ||
| 106 | /* state of #if processing */ | 94 | /* state of #if processing */ |
| @@ -168,11 +156,13 @@ static char const * const linestate_name[] = { | |||
| 168 | * Globals. | 156 | * Globals. |
| 169 | */ | 157 | */ |
| 170 | 158 | ||
| 159 | static bool compblank; /* -B: compress blank lines */ | ||
| 160 | static bool lnblank; /* -b: blank deleted lines */ | ||
| 171 | static bool complement; /* -c: do the complement */ | 161 | static bool complement; /* -c: do the complement */ |
| 172 | static bool debugging; /* -d: debugging reports */ | 162 | static bool debugging; /* -d: debugging reports */ |
| 173 | static bool iocccok; /* -e: fewer IOCCC errors */ | 163 | static bool iocccok; /* -e: fewer IOCCC errors */ |
| 164 | static bool strictlogic; /* -K: keep ambiguous #ifs */ | ||
| 174 | static bool killconsts; /* -k: eval constant #ifs */ | 165 | static bool killconsts; /* -k: eval constant #ifs */ |
| 175 | static bool lnblank; /* -l: blank deleted lines */ | ||
| 176 | static bool lnnum; /* -n: add #line directives */ | 166 | static bool lnnum; /* -n: add #line directives */ |
| 177 | static bool symlist; /* -s: output symbol list */ | 167 | static bool symlist; /* -s: output symbol list */ |
| 178 | static bool text; /* -t: this is a text file */ | 168 | static bool text; /* -t: this is a text file */ |
| @@ -196,7 +186,9 @@ static bool ignoring[MAXDEPTH]; /* ignore comments state */ | |||
| 196 | static int stifline[MAXDEPTH]; /* start of current #if */ | 186 | static int stifline[MAXDEPTH]; /* start of current #if */ |
| 197 | static int depth; /* current #if nesting */ | 187 | static int depth; /* current #if nesting */ |
| 198 | static int delcount; /* count of deleted lines */ | 188 | static int delcount; /* count of deleted lines */ |
| 199 | static bool keepthis; /* don't delete constant #if */ | 189 | static unsigned blankcount; /* count of blank lines */ |
| 190 | static unsigned blankmax; /* maximum recent blankcount */ | ||
| 191 | static bool constexpr; /* constant #if expression */ | ||
| 200 | 192 | ||
| 201 | static int exitstat; /* program exit status */ | 193 | static int exitstat; /* program exit status */ |
| 202 | 194 | ||
| @@ -206,13 +198,14 @@ static void done(void); | |||
| 206 | static void error(const char *); | 198 | static void error(const char *); |
| 207 | static int findsym(const char *); | 199 | static int findsym(const char *); |
| 208 | static void flushline(bool); | 200 | static void flushline(bool); |
| 209 | static Linetype get_line(void); | 201 | static Linetype parseline(void); |
| 210 | static Linetype ifeval(const char **); | 202 | static Linetype ifeval(const char **); |
| 211 | static void ignoreoff(void); | 203 | static void ignoreoff(void); |
| 212 | static void ignoreon(void); | 204 | static void ignoreon(void); |
| 213 | static void keywordedit(const char *); | 205 | static void keywordedit(const char *); |
| 214 | static void nest(void); | 206 | static void nest(void); |
| 215 | static void process(void); | 207 | static void process(void); |
| 208 | static const char *skipargs(const char *); | ||
| 216 | static const char *skipcomment(const char *); | 209 | static const char *skipcomment(const char *); |
| 217 | static const char *skipsym(const char *); | 210 | static const char *skipsym(const char *); |
| 218 | static void state(Ifstate); | 211 | static void state(Ifstate); |
| @@ -220,7 +213,7 @@ static int strlcmp(const char *, const char *, size_t); | |||
| 220 | static void unnest(void); | 213 | static void unnest(void); |
| 221 | static void usage(void); | 214 | static void usage(void); |
| 222 | 215 | ||
| 223 | #define endsym(c) (!isalpha((unsigned char)c) && !isdigit((unsigned char)c) && c != '_') | 216 | #define endsym(c) (!isalnum((unsigned char)c) && c != '_') |
| 224 | 217 | ||
| 225 | /* | 218 | /* |
| 226 | * The main program. | 219 | * The main program. |
| @@ -230,7 +223,7 @@ main(int argc, char *argv[]) | |||
| 230 | { | 223 | { |
| 231 | int opt; | 224 | int opt; |
| 232 | 225 | ||
| 233 | while ((opt = getopt(argc, argv, "i:D:U:I:cdeklnst")) != -1) | 226 | while ((opt = getopt(argc, argv, "i:D:U:I:BbcdeKklnst")) != -1) |
| 234 | switch (opt) { | 227 | switch (opt) { |
| 235 | case 'i': /* treat stuff controlled by these symbols as text */ | 228 | case 'i': /* treat stuff controlled by these symbols as text */ |
| 236 | /* | 229 | /* |
| @@ -255,6 +248,13 @@ main(int argc, char *argv[]) | |||
| 255 | case 'I': | 248 | case 'I': |
| 256 | /* no-op for compatibility with cpp */ | 249 | /* no-op for compatibility with cpp */ |
| 257 | break; | 250 | break; |
| 251 | case 'B': /* compress blank lines around removed section */ | ||
| 252 | compblank = true; | ||
| 253 | break; | ||
| 254 | case 'b': /* blank deleted lines instead of omitting them */ | ||
| 255 | case 'l': /* backwards compatibility */ | ||
| 256 | lnblank = true; | ||
| 257 | break; | ||
| 258 | case 'c': /* treat -D as -U and vice versa */ | 258 | case 'c': /* treat -D as -U and vice versa */ |
| 259 | complement = true; | 259 | complement = true; |
| 260 | break; | 260 | break; |
| @@ -264,12 +264,12 @@ main(int argc, char *argv[]) | |||
| 264 | case 'e': /* fewer errors from dodgy lines */ | 264 | case 'e': /* fewer errors from dodgy lines */ |
| 265 | iocccok = true; | 265 | iocccok = true; |
| 266 | break; | 266 | break; |
| 267 | case 'K': /* keep ambiguous #ifs */ | ||
| 268 | strictlogic = true; | ||
| 269 | break; | ||
| 267 | case 'k': /* process constant #ifs */ | 270 | case 'k': /* process constant #ifs */ |
| 268 | killconsts = true; | 271 | killconsts = true; |
| 269 | break; | 272 | break; |
| 270 | case 'l': /* blank deleted lines instead of omitting them */ | ||
| 271 | lnblank = true; | ||
| 272 | break; | ||
| 273 | case 'n': /* add #line directive after deleted lines */ | 273 | case 'n': /* add #line directive after deleted lines */ |
| 274 | lnnum = true; | 274 | lnnum = true; |
| 275 | break; | 275 | break; |
| @@ -284,6 +284,8 @@ main(int argc, char *argv[]) | |||
| 284 | } | 284 | } |
| 285 | argc -= optind; | 285 | argc -= optind; |
| 286 | argv += optind; | 286 | argv += optind; |
| 287 | if (compblank && lnblank) | ||
| 288 | errx(2, "-B and -b are mutually exclusive"); | ||
| 287 | if (argc > 1) { | 289 | if (argc > 1) { |
| 288 | errx(2, "can only do one file"); | 290 | errx(2, "can only do one file"); |
| 289 | } else if (argc == 1 && strcmp(*argv, "-") != 0) { | 291 | } else if (argc == 1 && strcmp(*argv, "-") != 0) { |
| @@ -302,7 +304,7 @@ main(int argc, char *argv[]) | |||
| 302 | static void | 304 | static void |
| 303 | usage(void) | 305 | usage(void) |
| 304 | { | 306 | { |
| 305 | fprintf(stderr, "usage: unifdef [-cdeklnst] [-Ipath]" | 307 | fprintf(stderr, "usage: unifdef [-BbcdeKknst] [-Ipath]" |
| 306 | " [-Dsym[=val]] [-Usym] [-iDsym[=val]] [-iUsym] ... [file]\n"); | 308 | " [-Dsym[=val]] [-Usym] [-iDsym[=val]] [-iUsym] ... [file]\n"); |
| 307 | exit(2); | 309 | exit(2); |
| 308 | } | 310 | } |
| @@ -383,46 +385,46 @@ static state_fn * const trans_table[IS_COUNT][LT_COUNT] = { | |||
| 383 | /* IS_OUTSIDE */ | 385 | /* IS_OUTSIDE */ |
| 384 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Eendif, | 386 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Eendif, |
| 385 | Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Eendif, | 387 | Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Eendif, |
| 386 | print, done }, | 388 | print, done, abort }, |
| 387 | /* IS_FALSE_PREFIX */ | 389 | /* IS_FALSE_PREFIX */ |
| 388 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Mpass, Strue, Sfalse,Selse, Dendif, | 390 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Mpass, Strue, Sfalse,Selse, Dendif, |
| 389 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Mpass, Eioccc,Eioccc,Eioccc,Eioccc, | 391 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Mpass, Eioccc,Eioccc,Eioccc,Eioccc, |
| 390 | drop, Eeof }, | 392 | drop, Eeof, abort }, |
| 391 | /* IS_TRUE_PREFIX */ | 393 | /* IS_TRUE_PREFIX */ |
| 392 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Dfalse,Dfalse,Dfalse,Delse, Dendif, | 394 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Dfalse,Dfalse,Dfalse,Delse, Dendif, |
| 393 | Oiffy, Oiffy, Fpass, Oif, Oif, Eioccc,Eioccc,Eioccc,Eioccc,Eioccc, | 395 | Oiffy, Oiffy, Fpass, Oif, Oif, Eioccc,Eioccc,Eioccc,Eioccc,Eioccc, |
| 394 | print, Eeof }, | 396 | print, Eeof, abort }, |
| 395 | /* IS_PASS_MIDDLE */ | 397 | /* IS_PASS_MIDDLE */ |
| 396 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Pelif, Mtrue, Delif, Pelse, Pendif, | 398 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Pelif, Mtrue, Delif, Pelse, Pendif, |
| 397 | Oiffy, Oiffy, Fpass, Oif, Oif, Pelif, Oelif, Oelif, Pelse, Pendif, | 399 | Oiffy, Oiffy, Fpass, Oif, Oif, Pelif, Oelif, Oelif, Pelse, Pendif, |
| 398 | print, Eeof }, | 400 | print, Eeof, abort }, |
| 399 | /* IS_FALSE_MIDDLE */ | 401 | /* IS_FALSE_MIDDLE */ |
| 400 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Pelif, Mtrue, Delif, Pelse, Pendif, | 402 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Pelif, Mtrue, Delif, Pelse, Pendif, |
| 401 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eioccc,Eioccc,Eioccc,Eioccc,Eioccc, | 403 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eioccc,Eioccc,Eioccc,Eioccc,Eioccc, |
| 402 | drop, Eeof }, | 404 | drop, Eeof, abort }, |
| 403 | /* IS_TRUE_MIDDLE */ | 405 | /* IS_TRUE_MIDDLE */ |
| 404 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Melif, Melif, Melif, Melse, Pendif, | 406 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Melif, Melif, Melif, Melse, Pendif, |
| 405 | Oiffy, Oiffy, Fpass, Oif, Oif, Eioccc,Eioccc,Eioccc,Eioccc,Pendif, | 407 | Oiffy, Oiffy, Fpass, Oif, Oif, Eioccc,Eioccc,Eioccc,Eioccc,Pendif, |
| 406 | print, Eeof }, | 408 | print, Eeof, abort }, |
| 407 | /* IS_PASS_ELSE */ | 409 | /* IS_PASS_ELSE */ |
| 408 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Pendif, | 410 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Pendif, |
| 409 | Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Pendif, | 411 | Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Pendif, |
| 410 | print, Eeof }, | 412 | print, Eeof, abort }, |
| 411 | /* IS_FALSE_ELSE */ | 413 | /* IS_FALSE_ELSE */ |
| 412 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eelif, Eelif, Eelif, Eelse, Dendif, | 414 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eelif, Eelif, Eelif, Eelse, Dendif, |
| 413 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eelif, Eelif, Eelif, Eelse, Eioccc, | 415 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Eelif, Eelif, Eelif, Eelse, Eioccc, |
| 414 | drop, Eeof }, | 416 | drop, Eeof, abort }, |
| 415 | /* IS_TRUE_ELSE */ | 417 | /* IS_TRUE_ELSE */ |
| 416 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Dendif, | 418 | { Itrue, Ifalse,Fpass, Ftrue, Ffalse,Eelif, Eelif, Eelif, Eelse, Dendif, |
| 417 | Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Eioccc, | 419 | Oiffy, Oiffy, Fpass, Oif, Oif, Eelif, Eelif, Eelif, Eelse, Eioccc, |
| 418 | print, Eeof }, | 420 | print, Eeof, abort }, |
| 419 | /* IS_FALSE_TRAILER */ | 421 | /* IS_FALSE_TRAILER */ |
| 420 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Dfalse,Dfalse,Dfalse,Delse, Dendif, | 422 | { Idrop, Idrop, Fdrop, Fdrop, Fdrop, Dfalse,Dfalse,Dfalse,Delse, Dendif, |
| 421 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Dfalse,Dfalse,Dfalse,Delse, Eioccc, | 423 | Idrop, Idrop, Fdrop, Fdrop, Fdrop, Dfalse,Dfalse,Dfalse,Delse, Eioccc, |
| 422 | drop, Eeof } | 424 | drop, Eeof, abort } |
| 423 | /*TRUEI FALSEI IF TRUE FALSE ELIF ELTRUE ELFALSE ELSE ENDIF | 425 | /*TRUEI FALSEI IF TRUE FALSE ELIF ELTRUE ELFALSE ELSE ENDIF |
| 424 | TRUEI FALSEI IF TRUE FALSE ELIF ELTRUE ELFALSE ELSE ENDIF (DODGY) | 426 | TRUEI FALSEI IF TRUE FALSE ELIF ELTRUE ELFALSE ELSE ENDIF (DODGY) |
| 425 | PLAIN EOF */ | 427 | PLAIN EOF ERROR */ |
| 426 | }; | 428 | }; |
| 427 | 429 | ||
| 428 | /* | 430 | /* |
| @@ -463,9 +465,11 @@ keywordedit(const char *replacement) | |||
| 463 | static void | 465 | static void |
| 464 | nest(void) | 466 | nest(void) |
| 465 | { | 467 | { |
| 466 | depth += 1; | 468 | if (depth > MAXDEPTH-1) |
| 467 | if (depth >= MAXDEPTH) | 469 | abort(); /* bug */ |
| 470 | if (depth == MAXDEPTH-1) | ||
| 468 | error("Too many levels of nesting"); | 471 | error("Too many levels of nesting"); |
| 472 | depth += 1; | ||
| 469 | stifline[depth] = linenum; | 473 | stifline[depth] = linenum; |
| 470 | } | 474 | } |
| 471 | static void | 475 | static void |
| @@ -490,15 +494,23 @@ flushline(bool keep) | |||
| 490 | if (symlist) | 494 | if (symlist) |
| 491 | return; | 495 | return; |
| 492 | if (keep ^ complement) { | 496 | if (keep ^ complement) { |
| 493 | if (lnnum && delcount > 0) | 497 | bool blankline = tline[strspn(tline, " \t\n")] == '\0'; |
| 494 | printf("#line %d\n", linenum); | 498 | if (blankline && compblank && blankcount != blankmax) { |
| 495 | fputs(tline, stdout); | 499 | delcount += 1; |
| 496 | delcount = 0; | 500 | blankcount += 1; |
| 501 | } else { | ||
| 502 | if (lnnum && delcount > 0) | ||
| 503 | printf("#line %d\n", linenum); | ||
| 504 | fputs(tline, stdout); | ||
| 505 | delcount = 0; | ||
| 506 | blankmax = blankcount = blankline ? blankcount + 1 : 0; | ||
| 507 | } | ||
| 497 | } else { | 508 | } else { |
| 498 | if (lnblank) | 509 | if (lnblank) |
| 499 | putc('\n', stdout); | 510 | putc('\n', stdout); |
| 500 | exitstat = 1; | 511 | exitstat = 1; |
| 501 | delcount += 1; | 512 | delcount += 1; |
| 513 | blankcount = 0; | ||
| 502 | } | 514 | } |
| 503 | } | 515 | } |
| 504 | 516 | ||
| @@ -510,9 +522,12 @@ process(void) | |||
| 510 | { | 522 | { |
| 511 | Linetype lineval; | 523 | Linetype lineval; |
| 512 | 524 | ||
| 525 | /* When compressing blank lines, act as if the file | ||
| 526 | is preceded by a large number of blank lines. */ | ||
| 527 | blankmax = blankcount = 1000; | ||
| 513 | for (;;) { | 528 | for (;;) { |
| 514 | linenum++; | 529 | linenum++; |
| 515 | lineval = get_line(); | 530 | lineval = parseline(); |
| 516 | trans_table[ifstate[depth]][lineval](); | 531 | trans_table[ifstate[depth]][lineval](); |
| 517 | debug("process %s -> %s depth %d", | 532 | debug("process %s -> %s depth %d", |
| 518 | linetype_name[lineval], | 533 | linetype_name[lineval], |
| @@ -526,7 +541,7 @@ process(void) | |||
| 526 | * help from skipcomment(). | 541 | * help from skipcomment(). |
| 527 | */ | 542 | */ |
| 528 | static Linetype | 543 | static Linetype |
| 529 | get_line(void) | 544 | parseline(void) |
| 530 | { | 545 | { |
| 531 | const char *cp; | 546 | const char *cp; |
| 532 | int cursym; | 547 | int cursym; |
| @@ -595,9 +610,21 @@ get_line(void) | |||
| 595 | if (incomment) | 610 | if (incomment) |
| 596 | linestate = LS_DIRTY; | 611 | linestate = LS_DIRTY; |
| 597 | } | 612 | } |
| 598 | /* skipcomment should have changed the state */ | 613 | /* skipcomment normally changes the state, except |
| 599 | if (linestate == LS_HASH) | 614 | if the last line of the file lacks a newline, or |
| 600 | abort(); /* bug */ | 615 | if there is too much whitespace in a directive */ |
| 616 | if (linestate == LS_HASH) { | ||
| 617 | size_t len = cp - tline; | ||
| 618 | if (fgets(tline + len, MAXLINE - len, input) == NULL) { | ||
| 619 | /* append the missing newline */ | ||
| 620 | tline[len+0] = '\n'; | ||
| 621 | tline[len+1] = '\0'; | ||
| 622 | cp++; | ||
| 623 | linestate = LS_START; | ||
| 624 | } else { | ||
| 625 | linestate = LS_DIRTY; | ||
| 626 | } | ||
| 627 | } | ||
| 601 | } | 628 | } |
| 602 | if (linestate == LS_DIRTY) { | 629 | if (linestate == LS_DIRTY) { |
| 603 | while (*cp != '\0') | 630 | while (*cp != '\0') |
| @@ -610,17 +637,40 @@ get_line(void) | |||
| 610 | 637 | ||
| 611 | /* | 638 | /* |
| 612 | * These are the binary operators that are supported by the expression | 639 | * These are the binary operators that are supported by the expression |
| 613 | * evaluator. Note that if support for division is added then we also | 640 | * evaluator. |
| 614 | * need short-circuiting booleans because of divide-by-zero. | ||
| 615 | */ | 641 | */ |
| 616 | static int op_lt(int a, int b) { return (a < b); } | 642 | static Linetype op_strict(int *p, int v, Linetype at, Linetype bt) { |
| 617 | static int op_gt(int a, int b) { return (a > b); } | 643 | if(at == LT_IF || bt == LT_IF) return (LT_IF); |
| 618 | static int op_le(int a, int b) { return (a <= b); } | 644 | return (*p = v, v ? LT_TRUE : LT_FALSE); |
| 619 | static int op_ge(int a, int b) { return (a >= b); } | 645 | } |
| 620 | static int op_eq(int a, int b) { return (a == b); } | 646 | static Linetype op_lt(int *p, Linetype at, int a, Linetype bt, int b) { |
| 621 | static int op_ne(int a, int b) { return (a != b); } | 647 | return op_strict(p, a < b, at, bt); |
| 622 | static int op_or(int a, int b) { return (a || b); } | 648 | } |
| 623 | static int op_and(int a, int b) { return (a && b); } | 649 | static Linetype op_gt(int *p, Linetype at, int a, Linetype bt, int b) { |
| 650 | return op_strict(p, a > b, at, bt); | ||
| 651 | } | ||
| 652 | static Linetype op_le(int *p, Linetype at, int a, Linetype bt, int b) { | ||
| 653 | return op_strict(p, a <= b, at, bt); | ||
| 654 | } | ||
| 655 | static Linetype op_ge(int *p, Linetype at, int a, Linetype bt, int b) { | ||
| 656 | return op_strict(p, a >= b, at, bt); | ||
| 657 | } | ||
| 658 | static Linetype op_eq(int *p, Linetype at, int a, Linetype bt, int b) { | ||
| 659 | return op_strict(p, a == b, at, bt); | ||
| 660 | } | ||
| 661 | static Linetype op_ne(int *p, Linetype at, int a, Linetype bt, int b) { | ||
| 662 | return op_strict(p, a != b, at, bt); | ||
| 663 | } | ||
| 664 | static Linetype op_or(int *p, Linetype at, int a, Linetype bt, int b) { | ||
| 665 | if (!strictlogic && (at == LT_TRUE || bt == LT_TRUE)) | ||
| 666 | return (*p = 1, LT_TRUE); | ||
| 667 | return op_strict(p, a || b, at, bt); | ||
| 668 | } | ||
| 669 | static Linetype op_and(int *p, Linetype at, int a, Linetype bt, int b) { | ||
| 670 | if (!strictlogic && (at == LT_FALSE || bt == LT_FALSE)) | ||
| 671 | return (*p = 0, LT_FALSE); | ||
| 672 | return op_strict(p, a && b, at, bt); | ||
| 673 | } | ||
| 624 | 674 | ||
| 625 | /* | 675 | /* |
| 626 | * An evaluation function takes three arguments, as follows: (1) a pointer to | 676 | * An evaluation function takes three arguments, as follows: (1) a pointer to |
| @@ -629,8 +679,8 @@ static int op_and(int a, int b) { return (a && b); } | |||
| 629 | * value of the expression; and (3) a pointer to a char* that points to the | 679 | * value of the expression; and (3) a pointer to a char* that points to the |
| 630 | * expression to be evaluated and that is updated to the end of the expression | 680 | * expression to be evaluated and that is updated to the end of the expression |
| 631 | * when evaluation is complete. The function returns LT_FALSE if the value of | 681 | * when evaluation is complete. The function returns LT_FALSE if the value of |
| 632 | * the expression is zero, LT_TRUE if it is non-zero, or LT_IF if the | 682 | * the expression is zero, LT_TRUE if it is non-zero, LT_IF if the expression |
| 633 | * expression could not be evaluated. | 683 | * depends on an unknown symbol, or LT_ERROR if there is a parse failure. |
| 634 | */ | 684 | */ |
| 635 | struct ops; | 685 | struct ops; |
| 636 | 686 | ||
| @@ -649,7 +699,7 @@ static const struct ops { | |||
| 649 | eval_fn *inner; | 699 | eval_fn *inner; |
| 650 | struct op { | 700 | struct op { |
| 651 | const char *str; | 701 | const char *str; |
| 652 | int (*fn)(int, int); | 702 | Linetype (*fn)(int *, Linetype, int, Linetype, int); |
| 653 | } op[5]; | 703 | } op[5]; |
| 654 | } eval_ops[] = { | 704 | } eval_ops[] = { |
| 655 | { eval_table, { { "||", op_or } } }, | 705 | { eval_table, { { "||", op_or } } }, |
| @@ -664,8 +714,8 @@ static const struct ops { | |||
| 664 | 714 | ||
| 665 | /* | 715 | /* |
| 666 | * Function for evaluating the innermost parts of expressions, | 716 | * Function for evaluating the innermost parts of expressions, |
| 667 | * viz. !expr (expr) defined(symbol) symbol number | 717 | * viz. !expr (expr) number defined(symbol) symbol |
| 668 | * We reset the keepthis flag when we find a non-constant subexpression. | 718 | * We reset the constexpr flag in the last two cases. |
| 669 | */ | 719 | */ |
| 670 | static Linetype | 720 | static Linetype |
| 671 | eval_unary(const struct ops *ops, int *valp, const char **cpp) | 721 | eval_unary(const struct ops *ops, int *valp, const char **cpp) |
| @@ -673,68 +723,83 @@ eval_unary(const struct ops *ops, int *valp, const char **cpp) | |||
| 673 | const char *cp; | 723 | const char *cp; |
| 674 | char *ep; | 724 | char *ep; |
| 675 | int sym; | 725 | int sym; |
| 726 | bool defparen; | ||
| 727 | Linetype lt; | ||
| 676 | 728 | ||
| 677 | cp = skipcomment(*cpp); | 729 | cp = skipcomment(*cpp); |
| 678 | if (*cp == '!') { | 730 | if (*cp == '!') { |
| 679 | debug("eval%d !", ops - eval_ops); | 731 | debug("eval%d !", ops - eval_ops); |
| 680 | cp++; | 732 | cp++; |
| 681 | if (eval_unary(ops, valp, &cp) == LT_IF) { | 733 | lt = eval_unary(ops, valp, &cp); |
| 682 | *cpp = cp; | 734 | if (lt == LT_ERROR) |
| 683 | return (LT_IF); | 735 | return (LT_ERROR); |
| 736 | if (lt != LT_IF) { | ||
| 737 | *valp = !*valp; | ||
| 738 | lt = *valp ? LT_TRUE : LT_FALSE; | ||
| 684 | } | 739 | } |
| 685 | *valp = !*valp; | ||
| 686 | } else if (*cp == '(') { | 740 | } else if (*cp == '(') { |
| 687 | cp++; | 741 | cp++; |
| 688 | debug("eval%d (", ops - eval_ops); | 742 | debug("eval%d (", ops - eval_ops); |
| 689 | if (eval_table(eval_ops, valp, &cp) == LT_IF) | 743 | lt = eval_table(eval_ops, valp, &cp); |
| 690 | return (LT_IF); | 744 | if (lt == LT_ERROR) |
| 745 | return (LT_ERROR); | ||
| 691 | cp = skipcomment(cp); | 746 | cp = skipcomment(cp); |
| 692 | if (*cp++ != ')') | 747 | if (*cp++ != ')') |
| 693 | return (LT_IF); | 748 | return (LT_ERROR); |
| 694 | } else if (isdigit((unsigned char)*cp)) { | 749 | } else if (isdigit((unsigned char)*cp)) { |
| 695 | debug("eval%d number", ops - eval_ops); | 750 | debug("eval%d number", ops - eval_ops); |
| 696 | *valp = strtol(cp, &ep, 0); | 751 | *valp = strtol(cp, &ep, 0); |
| 752 | if (ep == cp) | ||
| 753 | return (LT_ERROR); | ||
| 754 | lt = *valp ? LT_TRUE : LT_FALSE; | ||
| 697 | cp = skipsym(cp); | 755 | cp = skipsym(cp); |
| 698 | } else if (strncmp(cp, "defined", 7) == 0 && endsym(cp[7])) { | 756 | } else if (strncmp(cp, "defined", 7) == 0 && endsym(cp[7])) { |
| 699 | cp = skipcomment(cp+7); | 757 | cp = skipcomment(cp+7); |
| 700 | debug("eval%d defined", ops - eval_ops); | 758 | debug("eval%d defined", ops - eval_ops); |
| 701 | if (*cp++ != '(') | 759 | if (*cp == '(') { |
| 702 | return (LT_IF); | 760 | cp = skipcomment(cp+1); |
| 703 | cp = skipcomment(cp); | 761 | defparen = true; |
| 762 | } else { | ||
| 763 | defparen = false; | ||
| 764 | } | ||
| 704 | sym = findsym(cp); | 765 | sym = findsym(cp); |
| 705 | cp = skipsym(cp); | 766 | if (sym < 0) { |
| 706 | cp = skipcomment(cp); | 767 | lt = LT_IF; |
| 707 | if (*cp++ != ')') | 768 | } else { |
| 708 | return (LT_IF); | ||
| 709 | if (sym >= 0) | ||
| 710 | *valp = (value[sym] != NULL); | 769 | *valp = (value[sym] != NULL); |
| 711 | else { | 770 | lt = *valp ? LT_TRUE : LT_FALSE; |
| 712 | *cpp = cp; | ||
| 713 | return (LT_IF); | ||
| 714 | } | 771 | } |
| 715 | keepthis = false; | 772 | cp = skipsym(cp); |
| 773 | cp = skipcomment(cp); | ||
| 774 | if (defparen && *cp++ != ')') | ||
| 775 | return (LT_ERROR); | ||
| 776 | constexpr = false; | ||
| 716 | } else if (!endsym(*cp)) { | 777 | } else if (!endsym(*cp)) { |
| 717 | debug("eval%d symbol", ops - eval_ops); | 778 | debug("eval%d symbol", ops - eval_ops); |
| 718 | sym = findsym(cp); | 779 | sym = findsym(cp); |
| 719 | if (sym < 0) | 780 | cp = skipsym(cp); |
| 720 | return (LT_IF); | 781 | if (sym < 0) { |
| 721 | if (value[sym] == NULL) | 782 | lt = LT_IF; |
| 783 | cp = skipargs(cp); | ||
| 784 | } else if (value[sym] == NULL) { | ||
| 722 | *valp = 0; | 785 | *valp = 0; |
| 723 | else { | 786 | lt = LT_FALSE; |
| 787 | } else { | ||
| 724 | *valp = strtol(value[sym], &ep, 0); | 788 | *valp = strtol(value[sym], &ep, 0); |
| 725 | if (*ep != '\0' || ep == value[sym]) | 789 | if (*ep != '\0' || ep == value[sym]) |
| 726 | return (LT_IF); | 790 | return (LT_ERROR); |
| 791 | lt = *valp ? LT_TRUE : LT_FALSE; | ||
| 792 | cp = skipargs(cp); | ||
| 727 | } | 793 | } |
| 728 | cp = skipsym(cp); | 794 | constexpr = false; |
| 729 | keepthis = false; | ||
| 730 | } else { | 795 | } else { |
| 731 | debug("eval%d bad expr", ops - eval_ops); | 796 | debug("eval%d bad expr", ops - eval_ops); |
| 732 | return (LT_IF); | 797 | return (LT_ERROR); |
| 733 | } | 798 | } |
| 734 | 799 | ||
| 735 | *cpp = cp; | 800 | *cpp = cp; |
| 736 | debug("eval%d = %d", ops - eval_ops, *valp); | 801 | debug("eval%d = %d", ops - eval_ops, *valp); |
| 737 | return (*valp ? LT_TRUE : LT_FALSE); | 802 | return (lt); |
| 738 | } | 803 | } |
| 739 | 804 | ||
| 740 | /* | 805 | /* |
| @@ -746,11 +811,13 @@ eval_table(const struct ops *ops, int *valp, const char **cpp) | |||
| 746 | const struct op *op; | 811 | const struct op *op; |
| 747 | const char *cp; | 812 | const char *cp; |
| 748 | int val; | 813 | int val; |
| 749 | Linetype lhs, rhs; | 814 | Linetype lt, rt; |
| 750 | 815 | ||
| 751 | debug("eval%d", ops - eval_ops); | 816 | debug("eval%d", ops - eval_ops); |
| 752 | cp = *cpp; | 817 | cp = *cpp; |
| 753 | lhs = ops->inner(ops+1, valp, &cp); | 818 | lt = ops->inner(ops+1, valp, &cp); |
| 819 | if (lt == LT_ERROR) | ||
| 820 | return (LT_ERROR); | ||
| 754 | for (;;) { | 821 | for (;;) { |
| 755 | cp = skipcomment(cp); | 822 | cp = skipcomment(cp); |
| 756 | for (op = ops->op; op->str != NULL; op++) | 823 | for (op = ops->op; op->str != NULL; op++) |
| @@ -760,32 +827,16 @@ eval_table(const struct ops *ops, int *valp, const char **cpp) | |||
| 760 | break; | 827 | break; |
| 761 | cp += strlen(op->str); | 828 | cp += strlen(op->str); |
| 762 | debug("eval%d %s", ops - eval_ops, op->str); | 829 | debug("eval%d %s", ops - eval_ops, op->str); |
| 763 | rhs = ops->inner(ops+1, &val, &cp); | 830 | rt = ops->inner(ops+1, &val, &cp); |
| 764 | if (op->fn == op_and && (lhs == LT_FALSE || rhs == LT_FALSE)) { | 831 | if (rt == LT_ERROR) |
| 765 | debug("eval%d: and always false", ops - eval_ops); | 832 | return (LT_ERROR); |
| 766 | if (lhs == LT_IF) | 833 | lt = op->fn(valp, lt, *valp, rt, val); |
| 767 | *valp = val; | ||
| 768 | lhs = LT_FALSE; | ||
| 769 | continue; | ||
| 770 | } | ||
| 771 | if (op->fn == op_or && (lhs == LT_TRUE || rhs == LT_TRUE)) { | ||
| 772 | debug("eval%d: or always true", ops - eval_ops); | ||
| 773 | if (lhs == LT_IF) | ||
| 774 | *valp = val; | ||
| 775 | lhs = LT_TRUE; | ||
| 776 | continue; | ||
| 777 | } | ||
| 778 | if (rhs == LT_IF) | ||
| 779 | lhs = LT_IF; | ||
| 780 | if (lhs != LT_IF) | ||
| 781 | *valp = op->fn(*valp, val); | ||
| 782 | } | 834 | } |
| 783 | 835 | ||
| 784 | *cpp = cp; | 836 | *cpp = cp; |
| 785 | debug("eval%d = %d", ops - eval_ops, *valp); | 837 | debug("eval%d = %d", ops - eval_ops, *valp); |
| 786 | if (lhs != LT_IF) | 838 | debug("eval%d lt = %s", ops - eval_ops, linetype_name[lt]); |
| 787 | lhs = (*valp ? LT_TRUE : LT_FALSE); | 839 | return (lt); |
| 788 | return lhs; | ||
| 789 | } | 840 | } |
| 790 | 841 | ||
| 791 | /* | 842 | /* |
| @@ -796,17 +847,14 @@ eval_table(const struct ops *ops, int *valp, const char **cpp) | |||
| 796 | static Linetype | 847 | static Linetype |
| 797 | ifeval(const char **cpp) | 848 | ifeval(const char **cpp) |
| 798 | { | 849 | { |
| 799 | const char *cp = *cpp; | ||
| 800 | int ret; | 850 | int ret; |
| 801 | int val; | 851 | int val = 0; |
| 802 | 852 | ||
| 803 | debug("eval %s", *cpp); | 853 | debug("eval %s", *cpp); |
| 804 | keepthis = killconsts ? false : true; | 854 | constexpr = killconsts ? false : true; |
| 805 | ret = eval_table(eval_ops, &val, &cp); | 855 | ret = eval_table(eval_ops, &val, cpp); |
| 806 | if (ret != LT_IF) | ||
| 807 | *cpp = cp; | ||
| 808 | debug("eval = %d", val); | 856 | debug("eval = %d", val); |
| 809 | return (keepthis ? LT_IF : ret); | 857 | return (constexpr ? LT_IF : ret == LT_ERROR ? LT_IF : ret); |
| 810 | } | 858 | } |
| 811 | 859 | ||
| 812 | /* | 860 | /* |
| @@ -918,6 +966,31 @@ skipcomment(const char *cp) | |||
| 918 | } | 966 | } |
| 919 | 967 | ||
| 920 | /* | 968 | /* |
| 969 | * Skip macro arguments. | ||
| 970 | */ | ||
| 971 | static const char * | ||
| 972 | skipargs(const char *cp) | ||
| 973 | { | ||
| 974 | const char *ocp = cp; | ||
| 975 | int level = 0; | ||
| 976 | cp = skipcomment(cp); | ||
| 977 | if (*cp != '(') | ||
| 978 | return (cp); | ||
| 979 | do { | ||
| 980 | if (*cp == '(') | ||
| 981 | level++; | ||
| 982 | if (*cp == ')') | ||
| 983 | level--; | ||
| 984 | cp = skipcomment(cp+1); | ||
| 985 | } while (level != 0 && *cp != '\0'); | ||
| 986 | if (level == 0) | ||
| 987 | return (cp); | ||
| 988 | else | ||
| 989 | /* Rewind and re-detect the syntax error later. */ | ||
| 990 | return (ocp); | ||
| 991 | } | ||
| 992 | |||
| 993 | /* | ||
| 921 | * Skip over an identifier. | 994 | * Skip over an identifier. |
| 922 | */ | 995 | */ |
| 923 | static const char * | 996 | static const char * |
| @@ -929,7 +1002,7 @@ skipsym(const char *cp) | |||
| 929 | } | 1002 | } |
| 930 | 1003 | ||
| 931 | /* | 1004 | /* |
| 932 | * Look for the symbol in the symbol table. If is is found, we return | 1005 | * Look for the symbol in the symbol table. If it is found, we return |
| 933 | * the symbol table index, else we return -1. | 1006 | * the symbol table index, else we return -1. |
| 934 | */ | 1007 | */ |
| 935 | static int | 1008 | static int |
