Merge "Enable toc support for Darwin and Windows"
This commit is contained in:
@@ -144,11 +144,11 @@ var (
|
|||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Depfile: "${out}.d",
|
Depfile: "${out}.d",
|
||||||
Deps: blueprint.DepsGCC,
|
Deps: blueprint.DepsGCC,
|
||||||
Command: "CROSS_COMPILE=$crossCompile $tocPath -i ${in} -o ${out} -d ${out}.d",
|
Command: "CROSS_COMPILE=$crossCompile $tocPath $format -i ${in} -o ${out} -d ${out}.d",
|
||||||
CommandDeps: []string{"$tocPath"},
|
CommandDeps: []string{"$tocPath"},
|
||||||
Restat: true,
|
Restat: true,
|
||||||
},
|
},
|
||||||
"crossCompile")
|
"crossCompile", "format")
|
||||||
|
|
||||||
clangTidy = pctx.AndroidStaticRule("clangTidy",
|
clangTidy = pctx.AndroidStaticRule("clangTidy",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
@@ -759,7 +759,18 @@ func SourceAbiDiff(ctx android.ModuleContext, inputDump android.Path, referenceD
|
|||||||
func TransformSharedObjectToToc(ctx android.ModuleContext, inputFile android.Path,
|
func TransformSharedObjectToToc(ctx android.ModuleContext, inputFile android.Path,
|
||||||
outputFile android.WritablePath, flags builderFlags) {
|
outputFile android.WritablePath, flags builderFlags) {
|
||||||
|
|
||||||
crossCompile := gccCmd(flags.toolchain, "")
|
var format string
|
||||||
|
var crossCompile string
|
||||||
|
if ctx.Darwin() {
|
||||||
|
format = "--macho"
|
||||||
|
crossCompile = "${config.MacToolPath}"
|
||||||
|
} else if ctx.Windows() {
|
||||||
|
format = "--pe"
|
||||||
|
crossCompile = gccCmd(flags.toolchain, "")
|
||||||
|
} else {
|
||||||
|
format = "--elf"
|
||||||
|
crossCompile = gccCmd(flags.toolchain, "")
|
||||||
|
}
|
||||||
|
|
||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
Rule: toc,
|
Rule: toc,
|
||||||
@@ -768,6 +779,7 @@ func TransformSharedObjectToToc(ctx android.ModuleContext, inputFile android.Pat
|
|||||||
Input: inputFile,
|
Input: inputFile,
|
||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
"crossCompile": crossCompile,
|
"crossCompile": crossCompile,
|
||||||
|
"format": format,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -544,15 +544,13 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
|
|||||||
|
|
||||||
builderFlags := flagsToBuilderFlags(flags)
|
builderFlags := flagsToBuilderFlags(flags)
|
||||||
|
|
||||||
if !ctx.Darwin() && !ctx.Windows() {
|
// Optimize out relinking against shared libraries whose interface hasn't changed by
|
||||||
// Optimize out relinking against shared libraries whose interface hasn't changed by
|
// depending on a table of contents file instead of the library itself.
|
||||||
// depending on a table of contents file instead of the library itself.
|
tocPath := outputFile.RelPathString()
|
||||||
tocPath := outputFile.RelPathString()
|
tocPath = pathtools.ReplaceExtension(tocPath, flags.Toolchain.ShlibSuffix()[1:]+".toc")
|
||||||
tocPath = pathtools.ReplaceExtension(tocPath, flags.Toolchain.ShlibSuffix()[1:]+".toc")
|
tocFile := android.PathForOutput(ctx, tocPath)
|
||||||
tocFile := android.PathForOutput(ctx, tocPath)
|
library.tocFile = android.OptionalPathForPath(tocFile)
|
||||||
library.tocFile = android.OptionalPathForPath(tocFile)
|
TransformSharedObjectToToc(ctx, outputFile, tocFile, builderFlags)
|
||||||
TransformSharedObjectToToc(ctx, outputFile, tocFile, builderFlags)
|
|
||||||
}
|
|
||||||
|
|
||||||
if library.stripper.needsStrip(ctx) {
|
if library.stripper.needsStrip(ctx) {
|
||||||
// b/80093681, GNU strip/objcopy bug.
|
// b/80093681, GNU strip/objcopy bug.
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
# -i ${file}: input file (required)
|
# -i ${file}: input file (required)
|
||||||
# -o ${file}: output file (required)
|
# -o ${file}: output file (required)
|
||||||
# -d ${file}: deps file (required)
|
# -d ${file}: deps file (required)
|
||||||
|
# --elf | --macho | --pe: format (required)
|
||||||
|
|
||||||
OPTSTRING=d:i:o:-:
|
OPTSTRING=d:i:o:-:
|
||||||
|
|
||||||
@@ -36,13 +37,34 @@ EOF
|
|||||||
do_elf() {
|
do_elf() {
|
||||||
("${CROSS_COMPILE}readelf" -d "${infile}" | grep SONAME || echo "No SONAME for ${infile}") > "${outfile}.tmp"
|
("${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"
|
"${CROSS_COMPILE}readelf" --dyn-syms "${infile}" | awk '{$2=""; $3=""; print}' >> "${outfile}.tmp"
|
||||||
|
|
||||||
|
cat <<EOF > "${depsfile}"
|
||||||
|
${outfile}: \\
|
||||||
|
${CROSS_COMPILE}readelf \\
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
do_macho() {
|
do_macho() {
|
||||||
"${CROSS_COMPILE}/otool" -l "${infile}" | grep LC_ID_DYLIB -A 5 > "${outfile}.tmp"
|
"${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
|
while getopts $OPTSTRING opt; do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
@@ -51,6 +73,9 @@ while getopts $OPTSTRING opt; do
|
|||||||
o) outfile="${OPTARG}" ;;
|
o) outfile="${OPTARG}" ;;
|
||||||
-)
|
-)
|
||||||
case "${OPTARG}" in
|
case "${OPTARG}" in
|
||||||
|
elf) elf=1 ;;
|
||||||
|
macho) macho=1 ;;
|
||||||
|
pe) pe=1 ;;
|
||||||
*) echo "Unknown option --${OPTARG}"; usage ;;
|
*) echo "Unknown option --${OPTARG}"; usage ;;
|
||||||
esac;;
|
esac;;
|
||||||
?) usage ;;
|
?) usage ;;
|
||||||
@@ -58,21 +83,26 @@ while getopts $OPTSTRING opt; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -z "${infile}" ]; then
|
if [ -z "${infile:-}" ]; then
|
||||||
echo "-i argument is required"
|
echo "-i argument is required"
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${outfile}" ]; then
|
if [ -z "${outfile:-}" ]; then
|
||||||
echo "-o argument is required"
|
echo "-o argument is required"
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "${depsfile}" ]; then
|
if [ -z "${depsfile:-}" ]; then
|
||||||
echo "-d argument is required"
|
echo "-d argument is required"
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z "${CROSS_COMPILE:-}" ]; then
|
||||||
|
echo "CROSS_COMPILE environment variable must be set"
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
|
||||||
rm -f "${outfile}.tmp"
|
rm -f "${outfile}.tmp"
|
||||||
|
|
||||||
cat <<EOF > "${depsfile}"
|
cat <<EOF > "${depsfile}"
|
||||||
@@ -80,7 +110,15 @@ ${outfile}: \\
|
|||||||
${CROSS_COMPILE}readelf \\
|
${CROSS_COMPILE}readelf \\
|
||||||
EOF
|
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
|
if cmp "${outfile}" "${outfile}.tmp" > /dev/null 2> /dev/null; then
|
||||||
rm -f "${outfile}.tmp"
|
rm -f "${outfile}.tmp"
|
||||||
|
Reference in New Issue
Block a user