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 @@
# are not supported by all versions of the compiler
# ==========================================================================
KBUILD_CFLAGS += $(call cc-disable-warning, packed-not-aligned)
ifeq ("$(origin W)", "command line")
export KBUILD_ENABLE_EXTRA_GCC_CHECKS := $(W)
endif
......@@ -26,6 +28,7 @@ warning-1 += -Wold-style-definition
warning-1 += $(call cc-option, -Wmissing-include-dirs)
warning-1 += $(call cc-option, -Wunused-but-set-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, sign-compare)
......
......@@ -264,7 +264,7 @@ cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \
DTC ?= $(objtree)/scripts/dtc/dtc
# 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 \
-Wno-simple_bus_reg \
-Wno-unit_address_format \
......@@ -273,7 +273,7 @@ DTC_FLAGS += -Wno-unit_address_vs_reg \
-Wno-pci_device_reg
endif
ifeq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),2)
ifneq ($(findstring 2,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),)
DTC_FLAGS += -Wnode_name_chars_strict \
-Wproperty_name_chars_strict
endif
......
......@@ -104,20 +104,12 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <ctype.h>
#include <arpa/inet.h>
int insert_extra_deps;
char *target;
char *depfile;
char *cmdline;
static void usage(void)
{
......@@ -126,14 +118,6 @@ static void usage(void)
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
*/
......@@ -155,16 +139,16 @@ static void print_config(const char *m, int slen)
static void do_extra_deps(void)
{
if (insert_extra_deps) {
char buf[80];
while(fgets(buf, sizeof(buf), stdin)) {
while (fgets(buf, sizeof(buf), stdin)) {
int len = strlen(buf);
if (len < 2 || buf[len-1] != '\n') {
if (len < 2 || buf[len - 1] != '\n') {
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)
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)
{
const char *q, *r;
......@@ -244,7 +239,7 @@ static void parse_config_file(const char *p)
q = p;
while (*q && (isalnum(*q) || *q == '_'))
q++;
if (memcmp(q - 7, "_MODULE", 7) == 0)
if (str_ends_with(p, q - p, "_MODULE"))
r = q - 7;
else
r = q;
......@@ -254,56 +249,46 @@ static void parse_config_file(const char *p)
}
}
/* test if s ends in sub */
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)
static void *read_file(const char *filename)
{
struct stat st;
int fd;
char *map;
char *buf;
fd = open(filename, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "fixdep: error opening config file: ");
fprintf(stderr, "fixdep: error opening file: ");
perror(filename);
exit(2);
}
if (fstat(fd, &st) < 0) {
fprintf(stderr, "fixdep: error fstat'ing config file: ");
fprintf(stderr, "fixdep: error fstat'ing file: ");
perror(filename);
exit(2);
}
if (st.st_size == 0) {
close(fd);
return;
}
map = malloc(st.st_size + 1);
if (!map) {
buf = malloc(st.st_size + 1);
if (!buf) {
perror("fixdep: malloc");
close(fd);
return;
exit(2);
}
if (read(fd, map, st.st_size) != st.st_size) {
if (read(fd, buf, st.st_size) != st.st_size) {
perror("fixdep: read");
close(fd);
return;
exit(2);
}
map[st.st_size] = '\0';
buf[st.st_size] = '\0';
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)
* assignments are parsed not only by make, but also by the rather simple
* 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 s[PATH_MAX];
int is_target;
int is_last, is_target;
int saw_any_target = 0;
int is_first_dep = 0;
void *buf;
while (m < end) {
while (1) {
/* Skip any "white space" */
while (m < end && (*m == ' ' || *m == '\\' || *m == '\n'))
while (*m == ' ' || *m == '\\' || *m == '\n')
m++;
if (!*m)
break;
/* Find next "white space" */
p = m;
while (p < end && *p != ' ' && *p != '\\' && *p != '\n')
while (*p && *p != ' ' && *p != '\\' && *p != '\n')
p++;
is_last = (*p == '\0');
/* Is the token we found a target name? */
is_target = (*(p-1) == ':');
/* Don't write any target names into the dependency file */
if (is_target) {
/* The /next/ file is the first dependency */
is_first_dep = 1;
} else {
/* Save this token/filename */
memcpy(s, m, p-m);
s[p - m] = 0;
/* Ignore certain dependencies */
if (strrcmp(s, "include/generated/autoconf.h") &&
strrcmp(s, "include/generated/autoksyms.h") &&
strrcmp(s, "arch/um/include/uml-config.h") &&
strrcmp(s, "include/linux/kconfig.h") &&
strrcmp(s, ".ver")) {
} else if (!is_ignored_file(m, p - m)) {
*p = '\0';
/*
* Do not list the source file as dependency,
* so that kbuild is not confused if a .c file
* is rewritten into .S or vice versa. Storing
* it in source_* is needed for modpost to
* compute srcversions.
* Do not list the source file as dependency, so that
* kbuild is not confused if a .c file is rewritten
* into .S or vice versa. Storing it in source_* is
* needed for modpost to compute srcversions.
*/
if (is_first_dep) {
/*
* If processing the concatenation of
* multiple dependency files, only
* process the first target name, which
* will be the original source name,
* and ignore any other target names,
* which will be intermediate temporary
* If processing the concatenation of multiple
* dependency files, only process the first
* target name, which will be the original
* source name, and ignore any other target
* names, which will be intermediate temporary
* files.
*/
if (!saw_any_target) {
saw_any_target = 1;
printf("source_%s := %s\n\n",
target, s);
printf("deps_%s := \\\n",
target);
target, m);
printf("deps_%s := \\\n", target);
}
is_first_dep = 0;
} else
printf(" %s \\\n", s);
do_config_file(s);
} else {
printf(" %s \\\n", m);
}
buf = read_file(m);
parse_config_file(buf);
free(buf);
}
if (is_last)
break;
/*
* Start searching for next token immediately after the first
* "whitespace" character that follows this token.
......@@ -388,50 +372,19 @@ static void parse_dep_file(void *map, size_t len)
exit(1);
}
if (insert_extra_deps)
do_extra_deps();
printf("\n%s: $(deps_%s)\n\n", target, 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[])
{
const char *depfile, *target, *cmdline;
int insert_extra_deps = 0;
void *buf;
if (argc == 5 && !strcmp(argv[1], "-e")) {
insert_extra_deps = 1;
argv++;
......@@ -442,8 +395,11 @@ int main(int argc, char *argv[])
target = argv[2];
cmdline = argv[3];
print_cmdline();
print_deps();
printf("cmd_%s := %s\n\n", target, cmdline);
buf = read_file(depfile);
parse_dep_file(buf, target, insert_extra_deps);
free(buf);
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