diff options
author | Michael Forney <forney@google.com> | 2018-03-18 17:54:02 -0700 |
---|---|---|
committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2018-03-26 02:01:24 +0900 |
commit | a670b0b4aed129dc11b465c1c330bfe9202023e5 (patch) | |
tree | b92c66454350b3be0f8197877022122c81bc8f20 /scripts | |
parent | 3fdc7d3fe4c04bab0305838cf662ae30051cc192 (diff) |
kbuild: Use ls(1) instead of stat(1) to obtain file size
stat(1) is not standardized and different implementations have their own
(conflicting) flags for querying the size of a file.
ls(1) provides the same information (value of st.st_size) in the 5th
column, except when the file is a character or block device. This output
is standardized[0]. The -n option turns on -l, which writes lines
formatted like
"%s %u %s %s %u %s %s\n", <file mode>, <number of links>,
<owner name>, <group name>, <size>, <date and time>,
<pathname>
but instead of writing the <owner name> and <group name>, it writes the
numeric owner and group IDs (this avoids /etc/passwd and /etc/group
lookups as well as potential field splitting issues).
The <size> field is specified as "the value that would be returned for
the file in the st_size field of struct stat".
To avoid duplicating logic in several locations in the tree, create
scripts/file-size.sh and update callers to use that instead of stat(1).
[0] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html#tag_20_73_10
Signed-off-by: Michael Forney <forney@google.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/Makefile.lib | 2 | ||||
-rwxr-xr-x | scripts/file-size.sh | 4 | ||||
-rwxr-xr-x | scripts/link-vmlinux.sh | 4 |
3 files changed, 7 insertions, 3 deletions
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 5fd60af76d98..ef592e993e92 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -329,7 +329,7 @@ dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp) size_append = printf $(shell \ dec_size=0; \ for F in $1; do \ - fsize=$$(stat -c "%s" $$F); \ + fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F); \ dec_size=$$(expr $$dec_size + $$fsize); \ done; \ printf "%08x\n" $$dec_size | \ diff --git a/scripts/file-size.sh b/scripts/file-size.sh new file mode 100755 index 000000000000..7eb7423416b5 --- /dev/null +++ b/scripts/file-size.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +set -- $(ls -dn "$1") +printf '%s\n' "$5" diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 08ca08e9105c..9045823c7be7 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -269,8 +269,8 @@ if [ -n "${CONFIG_KALLSYMS}" ]; then kallsyms .tmp_vmlinux2 .tmp_kallsyms2.o # step 3 - size1=$(stat -c "%s" .tmp_kallsyms1.o) - size2=$(stat -c "%s" .tmp_kallsyms2.o) + size1=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" .tmp_kallsyms1.o) + size2=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" .tmp_kallsyms2.o) if [ $size1 -ne $size2 ] || [ -n "${KALLSYMS_EXTRA_PASS}" ]; then kallsymso=.tmp_kallsyms3.o |