2
1

check-bin-arch 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. while getopts p:l:r:a: OPT ; do
  3. case "${OPT}" in
  4. p) package="${OPTARG}";;
  5. l) pkg_list="${OPTARG}";;
  6. r) readelf="${OPTARG}";;
  7. a) arch_name="${OPTARG}";;
  8. :) error "option '%s' expects a mandatory argument\n" "${OPTARG}";;
  9. \?) error "unknown option '%s'\n" "${OPTARG}";;
  10. esac
  11. done
  12. if test -z "${package}" -o -z "${pkg_list}" -o -z "${readelf}" -o -z "${arch_name}" ; then
  13. echo "Usage: $0 -p <pkg> -l <pkg-file-list> -r <readelf> -a <arch name>"
  14. exit 1
  15. fi
  16. exitcode=0
  17. # Only split on new lines, for filenames-with-spaces
  18. IFS="
  19. "
  20. while read f; do
  21. # Skip firmware files, they could be ELF files for other
  22. # architectures
  23. if [[ "${f}" =~ ^/(usr/)?lib/firmware/.* ]]; then
  24. continue
  25. fi
  26. # Skip files in /usr/share, several packages (qemu,
  27. # pru-software-support) legitimately install ELF binaries that
  28. # are not for the target architecture
  29. if [[ "${f}" =~ ^/usr/share/.* ]]; then
  30. continue
  31. fi
  32. # Get architecture using readelf. We pipe through 'head -1' so
  33. # that when the file is a static library (.a), we only take
  34. # into account the architecture of the first object file.
  35. arch=$(LC_ALL=C ${readelf} -h "${TARGET_DIR}/${f}" 2>&1 | \
  36. sed -r -e '/^ Machine: +(.+)/!d; s//\1/;' | head -1)
  37. # If no architecture found, assume it was not an ELF file
  38. if test "${arch}" = "" ; then
  39. continue
  40. fi
  41. # Architecture is correct
  42. if test "${arch}" = "${arch_name}" ; then
  43. continue
  44. fi
  45. printf 'ERROR: architecture for "%s" is "%s", should be "%s"\n' \
  46. "${f}" "${arch}" "${arch_name}"
  47. exitcode=1
  48. done < <( sed -r -e "/^${package},\.(.+)$/!d; s//\1/;" ${pkg_list} )
  49. exit ${exitcode}