Commit 06c8f7a7 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'kbuild-v4.16' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild

Pull Kbuild updates from Masahiro Yamada:

 - terminate the build correctly in case of fixdep errors

 - clean up fixdep

 - suppress packed-not-aligned warnings from GCC-8

 - fix W= handling for extra DTC warnings

* tag 'kbuild-v4.16' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild:
  kbuild: fix W= option checks for extra DTC warnings
  Kbuild: suppress packed-not-aligned warning for default setting only
  fixdep: use existing helper to check modular CONFIG options
  fixdep: refactor parse_dep_file()
  fixdep: move global variables to local variables of main()
  fixdep: remove unneeded memcpy() in parse_dep_file()
  fixdep: factor out common code for reading files
  fixdep: use malloc() and read() to load dep_file to buffer
  fixdep: remove unnecessary <arpa/inet.h> inclusion
  fixdep: exit with error code in error branches of do_config_file()
parents 2bed2660 f759625a
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
# are not supported by all versions of the compiler # are not supported by all versions of the compiler
# ========================================================================== # ==========================================================================
KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
ifeq ("$(origin W)", "command line") ifeq ("$(origin W)", "command line")
export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W) export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W)
endif endif
...@@ -26,6 +28,7 @@ warning-1 += -Wold-style-definition ...@@ -26,6 +28,7 @@ warning-1 += -Wold-style-definition
warning-1 += $(call cc-option, -Wmissing-include-dirs) warning-1 += $(call cc-option, -Wmissing-include-dirs)
warning-1 += $(call cc-option, -Wunused-but-set-variable) warning-1 += $(call cc-option, -Wunused-but-set-variable)
warning-1 += $(call cc-option, -Wunused-const-variable) warning-1 += $(call cc-option, -Wunused-const-variable)
warning-1 += $(call cc-option, -Wpacked-not-aligned)
warning-1 += $(call cc-disable-warning, missing-field-initializers) warning-1 += $(call cc-disable-warning, missing-field-initializers)
warning-1 += $(call cc-disable-warning, sign-compare) warning-1 += $(call cc-disable-warning, sign-compare)
......
...@@ -264,7 +264,7 @@ cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \ ...@@ -264,7 +264,7 @@ cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \
DTC ?= $(objtree)/scripts/dtc/dtc DTC ?= $(objtree)/scripts/dtc/dtc
# Disable noisy checks by default # Disable noisy checks by default
ifeq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),) ifeq ($(findstring 1,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),)
DTC_FLAGS += -Wno-unit_address_vs_reg \ DTC_FLAGS += -Wno-unit_address_vs_reg \
-Wno-simple_bus_reg \ -Wno-simple_bus_reg \
-Wno-unit_address_format \ -Wno-unit_address_format \
...@@ -273,7 +273,7 @@ DTC_FLAGS += -Wno-unit_address_vs_reg \ ...@@ -273,7 +273,7 @@ DTC_FLAGS += -Wno-unit_address_vs_reg \
-Wno-pci_device_reg -Wno-pci_device_reg
endif endif
ifeq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),2) ifneq ($(findstring 2,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),)
DTC_FLAGS += -Wnode_name_chars_strict \ DTC_FLAGS += -Wnode_name_chars_strict \
-Wproperty_name_chars_strict -Wproperty_name_chars_strict
endif endif
......
...@@ -104,20 +104,12 @@ ...@@ -104,20 +104,12 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <limits.h>
#include <ctype.h> #include <ctype.h>
#include <arpa/inet.h>
int insert_extra_deps;
char *target;
char *depfile;
char *cmdline;
static void usage(void) static void usage(void)
{ {
...@@ -126,14 +118,6 @@ static void usage(void) ...@@ -126,14 +118,6 @@ static void usage(void)
exit(1); exit(1);
} }
/*
* Print out the commandline prefixed with cmd_<target filename> :=
*/
static void print_cmdline(void)
{
printf("cmd_%s := %s\n\n", target, cmdline);
}
/* /*
* Print out a dependency path from a symbol name * Print out a dependency path from a symbol name
*/ */
...@@ -155,16 +139,16 @@ static void print_config(const char *m, int slen) ...@@ -155,16 +139,16 @@ static void print_config(const char *m, int slen)
static void do_extra_deps(void) static void do_extra_deps(void)
{ {
if (insert_extra_deps) { char buf[80];
char buf[80];
while(fgets(buf, sizeof(buf), stdin)) { while (fgets(buf, sizeof(buf), stdin)) {
int len = strlen(buf); int len = strlen(buf);
if (len < 2 || buf[len-1] != '\n') {
fprintf(stderr, "fixdep: bad data on stdin\n"); if (len < 2 || buf[len - 1] != '\n') {
exit(1); fprintf(stderr, "fixdep: bad data on stdin\n");
} exit(1);
print_config(buf, len-1);
} }
print_config(buf, len - 1);
} }
} }
...@@ -235,6 +219,17 @@ static void use_config(const char *m, int slen) ...@@ -235,6 +219,17 @@ static void use_config(const char *m, int slen)
print_config(m, slen); print_config(m, slen);
} }
/* test if s ends in sub */
static int str_ends_with(const char *s, int slen, const char *sub)
{
int sublen = strlen(sub);
if (sublen > slen)
return 0;
return !memcmp(s + slen - sublen, sub, sublen);
}
static void parse_config_file(const char *p) static void parse_config_file(const char *p)
{ {
const char *q, *r; const char *q, *r;
...@@ -244,7 +239,7 @@ static void parse_config_file(const char *p) ...@@ -244,7 +239,7 @@ static void parse_config_file(const char *p)
q = p; q = p;
while (*q && (isalnum(*q) || *q == '_')) while (*q && (isalnum(*q) || *q == '_'))
q++; q++;
if (memcmp(q - 7, "_MODULE", 7) == 0) if (str_ends_with(p, q - p, "_MODULE"))
r = q - 7; r = q - 7;
else else
r = q; r = q;
...@@ -254,56 +249,46 @@ static void parse_config_file(const char *p) ...@@ -254,56 +249,46 @@ static void parse_config_file(const char *p)
} }
} }
/* test if s ends in sub */ static void *read_file(const char *filename)
static int strrcmp(const char *s, const char *sub)
{
int slen = strlen(s);
int sublen = strlen(sub);
if (sublen > slen)
return 1;
return memcmp(s + slen - sublen, sub, sublen);
}
static void do_config_file(const char *filename)
{ {
struct stat st; struct stat st;
int fd; int fd;
char *map; char *buf;
fd = open(filename, O_RDONLY); fd = open(filename, O_RDONLY);
if (fd < 0) { if (fd < 0) {
fprintf(stderr, "fixdep: error opening config file: "); fprintf(stderr, "fixdep: error opening file: ");
perror(filename); perror(filename);
exit(2); exit(2);
} }
if (fstat(fd, &st) < 0) { if (fstat(fd, &st) < 0) {
fprintf(stderr, "fixdep: error fstat'ing config file: "); fprintf(stderr, "fixdep: error fstat'ing file: ");
perror(filename); perror(filename);
exit(2); exit(2);
} }
if (st.st_size == 0) { buf = malloc(st.st_size + 1);
close(fd); if (!buf) {
return;
}
map = malloc(st.st_size + 1);
if (!map) {
perror("fixdep: malloc"); perror("fixdep: malloc");
close(fd); exit(2);
return;
} }
if (read(fd, map, st.st_size) != st.st_size) { if (read(fd, buf, st.st_size) != st.st_size) {
perror("fixdep: read"); perror("fixdep: read");
close(fd); exit(2);
return;
} }
map[st.st_size] = '\0'; buf[st.st_size] = '\0';
close(fd); close(fd);
parse_config_file(map); return buf;
}
free(map); /* Ignore certain dependencies */
static int is_ignored_file(const char *s, int len)
{
return str_ends_with(s, len, "include/generated/autoconf.h") ||
str_ends_with(s, len, "include/generated/autoksyms.h") ||
str_ends_with(s, len, "arch/um/include/uml-config.h") ||
str_ends_with(s, len, "include/linux/kconfig.h") ||
str_ends_with(s, len, ".ver");
} }
/* /*
...@@ -311,71 +296,70 @@ static void do_config_file(const char *filename) ...@@ -311,71 +296,70 @@ static void do_config_file(const char *filename)
* assignments are parsed not only by make, but also by the rather simple * assignments are parsed not only by make, but also by the rather simple
* parser in scripts/mod/sumversion.c. * parser in scripts/mod/sumversion.c.
*/ */
static void parse_dep_file(void *map, size_t len) static void parse_dep_file(char *m, const char *target, int insert_extra_deps)
{ {
char *m = map;
char *end = m + len;
char *p; char *p;
char s[PATH_MAX]; int is_last, is_target;
int is_target;
int saw_any_target = 0; int saw_any_target = 0;
int is_first_dep = 0; int is_first_dep = 0;
void *buf;
while (m < end) { while (1) {
/* Skip any "white space" */ /* Skip any "white space" */
while (m < end && (*m == ' ' || *m == '\\' || *m == '\n')) while (*m == ' ' || *m == '\\' || *m == '\n')
m++; m++;
if (!*m)
break;
/* Find next "white space" */ /* Find next "white space" */
p = m; p = m;
while (p < end && *p != ' ' && *p != '\\' && *p != '\n') while (*p && *p != ' ' && *p != '\\' && *p != '\n')
p++; p++;
is_last = (*p == '\0');
/* Is the token we found a target name? */ /* Is the token we found a target name? */
is_target = (*(p-1) == ':'); is_target = (*(p-1) == ':');
/* Don't write any target names into the dependency file */ /* Don't write any target names into the dependency file */
if (is_target) { if (is_target) {
/* The /next/ file is the first dependency */ /* The /next/ file is the first dependency */
is_first_dep = 1; is_first_dep = 1;
} else { } else if (!is_ignored_file(m, p - m)) {
/* Save this token/filename */ *p = '\0';
memcpy(s, m, p-m);
s[p - m] = 0; /*
* Do not list the source file as dependency, so that
/* Ignore certain dependencies */ * kbuild is not confused if a .c file is rewritten
if (strrcmp(s, "include/generated/autoconf.h") && * into .S or vice versa. Storing it in source_* is
strrcmp(s, "include/generated/autoksyms.h") && * needed for modpost to compute srcversions.
strrcmp(s, "arch/um/include/uml-config.h") && */
strrcmp(s, "include/linux/kconfig.h") && if (is_first_dep) {
strrcmp(s, ".ver")) {
/* /*
* Do not list the source file as dependency, * If processing the concatenation of multiple
* so that kbuild is not confused if a .c file * dependency files, only process the first
* is rewritten into .S or vice versa. Storing * target name, which will be the original
* it in source_* is needed for modpost to * source name, and ignore any other target
* compute srcversions. * names, which will be intermediate temporary
* files.
*/ */
if (is_first_dep) { if (!saw_any_target) {
/* saw_any_target = 1;
* If processing the concatenation of printf("source_%s := %s\n\n",
* multiple dependency files, only target, m);
* process the first target name, which printf("deps_%s := \\\n", target);
* will be the original source name, }
* and ignore any other target names, is_first_dep = 0;
* which will be intermediate temporary } else {
* files. printf(" %s \\\n", m);
*/
if (!saw_any_target) {
saw_any_target = 1;
printf("source_%s := %s\n\n",
target, s);
printf("deps_%s := \\\n",
target);
}
is_first_dep = 0;
} else
printf(" %s \\\n", s);
do_config_file(s);
} }
buf = read_file(m);
parse_config_file(buf);
free(buf);
} }
if (is_last)
break;
/* /*
* Start searching for next token immediately after the first * Start searching for next token immediately after the first
* "whitespace" character that follows this token. * "whitespace" character that follows this token.
...@@ -388,50 +372,19 @@ static void parse_dep_file(void *map, size_t len) ...@@ -388,50 +372,19 @@ static void parse_dep_file(void *map, size_t len)
exit(1); exit(1);
} }
do_extra_deps(); if (insert_extra_deps)
do_extra_deps();
printf("\n%s: $(deps_%s)\n\n", target, target); printf("\n%s: $(deps_%s)\n\n", target, target);
printf("$(deps_%s):\n", target); printf("$(deps_%s):\n", target);
} }
static void print_deps(void)
{
struct stat st;
int fd;
void *map;
fd = open(depfile, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "fixdep: error opening depfile: ");
perror(depfile);
exit(2);
}
if (fstat(fd, &st) < 0) {
fprintf(stderr, "fixdep: error fstat'ing depfile: ");
perror(depfile);
exit(2);
}
if (st.st_size == 0) {
fprintf(stderr,"fixdep: %s is empty\n",depfile);
close(fd);
return;
}
map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if ((long) map == -1) {
perror("fixdep: mmap");
close(fd);
return;
}
parse_dep_file(map, st.st_size);
munmap(map, st.st_size);
close(fd);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
const char *depfile, *target, *cmdline;
int insert_extra_deps = 0;
void *buf;
if (argc == 5 && !strcmp(argv[1], "-e")) { if (argc == 5 && !strcmp(argv[1], "-e")) {
insert_extra_deps = 1; insert_extra_deps = 1;
argv++; argv++;
...@@ -442,8 +395,11 @@ int main(int argc, char *argv[]) ...@@ -442,8 +395,11 @@ int main(int argc, char *argv[])
target = argv[2]; target = argv[2];
cmdline = argv[3]; cmdline = argv[3];
print_cmdline(); printf("cmd_%s := %s\n\n", target, cmdline);
print_deps();
buf = read_file(depfile);
parse_dep_file(buf, target, insert_extra_deps);
free(buf);
return 0; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment