diff options
author | Colin Cross <ccross@android.com> | 2018-09-10 16:50:05 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2018-09-10 23:12:11 -0700 |
commit | b496cfd9d238423afb165d6e4006f247c96bb7bc (patch) | |
tree | 907594f105635c015cc94e4219943719a9d72496 /scripts | |
parent | 7b59e7b2d038a50573155c2d51dd086f744eb26a (diff) | |
download | build_soong-b496cfd9d238423afb165d6e4006f247c96bb7bc.tar.gz build_soong-b496cfd9d238423afb165d6e4006f247c96bb7bc.tar.bz2 build_soong-b496cfd9d238423afb165d6e4006f247c96bb7bc.zip |
Enable toc support for Darwin and Windows
Bug: 113936524
Test: m checkbuild
Change-Id: I0f2030ad75daae2cbe44e8cbedad329d33df55f7
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/toc.sh | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/scripts/toc.sh b/scripts/toc.sh index bd6425be..8b1d25fb 100755 --- a/scripts/toc.sh +++ b/scripts/toc.sh @@ -22,6 +22,7 @@ # -i ${file}: input file (required) # -o ${file}: output file (required) # -d ${file}: deps file (required) +# --elf | --macho | --pe: format (required) OPTSTRING=d:i:o:-: @@ -36,13 +37,34 @@ EOF do_elf() { ("${CROSS_COMPILE}readelf" -d "${infile}" | grep SONAME || echo "No SONAME for ${infile}") > "${outfile}.tmp" "${CROSS_COMPILE}readelf" --dyn-syms "${infile}" | awk '{$2=""; $3=""; print}' >> "${outfile}.tmp" + + cat <<EOF > "${depsfile}" +${outfile}: \\ + ${CROSS_COMPILE}readelf \\ +EOF } do_macho() { "${CROSS_COMPILE}/otool" -l "${infile}" | grep LC_ID_DYLIB -A 5 > "${outfile}.tmp" - "${CROSS_COMPILE}/nm" -gP "${infile}" | cut -f1-2 -d" " | grep -v 'U$' >> "${outfile}.tmp" + "${CROSS_COMPILE}/nm" -gP "${infile}" | cut -f1-2 -d" " | (grep -v 'U$' >> "${outfile}.tmp" || true) + + cat <<EOF > "${depsfile}" +${outfile}: \\ + ${CROSS_COMPILE}/otool \\ + ${CROSS_COMPILE}/nm \\ +EOF } +do_pe() { + "${CROSS_COMPILE}objdump" -x "${infile}" | grep "^Name" | cut -f3 -d" " > "${outfile}.tmp" + "${CROSS_COMPILE}nm" -g -f p "${infile}" | cut -f1-2 -d" " >> "${outfile}.tmp" + + cat <<EOF > "${depsfile}" +${outfile}: \\ + ${CROSS_COMPILE}objdump \\ + ${CROSS_COMPILE}nm \\ +EOF +} while getopts $OPTSTRING opt; do case "$opt" in @@ -51,6 +73,9 @@ while getopts $OPTSTRING opt; do o) outfile="${OPTARG}" ;; -) case "${OPTARG}" in + elf) elf=1 ;; + macho) macho=1 ;; + pe) pe=1 ;; *) echo "Unknown option --${OPTARG}"; usage ;; esac;; ?) usage ;; @@ -58,21 +83,26 @@ while getopts $OPTSTRING opt; do esac done -if [ -z "${infile}" ]; then +if [ -z "${infile:-}" ]; then echo "-i argument is required" usage fi -if [ -z "${outfile}" ]; then +if [ -z "${outfile:-}" ]; then echo "-o argument is required" usage fi -if [ -z "${depsfile}" ]; then +if [ -z "${depsfile:-}" ]; then echo "-d argument is required" usage fi +if [ -z "${CROSS_COMPILE:-}" ]; then + echo "CROSS_COMPILE environment variable must be set" + usage +fi + rm -f "${outfile}.tmp" cat <<EOF > "${depsfile}" @@ -80,7 +110,15 @@ ${outfile}: \\ ${CROSS_COMPILE}readelf \\ EOF -do_elf +if [ -n "${elf:-}" ]; then + do_elf +elif [ -n "${macho:-}" ]; then + do_macho +elif [ -n "${pe:-}" ]; then + do_pe +else + echo "--elf, --macho or --pe is required"; usage +fi if cmp "${outfile}" "${outfile}.tmp" > /dev/null 2> /dev/null; then rm -f "${outfile}.tmp" |