summaryrefslogtreecommitdiff
path: root/usr
diff options
context:
space:
mode:
Diffstat (limited to 'usr')
-rw-r--r--usr/Kconfig6
-rw-r--r--usr/Makefile15
-rw-r--r--usr/dummy-include/stdbool.h7
-rw-r--r--usr/dummy-include/stdlib.h7
-rw-r--r--usr/gen_init_cpio.c343
-rwxr-xr-xusr/gen_initramfs.sh23
-rw-r--r--usr/include/Makefile41
-rwxr-xr-xusr/include/headers_check.pl77
8 files changed, 294 insertions, 225 deletions
diff --git a/usr/Kconfig b/usr/Kconfig
index 8bbcf699fe3b..9279a2893ab0 100644
--- a/usr/Kconfig
+++ b/usr/Kconfig
@@ -185,9 +185,9 @@ config INITRAMFS_COMPRESSION_LZO
bool "LZO"
depends on RD_LZO
help
- It's compression ratio is the second poorest amongst the choices. The
- kernel size is about 10% bigger than gzip. Despite that, it's
- decompression speed is the second fastest and it's compression speed
+ Its compression ratio is the second poorest amongst the choices. The
+ kernel size is about 10% bigger than gzip. Despite that, its
+ decompression speed is the second fastest and its compression speed
is quite fast too.
If you choose this, keep in mind that you may need to install the lzop
diff --git a/usr/Makefile b/usr/Makefile
index cc0d2824e100..e8f42478a0b7 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -3,7 +3,7 @@
# kbuild file for usr/ - including initramfs image
#
-compress-y := shipped
+compress-y := copy
compress-$(CONFIG_INITRAMFS_COMPRESSION_GZIP) := gzip
compress-$(CONFIG_INITRAMFS_COMPRESSION_BZIP2) := bzip2
compress-$(CONFIG_INITRAMFS_COMPRESSION_LZMA) := lzma
@@ -16,13 +16,15 @@ obj-$(CONFIG_BLK_DEV_INITRD) := initramfs_data.o
$(obj)/initramfs_data.o: $(obj)/initramfs_inc_data
+hostprogs := gen_init_cpio
+
ramfs-input := $(CONFIG_INITRAMFS_SOURCE)
cpio-data :=
# If CONFIG_INITRAMFS_SOURCE is empty, generate a small initramfs with the
# default contents.
ifeq ($(ramfs-input),)
-ramfs-input := $(srctree)/$(src)/default_cpio_list
+ramfs-input := $(src)/default_cpio_list
endif
ifeq ($(words $(ramfs-input)),1)
@@ -37,7 +39,7 @@ endif
# .cpio.*, use it directly as an initramfs, and avoid double compression.
ifeq ($(words $(subst .cpio.,$(space),$(ramfs-input))),2)
cpio-data := $(ramfs-input)
-compress-y := shipped
+compress-y := copy
endif
endif
@@ -48,8 +50,6 @@ ifeq ($(cpio-data),)
cpio-data := $(obj)/initramfs_data.cpio
-hostprogs := gen_init_cpio
-
# .initramfs_data.cpio.d is used to identify all files included
# in initramfs and to detect if any files are added/removed.
# Removed files are identified by directory timestamp being updated
@@ -62,8 +62,9 @@ $(deps_initramfs): ;
quiet_cmd_initfs = GEN $@
cmd_initfs = \
$(CONFIG_SHELL) $< -o $@ -l $(obj)/.initramfs_data.cpio.d \
- $(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
- $(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID)) \
+ $(addprefix -u , $(CONFIG_INITRAMFS_ROOT_UID)) \
+ $(addprefix -g , $(CONFIG_INITRAMFS_ROOT_GID)) \
+ $(if $(KBUILD_BUILD_TIMESTAMP), -d "$(KBUILD_BUILD_TIMESTAMP)") \
$(ramfs-input)
# We rebuild initramfs_data.cpio if:
diff --git a/usr/dummy-include/stdbool.h b/usr/dummy-include/stdbool.h
new file mode 100644
index 000000000000..54ff9e9c90ac
--- /dev/null
+++ b/usr/dummy-include/stdbool.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _STDBOOL_H
+#define _STDBOOL_H
+
+#error "Please do not include <stdbool.h> from exported headers"
+
+#endif /* _STDBOOL_H */
diff --git a/usr/dummy-include/stdlib.h b/usr/dummy-include/stdlib.h
new file mode 100644
index 000000000000..e8c21888e371
--- /dev/null
+++ b/usr/dummy-include/stdlib.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _STDLIB_H
+#define _STDLIB_H
+
+#error "Please do not include <stdlib.h> from exported headers"
+
+#endif /* _STDLIB_H */
diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
index 0e2c8a5838b1..b7296edc6626 100644
--- a/usr/gen_init_cpio.c
+++ b/usr/gen_init_cpio.c
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: GPL-2.0
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
@@ -20,64 +23,75 @@
#define xstr(s) #s
#define str(s) xstr(s)
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define CPIO_HDR_LEN 110
+#define CPIO_TRAILER "TRAILER!!!"
+#define padlen(_off, _align) (((_align) - ((_off) & ((_align) - 1))) % (_align))
+/* zero-padding the filename field for data alignment is limited by PATH_MAX */
+static char padding[PATH_MAX];
static unsigned int offset;
static unsigned int ino = 721;
static time_t default_mtime;
+static bool do_file_mtime;
+static bool do_csum = false;
+static int outfd = STDOUT_FILENO;
+static unsigned int dalign;
struct file_handler {
const char *type;
int (*handler)(const char *line);
};
-static void push_string(const char *name)
+static int push_buf(const char *name, size_t name_len)
{
- unsigned int name_len = strlen(name) + 1;
+ ssize_t len;
+
+ len = write(outfd, name, name_len);
+ if (len != name_len)
+ return -1;
- fputs(name, stdout);
- putchar(0);
offset += name_len;
+ return 0;
}
-static void push_pad (void)
+static int push_pad(size_t padlen)
{
- while (offset & 3) {
- putchar(0);
- offset++;
- }
-}
+ ssize_t len = 0;
-static void push_rest(const char *name)
-{
- unsigned int name_len = strlen(name) + 1;
- unsigned int tmp_ofs;
+ if (!padlen)
+ return 0;
- fputs(name, stdout);
- putchar(0);
- offset += name_len;
+ if (padlen < sizeof(padding))
+ len = write(outfd, padding, padlen);
+ if (len != padlen)
+ return -1;
- tmp_ofs = name_len + 110;
- while (tmp_ofs & 3) {
- putchar(0);
- offset++;
- tmp_ofs++;
- }
+ offset += padlen;
+ return 0;
}
-static void push_hdr(const char *s)
+static int push_rest(const char *name, size_t name_len)
{
- fputs(s, stdout);
- offset += 110;
+ ssize_t len;
+
+ len = write(outfd, name, name_len);
+ if (len != name_len)
+ return -1;
+
+ offset += name_len;
+
+ return push_pad(padlen(name_len + CPIO_HDR_LEN, 4));
}
-static void cpio_trailer(void)
+static int cpio_trailer(void)
{
- char s[256];
- const char name[] = "TRAILER!!!";
+ int len;
+ unsigned int namesize = sizeof(CPIO_TRAILER);
- sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX"
+ len = dprintf(outfd, "%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X",
- "070701", /* magic */
+ do_csum ? "070702" : "070701", /* magic */
0, /* ino */
0, /* mode */
(long) 0, /* uid */
@@ -89,46 +103,58 @@ static void cpio_trailer(void)
0, /* minor */
0, /* rmajor */
0, /* rminor */
- (unsigned)strlen(name)+1, /* namesize */
+ namesize, /* namesize */
0); /* chksum */
- push_hdr(s);
- push_rest(name);
+ offset += len;
- while (offset % 512) {
- putchar(0);
- offset++;
- }
+ if (len != CPIO_HDR_LEN ||
+ push_rest(CPIO_TRAILER, namesize) < 0 ||
+ push_pad(padlen(offset, 512)) < 0)
+ return -1;
+
+ if (fsync(outfd) < 0 && errno != EINVAL)
+ return -1;
+
+ return 0;
}
static int cpio_mkslink(const char *name, const char *target,
unsigned int mode, uid_t uid, gid_t gid)
{
- char s[256];
+ int len;
+ unsigned int namesize, targetsize = strlen(target) + 1;
if (name[0] == '/')
name++;
- sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
+ namesize = strlen(name) + 1;
+
+ len = dprintf(outfd, "%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X",
- "070701", /* magic */
+ do_csum ? "070702" : "070701", /* magic */
ino++, /* ino */
S_IFLNK | mode, /* mode */
(long) uid, /* uid */
(long) gid, /* gid */
1, /* nlink */
(long) default_mtime, /* mtime */
- (unsigned)strlen(target)+1, /* filesize */
+ targetsize, /* filesize */
3, /* major */
1, /* minor */
0, /* rmajor */
0, /* rminor */
- (unsigned)strlen(name) + 1,/* namesize */
+ namesize, /* namesize */
0); /* chksum */
- push_hdr(s);
- push_string(name);
- push_pad();
- push_string(target);
- push_pad();
+ offset += len;
+
+ if (len != CPIO_HDR_LEN ||
+ push_buf(name, namesize) < 0 ||
+ push_pad(padlen(offset, 4)) < 0 ||
+ push_buf(target, targetsize) < 0 ||
+ push_pad(padlen(offset, 4)) < 0)
+ return -1;
+
return 0;
+
}
static int cpio_mkslink_line(const char *line)
@@ -152,13 +178,16 @@ static int cpio_mkslink_line(const char *line)
static int cpio_mkgeneric(const char *name, unsigned int mode,
uid_t uid, gid_t gid)
{
- char s[256];
+ int len;
+ unsigned int namesize;
if (name[0] == '/')
name++;
- sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
+ namesize = strlen(name) + 1;
+
+ len = dprintf(outfd, "%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X",
- "070701", /* magic */
+ do_csum ? "070702" : "070701", /* magic */
ino++, /* ino */
mode, /* mode */
(long) uid, /* uid */
@@ -170,10 +199,14 @@ static int cpio_mkgeneric(const char *name, unsigned int mode,
1, /* minor */
0, /* rmajor */
0, /* rminor */
- (unsigned)strlen(name) + 1,/* namesize */
+ namesize, /* namesize */
0); /* chksum */
- push_hdr(s);
- push_rest(name);
+ offset += len;
+
+ if (len != CPIO_HDR_LEN ||
+ push_rest(name, namesize) < 0)
+ return -1;
+
return 0;
}
@@ -241,7 +274,8 @@ static int cpio_mknod(const char *name, unsigned int mode,
uid_t uid, gid_t gid, char dev_type,
unsigned int maj, unsigned int min)
{
- char s[256];
+ int len;
+ unsigned int namesize;
if (dev_type == 'b')
mode |= S_IFBLK;
@@ -250,9 +284,11 @@ static int cpio_mknod(const char *name, unsigned int mode,
if (name[0] == '/')
name++;
- sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
+ namesize = strlen(name) + 1;
+
+ len = dprintf(outfd, "%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X",
- "070701", /* magic */
+ do_csum ? "070702" : "070701", /* magic */
ino++, /* ino */
mode, /* mode */
(long) uid, /* uid */
@@ -264,10 +300,14 @@ static int cpio_mknod(const char *name, unsigned int mode,
1, /* minor */
maj, /* rmajor */
min, /* rminor */
- (unsigned)strlen(name) + 1,/* namesize */
+ namesize, /* namesize */
0); /* chksum */
- push_hdr(s);
- push_rest(name);
+ offset += len;
+
+ if (len != CPIO_HDR_LEN ||
+ push_rest(name, namesize) < 0)
+ return -1;
+
return 0;
}
@@ -292,19 +332,42 @@ static int cpio_mknod_line(const char *line)
return rc;
}
+static int cpio_mkfile_csum(int fd, unsigned long size, uint32_t *csum)
+{
+ while (size) {
+ unsigned char filebuf[65536];
+ ssize_t this_read;
+ size_t i, this_size = MIN(size, sizeof(filebuf));
+
+ this_read = read(fd, filebuf, this_size);
+ if (this_read <= 0 || this_read > this_size)
+ return -1;
+
+ for (i = 0; i < this_read; i++)
+ *csum += filebuf[i];
+
+ size -= this_read;
+ }
+ /* seek back to the start for data segment I/O */
+ if (lseek(fd, 0, SEEK_SET) < 0)
+ return -1;
+
+ return 0;
+}
+
static int cpio_mkfile(const char *name, const char *location,
unsigned int mode, uid_t uid, gid_t gid,
unsigned int nlinks)
{
- char s[256];
- char *filebuf = NULL;
struct stat buf;
- long size;
- int file = -1;
- int retval;
+ unsigned long size;
+ int file, retval, len;
int rc = -1;
- int namesize;
+ time_t mtime;
+ int namesize, namepadlen;
unsigned int i;
+ uint32_t csum = 0;
+ ssize_t this_read;
mode |= S_IFREG;
@@ -320,69 +383,118 @@ static int cpio_mkfile(const char *name, const char *location,
goto error;
}
- if (buf.st_mtime > 0xffffffff) {
- fprintf(stderr, "%s: Timestamp exceeds maximum cpio timestamp, clipping.\n",
- location);
- buf.st_mtime = 0xffffffff;
+ if (do_file_mtime) {
+ mtime = default_mtime;
+ } else {
+ mtime = buf.st_mtime;
+ if (mtime > 0xffffffff) {
+ fprintf(stderr, "%s: Timestamp exceeds maximum cpio timestamp, clipping.\n",
+ location);
+ mtime = 0xffffffff;
+ }
+
+ if (mtime < 0) {
+ fprintf(stderr, "%s: Timestamp negative, clipping.\n",
+ location);
+ mtime = 0;
+ }
}
- filebuf = malloc(buf.st_size);
- if (!filebuf) {
- fprintf (stderr, "out of memory\n");
+ if (buf.st_size > 0xffffffff) {
+ fprintf(stderr, "%s: Size exceeds maximum cpio file size\n",
+ location);
goto error;
}
- retval = read (file, filebuf, buf.st_size);
- if (retval < 0) {
- fprintf (stderr, "Can not read %s file\n", location);
+ if (do_csum && cpio_mkfile_csum(file, buf.st_size, &csum) < 0) {
+ fprintf(stderr, "Failed to checksum file %s\n", location);
goto error;
}
size = 0;
+ namepadlen = 0;
for (i = 1; i <= nlinks; i++) {
- /* data goes on last link */
- if (i == nlinks) size = buf.st_size;
-
if (name[0] == '/')
name++;
namesize = strlen(name) + 1;
- sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
+
+ /* data goes on last link, after any alignment padding */
+ if (i == nlinks)
+ size = buf.st_size;
+
+ if (dalign && size > dalign) {
+ namepadlen = padlen(offset + CPIO_HDR_LEN + namesize,
+ dalign);
+ if (namesize + namepadlen > PATH_MAX) {
+ fprintf(stderr,
+ "%s: best-effort alignment %u missed\n",
+ name, dalign);
+ namepadlen = 0;
+ }
+ }
+
+ len = dprintf(outfd, "%s%08X%08X%08lX%08lX%08X%08lX"
"%08lX%08X%08X%08X%08X%08X%08X",
- "070701", /* magic */
+ do_csum ? "070702" : "070701", /* magic */
ino, /* ino */
mode, /* mode */
(long) uid, /* uid */
(long) gid, /* gid */
nlinks, /* nlink */
- (long) buf.st_mtime, /* mtime */
+ (long) mtime, /* mtime */
size, /* filesize */
3, /* major */
1, /* minor */
0, /* rmajor */
0, /* rminor */
- namesize, /* namesize */
- 0); /* chksum */
- push_hdr(s);
- push_string(name);
- push_pad();
+ namesize + namepadlen, /* namesize */
+ size ? csum : 0); /* chksum */
+ offset += len;
+
+ if (len != CPIO_HDR_LEN ||
+ push_buf(name, namesize) < 0 ||
+ push_pad(namepadlen ? namepadlen : padlen(offset, 4)) < 0)
+ goto error;
if (size) {
- if (fwrite(filebuf, size, 1, stdout) != 1) {
+ this_read = copy_file_range(file, NULL, outfd, NULL, size, 0);
+ if (this_read > 0) {
+ if (this_read > size)
+ goto error;
+ offset += this_read;
+ size -= this_read;
+ }
+ /* short or failed copy falls back to read/write... */
+ }
+
+ while (size) {
+ unsigned char filebuf[65536];
+ size_t this_size = MIN(size, sizeof(filebuf));
+
+ this_read = read(file, filebuf, this_size);
+ if (this_read <= 0 || this_read > this_size) {
+ fprintf(stderr, "Can not read %s file\n", location);
+ goto error;
+ }
+
+ if (write(outfd, filebuf, this_read) != this_read) {
fprintf(stderr, "writing filebuf failed\n");
goto error;
}
- offset += size;
- push_pad();
+ offset += this_read;
+ size -= this_read;
}
+ if (push_pad(padlen(offset, 4)) < 0)
+ goto error;
name += namesize;
}
ino++;
rc = 0;
-
+
error:
- if (filebuf) free(filebuf);
- if (file >= 0) close(file);
+ if (file >= 0)
+ close(file);
return rc;
}
@@ -458,7 +570,7 @@ static int cpio_mkfile_line(const char *line)
static void usage(const char *prog)
{
fprintf(stderr, "Usage:\n"
- "\t%s [-t <timestamp>] <cpio_list>\n"
+ "\t%s [-t <timestamp>] [-c] [-o <output_file>] [-a <data_align>] <cpio_list>\n"
"\n"
"<cpio_list> is a file containing newline separated entries that\n"
"describe the files to be included in the initramfs archive:\n"
@@ -492,8 +604,14 @@ static void usage(const char *prog)
"file /sbin/kinit /usr/src/klibc/kinit/kinit 0755 0 0\n"
"\n"
"<timestamp> is time in seconds since Epoch that will be used\n"
- "as mtime for symlinks, special files and directories. The default\n"
- "is to use the current time for these entries.\n",
+ "as mtime for symlinks, directories, regular and special files.\n"
+ "The default is to use the current time for all files, but\n"
+ "preserve modification time for regular files.\n"
+ "-c: calculate and store 32-bit checksums for file data.\n"
+ "<output_file>: write cpio to this file instead of stdout\n"
+ "<data_align>: attempt to align file data by zero-padding the\n"
+ "filename field up to data_align. Must be a multiple of 4.\n"
+ "Alignment is best-effort; PATH_MAX limits filename padding.\n",
prog);
}
@@ -535,7 +653,7 @@ int main (int argc, char *argv[])
default_mtime = time(NULL);
while (1) {
- int opt = getopt(argc, argv, "t:h");
+ int opt = getopt(argc, argv, "t:cho:a:");
char *invalid;
if (opt == -1)
@@ -549,6 +667,29 @@ int main (int argc, char *argv[])
usage(argv[0]);
exit(1);
}
+ do_file_mtime = true;
+ break;
+ case 'c':
+ do_csum = true;
+ break;
+ case 'o':
+ outfd = open(optarg,
+ O_WRONLY | O_CREAT | O_LARGEFILE | O_TRUNC,
+ 0600);
+ if (outfd < 0) {
+ fprintf(stderr, "failed to open %s\n", optarg);
+ usage(argv[0]);
+ exit(1);
+ }
+ break;
+ case 'a':
+ dalign = strtoul(optarg, &invalid, 10);
+ if (!*optarg || *invalid || (dalign & 3)) {
+ fprintf(stderr, "Invalid data_align: %s\n",
+ optarg);
+ usage(argv[0]);
+ exit(1);
+ }
break;
case 'h':
case '?':
@@ -560,10 +701,10 @@ int main (int argc, char *argv[])
/*
* Timestamps after 2106-02-07 06:28:15 UTC have an ascii hex time_t
* representation that exceeds 8 chars and breaks the cpio header
- * specification.
+ * specification. Negative timestamps similarly exceed 8 chars.
*/
- if (default_mtime > 0xffffffff) {
- fprintf(stderr, "ERROR: Timestamp too large for cpio format\n");
+ if (default_mtime > 0xffffffff || default_mtime < 0) {
+ fprintf(stderr, "ERROR: Timestamp out of range for cpio format\n");
exit(1);
}
@@ -634,7 +775,7 @@ int main (int argc, char *argv[])
}
}
if (ec == 0)
- cpio_trailer();
+ ec = cpio_trailer();
exit(ec);
}
diff --git a/usr/gen_initramfs.sh b/usr/gen_initramfs.sh
index 63476bb70b41..7eba2fddf0ef 100755
--- a/usr/gen_initramfs.sh
+++ b/usr/gen_initramfs.sh
@@ -23,6 +23,7 @@ $0 [-o <file>] [-l <dep_list>] [-u <uid>] [-g <gid>] {-d | <cpio_source>} ...
-g <gid> Group ID to map to group ID 0 (root).
<gid> is only meaningful if <cpio_source> is a
directory. "squash" forces all files to gid 0.
+ -d <date> Use date for all file mtime values
<cpio_source> File list or directory for cpio archive.
If <cpio_source> is a .cpio file it will be used
as direct input to initramfs.
@@ -190,8 +191,10 @@ prog=$0
root_uid=0
root_gid=0
dep_list=
+timestamp=
cpio_list=$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)
-output="/dev/stdout"
+# gen_init_cpio writes to stdout by default
+output=""
trap "rm -f $cpio_list" EXIT
@@ -205,7 +208,7 @@ while [ $# -gt 0 ]; do
shift
;;
"-o") # generate cpio image named $1
- output="$1"
+ output="-o $1"
shift
;;
"-u") # map $1 to uid=0 (root)
@@ -218,6 +221,13 @@ while [ $# -gt 0 ]; do
[ "$root_gid" = "-1" ] && root_gid=$(id -g || echo 0)
shift
;;
+ "-d") # date for file mtimes
+ timestamp="$(date -d"$1" +%s || :)"
+ if test -n "$timestamp"; then
+ timestamp="-t $timestamp"
+ fi
+ shift
+ ;;
"-h")
usage
exit 0
@@ -237,11 +247,4 @@ done
# If output_file is set we will generate cpio archive
# we are careful to delete tmp files
-timestamp=
-if test -n "$KBUILD_BUILD_TIMESTAMP"; then
- timestamp="$(date -d"$KBUILD_BUILD_TIMESTAMP" +%s || :)"
- if test -n "$timestamp"; then
- timestamp="-t $timestamp"
- fi
-fi
-usr/gen_init_cpio $timestamp $cpio_list > $output
+usr/gen_init_cpio $output $timestamp $cpio_list
diff --git a/usr/include/Makefile b/usr/include/Makefile
index 7be7468c177b..d8a508042fed 100644
--- a/usr/include/Makefile
+++ b/usr/include/Makefile
@@ -6,13 +6,9 @@
#
# -std=c90 (equivalent to -ansi) catches the violation of those.
# We cannot go as far as adding -Wpedantic since it emits too many warnings.
-UAPI_CFLAGS := -std=c90 -Wall -Werror=implicit-function-declaration
+UAPI_CFLAGS := -std=c90 -Werror=implicit-function-declaration
-# In theory, we do not care -m32 or -m64 for header compile tests.
-# It is here just because CONFIG_CC_CAN_LINK is tested with -m32 or -m64.
-UAPI_CFLAGS += $(filter -m32 -m64, $(KBUILD_CFLAGS))
-
-override c_flags = $(UAPI_CFLAGS) -Wp,-MMD,$(depfile) -I$(objtree)/usr/include
+override c_flags = $(KBUILD_USERCFLAGS) $(UAPI_CFLAGS) -Wp,-MMD,$(depfile) -I $(obj) -I $(srctree)/usr/dummy-include
# The following are excluded for now because they fail to build.
#
@@ -20,27 +16,20 @@ override c_flags = $(UAPI_CFLAGS) -Wp,-MMD,$(depfile) -I$(objtree)/usr/include
# Please consider to fix the header first.
#
# Sorted alphabetically.
-no-header-test += asm/shmbuf.h
-no-header-test += asm/signal.h
no-header-test += asm/ucontext.h
no-header-test += drm/vmwgfx_drm.h
no-header-test += linux/am437x-vpfe.h
-no-header-test += linux/android/binder.h
-no-header-test += linux/android/binderfs.h
no-header-test += linux/coda.h
+no-header-test += linux/cyclades.h
no-header-test += linux/errqueue.h
-no-header-test += linux/fsmap.h
no-header-test += linux/hdlc/ioctl.h
no-header-test += linux/ivtv.h
-no-header-test += linux/kexec.h
no-header-test += linux/matroxfb.h
no-header-test += linux/omap3isp.h
no-header-test += linux/omapfb.h
no-header-test += linux/patchkey.h
no-header-test += linux/phonet.h
-no-header-test += linux/reiserfs_xattr.h
no-header-test += linux/sctp.h
-no-header-test += linux/signal.h
no-header-test += linux/sysctl.h
no-header-test += linux/usb/audio.h
no-header-test += linux/v4l2-mediabus.h
@@ -63,27 +52,15 @@ ifeq ($(SRCARCH),arc)
no-header-test += linux/bpf_perf_event.h
endif
-ifeq ($(SRCARCH),ia64)
-no-header-test += asm/setup.h
-no-header-test += asm/sigcontext.h
-no-header-test += linux/if_bonding.h
-endif
-
-ifeq ($(SRCARCH),mips)
-no-header-test += asm/stat.h
-endif
-
-ifeq ($(SRCARCH),powerpc)
-no-header-test += asm/stat.h
+ifeq ($(SRCARCH),openrisc)
no-header-test += linux/bpf_perf_event.h
endif
-ifeq ($(SRCARCH),riscv)
+ifeq ($(SRCARCH),powerpc)
no-header-test += linux/bpf_perf_event.h
endif
ifeq ($(SRCARCH),sparc)
-no-header-test += asm/stat.h
no-header-test += asm/uctx.h
no-header-test += asm/fbio.h
endif
@@ -91,17 +68,17 @@ endif
# asm-generic/*.h is used by asm/*.h, and should not be included directly
no-header-test += asm-generic/%
-extra-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/dev/null))
+always-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/dev/null))
# Include the header twice to detect missing include guard.
quiet_cmd_hdrtest = HDRTEST $<
cmd_hdrtest = \
- $(CC) $(c_flags) -S -o /dev/null -x c /dev/null \
+ $(CC) $(c_flags) -fsyntax-only -Werror -x c /dev/null \
$(if $(filter-out $(no-header-test), $*.h), -include $< -include $<); \
- $(PERL) $(srctree)/$(src)/headers_check.pl $(obj) $(SRCARCH) $<; \
+ $(PERL) $(src)/headers_check.pl $(obj) $<; \
touch $@
-$(obj)/%.hdrtest: $(obj)/%.h FORCE
+$(obj)/%.hdrtest: $(obj)/%.h $(src)/headers_check.pl FORCE
$(call if_changed_dep,hdrtest)
# Since GNU Make 4.3, $(patsubst $(obj)/%/,%,$(wildcard $(obj)/*/)) works.
diff --git a/usr/include/headers_check.pl b/usr/include/headers_check.pl
index b6aec5e4365f..af5a513eaa00 100755
--- a/usr/include/headers_check.pl
+++ b/usr/include/headers_check.pl
@@ -3,9 +3,8 @@
#
# headers_check.pl execute a number of trivial consistency checks
#
-# Usage: headers_check.pl dir arch [files...]
+# Usage: headers_check.pl dir [files...]
# dir: dir to look for included files
-# arch: architecture
# files: list of files to check
#
# The script reads the supplied files line by line and:
@@ -23,7 +22,7 @@ use warnings;
use strict;
use File::Basename;
-my ($dir, $arch, @files) = @ARGV;
+my ($dir, @files) = @ARGV;
my $ret = 0;
my $line;
@@ -40,7 +39,6 @@ foreach my $file (@files) {
$lineno++;
&check_include();
&check_asm_types();
- &check_sizetypes();
&check_declarations();
# Dropped for now. Too much noise &check_config();
}
@@ -55,10 +53,6 @@ sub check_include
my $found;
$found = stat($dir . "/" . $inc);
if (!$found) {
- $inc =~ s#asm/#asm-$arch/#;
- $found = stat($dir . "/" . $inc);
- }
- if (!$found) {
printf STDERR "$filename:$lineno: included file '$inc' is not exported\n";
$ret = 1;
}
@@ -79,6 +73,7 @@ sub check_declarations
printf STDERR "$filename:$lineno: " .
"userspace cannot reference function or " .
"variable defined in the kernel\n";
+ $ret = 1;
}
}
@@ -103,69 +98,7 @@ sub check_asm_types
if ($line =~ m/^\s*#\s*include\s+<asm\/types.h>/) {
$linux_asm_types = 1;
printf STDERR "$filename:$lineno: " .
- "include of <linux/types.h> is preferred over <asm/types.h>\n"
- # Warn until headers are all fixed
- #$ret = 1;
- }
-}
-
-my $linux_types;
-my %import_stack = ();
-sub check_include_typesh
-{
- my $path = $_[0];
- my $import_path;
-
- my $fh;
- my @file_paths = ($path, $dir . "/" . $path, dirname($filename) . "/" . $path);
- for my $possible ( @file_paths ) {
- if (not $import_stack{$possible} and open($fh, '<', $possible)) {
- $import_path = $possible;
- $import_stack{$import_path} = 1;
- last;
- }
- }
- if (eof $fh) {
- return;
- }
-
- my $line;
- while ($line = <$fh>) {
- if ($line =~ m/^\s*#\s*include\s+<linux\/types.h>/) {
- $linux_types = 1;
- last;
- }
- if (my $included = ($line =~ /^\s*#\s*include\s+[<"](\S+)[>"]/)[0]) {
- check_include_typesh($included);
- }
- }
- close $fh;
- delete $import_stack{$import_path};
-}
-
-sub check_sizetypes
-{
- if ($filename =~ /types.h|int-l64.h|int-ll64.h/o) {
- return;
- }
- if ($lineno == 1) {
- $linux_types = 0;
- } elsif ($linux_types >= 1) {
- return;
- }
- if ($line =~ m/^\s*#\s*include\s+<linux\/types.h>/) {
- $linux_types = 1;
- return;
- }
- if (my $included = ($line =~ /^\s*#\s*include\s+[<"](\S+)[>"]/)[0]) {
- check_include_typesh($included);
- }
- if ($line =~ m/__[us](8|16|32|64)\b/) {
- printf STDERR "$filename:$lineno: " .
- "found __[us]{8,16,32,64} type " .
- "without #include <linux/types.h>\n";
- $linux_types = 2;
- # Warn until headers are all fixed
- #$ret = 1;
+ "include of <linux/types.h> is preferred over <asm/types.h>\n";
+ $ret = 1;
}
}