Move toc.sh to use LLVM binutils

Test: build
Change-Id: Ib965b6ea3fba6ae007135ac7e167cc50f0f6e3de
This commit is contained in:
Yi Kong 2021-04-01 17:45:42 +08:00
parent f8c9713fb8
commit 4ad44e713b
2 changed files with 19 additions and 23 deletions

View File

@ -182,11 +182,11 @@ var (
blueprint.RuleParams{ blueprint.RuleParams{
Depfile: "${out}.d", Depfile: "${out}.d",
Deps: blueprint.DepsGCC, Deps: blueprint.DepsGCC,
Command: "CROSS_COMPILE=$crossCompile $tocPath $format -i ${in} -o ${out} -d ${out}.d", Command: "CLANG_BIN=$clangBin $tocPath $format -i ${in} -o ${out} -d ${out}.d",
CommandDeps: []string{"$tocPath"}, CommandDeps: []string{"$tocPath"},
Restat: true, Restat: true,
}, },
"crossCompile", "format") "clangBin", "format")
// Rule for invoking clang-tidy (a clang-based linter). // Rule for invoking clang-tidy (a clang-based linter).
clangTidy, clangTidyRE = pctx.RemoteStaticRules("clangTidy", clangTidy, clangTidyRE = pctx.RemoteStaticRules("clangTidy",
@ -918,16 +918,12 @@ func transformSharedObjectToToc(ctx android.ModuleContext, inputFile android.Pat
outputFile android.WritablePath, flags builderFlags) { outputFile android.WritablePath, flags builderFlags) {
var format string var format string
var crossCompile string
if ctx.Darwin() { if ctx.Darwin() {
format = "--macho" format = "--macho"
crossCompile = "${config.MacToolPath}"
} else if ctx.Windows() { } else if ctx.Windows() {
format = "--pe" format = "--pe"
crossCompile = gccCmd(flags.toolchain, "")
} else { } else {
format = "--elf" format = "--elf"
crossCompile = gccCmd(flags.toolchain, "")
} }
ctx.Build(pctx, android.BuildParams{ ctx.Build(pctx, android.BuildParams{
@ -936,8 +932,8 @@ func transformSharedObjectToToc(ctx android.ModuleContext, inputFile android.Pat
Output: outputFile, Output: outputFile,
Input: inputFile, Input: inputFile,
Args: map[string]string{ Args: map[string]string{
"crossCompile": crossCompile, "clangBin": "${config.ClangBin}",
"format": format, "format": format,
}, },
}) })
} }

View File

@ -17,7 +17,7 @@
# Script to handle generating a .toc file from a .so file # Script to handle generating a .toc file from a .so file
# Inputs: # Inputs:
# Environment: # Environment:
# CROSS_COMPILE: prefix added to readelf tool # CLANG_BIN: path to the clang bin directory
# Arguments: # Arguments:
# -i ${file}: input file (required) # -i ${file}: input file (required)
# -o ${file}: output file (required) # -o ${file}: output file (required)
@ -35,34 +35,34 @@ EOF
} }
do_elf() { do_elf() {
("${CROSS_COMPILE}readelf" -d "${infile}" | grep SONAME || echo "No SONAME for ${infile}") > "${outfile}.tmp" ("${CLANG_BIN}/llvm-readelf" -d "${infile}" | grep SONAME || echo "No SONAME for ${infile}") > "${outfile}.tmp"
"${CROSS_COMPILE}readelf" --dyn-syms "${infile}" | awk '{$2=""; $3=""; print}' >> "${outfile}.tmp" "${CLANG_BIN}/llvm-readelf" --dyn-syms "${infile}" | awk '{$2=""; $3=""; print}' >> "${outfile}.tmp"
cat <<EOF > "${depsfile}" cat <<EOF > "${depsfile}"
${outfile}: \\ ${outfile}: \\
${CROSS_COMPILE}readelf \\ ${CLANG_BIN}/llvm-readelf \\
EOF EOF
} }
do_macho() { do_macho() {
"${CROSS_COMPILE}/otool" -l "${infile}" | grep LC_ID_DYLIB -A 5 > "${outfile}.tmp" "${CLANG_BIN}/llvm-objdump" -p "${infile}" | grep LC_ID_DYLIB -A 5 > "${outfile}.tmp"
"${CROSS_COMPILE}/nm" -gP "${infile}" | cut -f1-2 -d" " | (grep -v 'U$' >> "${outfile}.tmp" || true) "${CLANG_BIN}/llvm-nm" -gP "${infile}" | cut -f1-2 -d" " | (grep -v 'U$' >> "${outfile}.tmp" || true)
cat <<EOF > "${depsfile}" cat <<EOF > "${depsfile}"
${outfile}: \\ ${outfile}: \\
${CROSS_COMPILE}/otool \\ ${CLANG_BIN}/llvm-objdump \\
${CROSS_COMPILE}/nm \\ ${CLANG_BIN}/llvm-nm \\
EOF EOF
} }
do_pe() { do_pe() {
"${CROSS_COMPILE}objdump" -x "${infile}" | grep "^Name" | cut -f3 -d" " > "${outfile}.tmp" "${CLANG_BIN}/llvm-objdump" -x "${infile}" | grep "^Name" | cut -f3 -d" " > "${outfile}.tmp"
"${CROSS_COMPILE}nm" -g -f p "${infile}" | cut -f1-2 -d" " >> "${outfile}.tmp" "${CLANG_BIN}/llvm-nm" -g -f p "${infile}" | cut -f1-2 -d" " >> "${outfile}.tmp"
cat <<EOF > "${depsfile}" cat <<EOF > "${depsfile}"
${outfile}: \\ ${outfile}: \\
${CROSS_COMPILE}objdump \\ ${CLANG_BIN}/llvm-objdump \\
${CROSS_COMPILE}nm \\ ${CLANG_BIN}/llvm-nm \\
EOF EOF
} }
@ -98,8 +98,8 @@ if [ -z "${depsfile:-}" ]; then
usage usage
fi fi
if [ -z "${CROSS_COMPILE:-}" ]; then if [ -z "${CLANG_BIN:-}" ]; then
echo "CROSS_COMPILE environment variable must be set" echo "CLANG_BIN environment variable must be set"
usage usage
fi fi
@ -107,7 +107,7 @@ rm -f "${outfile}.tmp"
cat <<EOF > "${depsfile}" cat <<EOF > "${depsfile}"
${outfile}: \\ ${outfile}: \\
${CROSS_COMPILE}readelf \\ ${CLANG_BIN}/llvm-readelf \\
EOF EOF
if [ -n "${elf:-}" ]; then if [ -n "${elf:-}" ]; then