Gentoo Archives: gentoo-portage-dev

From: Mike Frysinger <vapier@g.o>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] [PATCH v2] install-qa-check.d: issue warnings for 32bit ELFs not using LFS
Date: Tue, 26 May 2015 14:24:45
Message-Id: 1432650278-31471-1-git-send-email-vapier@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH] install-qa-check.d: issue warnings for 32bit ELFs not using LFS by Mike Frysinger
1 From: Mike Frysinger <vapier@××××××××.org>
2
3 Start issuing QA warnings when ELFs are installed using the old 32bit
4 file interface. These programs can fail out right:
5 * working with large files (more than 2GiB) can return EOVERFLOW
6 * stating files on large filesystems w/64bit inodes can fail too
7
8 It also can lead to silent corruption that is hard to debug like when
9 one library/app is compiled using 64bit structures and tries to work
10 with another one that uses 32bit (or vice versa). This is because
11 the API in the header utilizes off_t's or structs (like stat) that
12 have off_t's embedded in them. By default, off_t is defined as an
13 off32_t, but when the code is compiled with -D_FILE_OFFSET_BITS=64,
14 it is transparently changed to off64_t. That means while one side
15 was compiled (w/out warnings) expecting 32bit structs, the other
16 was compiled (w/out warnings) expecting 64bit structs. The ABI is
17 different, but C does not support type checking, so no one notices.
18
19 The only sane way forward is to use LFS everywhere.
20
21 X-Gentoo-Bug: 549092
22 X-Gentoo-Bug-url: https://bugs.gentoo.org/549092
23 ---
24 v2
25 - do some word smithing in the commit message
26
27 bin/install-qa-check.d/10large-file-support | 158 ++++++++++++++++++++++++++++
28 1 file changed, 158 insertions(+)
29 create mode 100644 bin/install-qa-check.d/10large-file-support
30
31 diff --git a/bin/install-qa-check.d/10large-file-support b/bin/install-qa-check.d/10large-file-support
32 new file mode 100644
33 index 0000000..34726d7
34 --- /dev/null
35 +++ b/bin/install-qa-check.d/10large-file-support
36 @@ -0,0 +1,158 @@
37 +# Detect 32-bit builds that are using legacy 32-bit file interfaces.
38 +# https://en.wikipedia.org/wiki/Large_file_support
39 +#
40 +# We want to make sure everyone is using the 64-bit interfaces.
41 +# https://bugs.gentoo.org/471102
42 +
43 +# Lists gleaned from headers and this doc:
44 +# http://people.redhat.com/berrange/notes/largefile.html
45 +# http://opengroup.org/platform/lfs.html
46 +SYMBOLS=(
47 + # aio.h
48 + aio_cancel
49 + aio_error
50 + aio_fsync
51 + aio_read
52 + aio_return
53 + aio_suspend
54 + aio_write
55 + lio_listio
56 +
57 + # dirent.h
58 + alphasort
59 + getdirentries
60 + readdir
61 + readdir_r
62 + scandir
63 + scandirat
64 + versionsort
65 +
66 + # fcntl.h
67 + creat
68 + fallocate
69 + fopen
70 + fopenat
71 + freopen
72 + open
73 + openat
74 + posix_fadvise
75 + posix_fallocate
76 + __open
77 + __open_2
78 + __openat_2
79 +
80 + # ftw.h
81 + ftw
82 + nftw
83 +
84 + # glob.h
85 + glob
86 + globfree
87 +
88 + # stdio.h
89 + fgetpos
90 + fopen
91 + freopen
92 + fseeko
93 + fsetpos
94 + ftello
95 + tmpfile
96 +
97 + # stdlib.h
98 + mkostemp
99 + mkostemps
100 + mkstemp
101 + mkstemps
102 +
103 + # sys/mman.h
104 + mmap
105 +
106 + # sys/resource.h
107 + getrlimit
108 + prlimit
109 + setrlimit
110 +
111 + # sys/sendfile.h
112 + sendfile
113 +
114 + # sys/stat.h
115 + fstat
116 + fstatat
117 + lstat
118 + stat
119 + __fxstat
120 + __fxstatat
121 + __lxstat
122 + __xstat
123 +
124 + # sys/statfs.h
125 + fstatfs
126 +
127 + # sys/statvfs.h
128 + statvfs
129 + fstatvfs
130 +
131 + # unistd.h
132 + lockf
133 + lseek
134 + ftruncate
135 + pread
136 + preadv
137 + pwrite
138 + pwritev
139 + truncate
140 + __pread_chk
141 +)
142 +SYMBOLS_REGEX=$(printf '%s|' "${SYMBOLS[@]}")
143 +# The @@ part is to workaround a limitation in pax-utils w/versioned symbols.
144 +SYMBOLS_REGEX="^(${SYMBOLS_REGEX%|})(@@.*)?$"
145 +
146 +check_lfs() {
147 + local files=$(scanelf -F '%s %p' -qyRgs "-${SYMBOLS_REGEX}" "$@")
148 +
149 + if [[ -n ${files} ]]; then
150 + echo
151 + eqawarn "QA Notice: The following files were not built with LFS support:"
152 + eqawarn " Please see https://bugs.gentoo.org/471102 for details."
153 + eqawarn "${files}"
154 + echo
155 + fi
156 +}
157 +
158 +filtered_check_lfs() {
159 + if ! type -P scanelf >/dev/null || has binchecks ${RESTRICT}; then
160 + return
161 + fi
162 +
163 + # Only check glibc & uClibc libraries. Others are presumed to use LFS by
164 + # default (e.g. musl), or it's not relevant (e.g. newlib).
165 + case ${CHOST} in
166 + *-gnu*|*-uclibc*) ;;
167 + *) return ;;
168 + esac
169 +
170 + # Only check on 32-bit systems. Filtering by $ARCH here isn't perfect, but
171 + # it should be good enough for our needs.
172 + case ${ARCH} in
173 + arm|mips|ppc|sh|x86) ;;
174 + *) return ;;
175 + esac
176 +
177 + # Obviously filter out C libraries themselves :).
178 + # The sandbox has to capture all symbols by design.
179 + case ${CATEGORY}/${PN} in
180 + */glibc|\
181 + */uclibc|\
182 + */gcc|\
183 + sys-apps/sandbox) ;;
184 + *) check_lfs "${ED}" ;;
185 + esac
186 +}
187 +
188 +# Allow for people to run manually for testing/debugging.
189 +if [[ $# -ne 0 ]]; then
190 + eqawarn() { echo " * $*"; }
191 + check_lfs "$@"
192 +else
193 + filtered_check_lfs
194 +fi
195 --
196 2.4.1

Replies