1#!/usr/local/bin/bash
2# Copyright (C) 2015 Red Hat, Inc.
3# This file is part of elfutils.
4#
5# This file is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3 of the License, or
8# (at your option) any later version.
9#
10# elfutils is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18. $srcdir/test-subr.sh
19
20if ! grep -q -F '#define _FILE_OFFSET_BITS' ${abs_top_builddir}/config.h; then
21  echo "LFS testing is irrelevent on this system"
22  exit 77
23fi
24
25# #include <stdio.h>
26# int main () {
27#     FILE *f = fopen ("/dev/null", "r");
28#     return f == NULL;
29# }
30#
31# Built for Linux i686, without setting _FILE_OFFSET_BITS.
32# $ gcc -m32 -O2 nolfs.c -o testfile-nolfs
33testfiles testfile-nolfs
34
35LFS_FORMAT='BEGIN {
36  while ((getline < "%s") > 0)
37    /^\w/ && bad[$0]
38  FS="@"
39}
40/@@GLIBC_/ && $1 in bad { print $1 }'
41
42LFS=$(printf "$LFS_FORMAT" "${abs_srcdir}/lfs-symbols")
43
44makeprint() {
45  make print-$1 -C $2 |& awk -F= "/^$1=/{ print \$2 }"
46}
47
48testrun_lfs() {
49  echo "checking $1"
50  if [ -e "$1" ]; then
51    bad=$(testrun ${abs_top_builddir}/src/nm -u "$1" | awk "$LFS")
52    if [ -n "$bad" ]; then
53      echo "$1 contains non-lfs symbols:" $bad
54      exit_status=1
55    fi
56  else
57    echo "$1 doesn't exist"
58    exit_status=1
59  fi
60}
61
62echo First sanity-check that LFS detection works.
63exit_status=0
64testrun_lfs ./testfile-nolfs
65if [ $exit_status -eq 0 ]; then
66  echo "Didn't detect any problem with testfile-nolfs!"
67  exit 99
68fi
69echo
70
71exit_status=0
72
73echo Check all normal build targets.
74for dir in libelf libdw libasm libcpu src; do
75  dir=${abs_top_builddir}/$dir
76  for program in $(makeprint PROGRAMS $dir); do
77    testrun_lfs $dir/$program
78  done
79done
80echo
81
82echo Check all test programs.
83dir=${abs_builddir}
84for program in $(makeprint check_PROGRAMS $dir); do
85  testrun_lfs $dir/$program
86done
87echo
88
89exit $exit_status
90