Merge "Support new Doclava flag"
diff --git a/android/config.go b/android/config.go
index bc3d4f5..f5a5e8e 100644
--- a/android/config.go
+++ b/android/config.go
@@ -627,10 +627,6 @@
return false
}
-func (c *config) UseD8Desugar() bool {
- return !c.IsEnvFalse("USE_D8_DESUGAR")
-}
-
func (c *config) UseGoma() bool {
return Bool(c.productVariables.UseGoma)
}
diff --git a/cc/binary.go b/cc/binary.go
index 00fda06..04b912a 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -318,6 +318,10 @@
builderFlags := flagsToBuilderFlags(flags)
if binary.stripper.needsStrip(ctx) {
+ // b/80093681, GNU strip/objcopy bug.
+ // Use llvm-{strip,objcopy} when clang lld is used.
+ builderFlags.stripUseLlvmStrip =
+ flags.Clang && binary.baseLinker.useClangLld(ctx)
strippedOutputFile := outputFile
outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
binary.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags)
diff --git a/cc/builder.go b/cc/builder.go
index dd1fc05..bc3652e 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -117,7 +117,7 @@
blueprint.RuleParams{
Depfile: "${out}.d",
Deps: blueprint.DepsGCC,
- Command: "CROSS_COMPILE=$crossCompile XZ=$xzCmd $stripPath ${args} -i ${in} -o ${out} -d ${out}.d",
+ Command: "CROSS_COMPILE=$crossCompile XZ=$xzCmd CLANG_BIN=${config.ClangBin} $stripPath ${args} -i ${in} -o ${out} -d ${out}.d",
CommandDeps: []string{"$stripPath", "$xzCmd"},
},
"args", "crossCompile")
@@ -266,6 +266,7 @@
stripKeepSymbols bool
stripKeepMiniDebugInfo bool
stripAddGnuDebuglink bool
+ stripUseLlvmStrip bool
}
type Objects struct {
@@ -822,6 +823,9 @@
if flags.stripKeepSymbols {
args += " --keep-symbols"
}
+ if flags.stripUseLlvmStrip {
+ args += " --use-llvm-strip"
+ }
ctx.Build(pctx, android.BuildParams{
Rule: strip,
diff --git a/cc/library.go b/cc/library.go
index c83e89a..3bc1001 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -593,6 +593,10 @@
}
if library.stripper.needsStrip(ctx) {
+ // b/80093681, GNU strip/objcopy bug.
+ // Use llvm-{strip,objcopy} when clang lld is used.
+ builderFlags.stripUseLlvmStrip =
+ flags.Clang && library.baseLinker.useClangLld(ctx)
strippedOutputFile := outputFile
outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
library.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags)
diff --git a/cc/makevars.go b/cc/makevars.go
index d036bb6..8b72dbb 100644
--- a/cc/makevars.go
+++ b/cc/makevars.go
@@ -72,6 +72,8 @@
ctx.Strict("CLANG_CXX", "${config.ClangBin}/clang++")
ctx.Strict("LLVM_AS", "${config.ClangBin}/llvm-as")
ctx.Strict("LLVM_LINK", "${config.ClangBin}/llvm-link")
+ ctx.Strict("LLVM_OBJCOPY", "${config.ClangBin}/llvm-objcopy")
+ ctx.Strict("LLVM_STRIP", "${config.ClangBin}/llvm-strip")
ctx.Strict("PATH_TO_CLANG_TIDY", "${config.ClangBin}/clang-tidy")
ctx.StrictSorted("CLANG_CONFIG_UNKNOWN_CFLAGS", strings.Join(config.ClangUnknownCflags, " "))
diff --git a/java/builder.go b/java/builder.go
index d36e0dc..d338623 100644
--- a/java/builder.go
+++ b/java/builder.go
@@ -243,7 +243,7 @@
// ensure java does not fall back to the default bootclasspath.
bootClasspath = `--bootclasspath ""`
} else {
- bootClasspath = strings.Join(flags.bootClasspath.FormDesugarClasspath("--bootclasspath"), " ")
+ bootClasspath = strings.Join(flags.bootClasspath.FormTurbineClasspath("--bootclasspath"), " ")
}
ctx.Build(pctx, android.BuildParams{
@@ -256,7 +256,7 @@
"javacFlags": flags.javacFlags,
"bootClasspath": bootClasspath,
"srcJars": strings.Join(srcJars.Strings(), " "),
- "classpath": strings.Join(flags.classpath.FormDesugarClasspath("--classpath"), " "),
+ "classpath": strings.Join(flags.classpath.FormTurbineClasspath("--classpath"), " "),
"outDir": android.PathForModuleOut(ctx, "turbine", "classes").String(),
"javaVersion": flags.javaVersion,
},
@@ -419,7 +419,7 @@
}
}
-func (x *classpath) FormDesugarClasspath(optName string) []string {
+func (x *classpath) FormTurbineClasspath(optName string) []string {
if x == nil || *x == nil {
return nil
}
diff --git a/java/config/config.go b/java/config/config.go
index fe57c50..c6555f1 100644
--- a/java/config/config.go
+++ b/java/config/config.go
@@ -93,18 +93,6 @@
pctx.HostBinToolVariable("Zip2ZipCmd", "zip2zip")
pctx.HostBinToolVariable("ZipSyncCmd", "zipsync")
pctx.HostBinToolVariable("ApiCheckCmd", "apicheck")
- pctx.VariableFunc("DxCmd", func(ctx android.PackageVarContext) string {
- config := ctx.Config()
- if config.IsEnvFalse("USE_D8") {
- if config.UnbundledBuild() || config.IsPdkBuild() {
- return "prebuilts/build-tools/common/bin/dx"
- } else {
- return pctx.HostBinToolPath(ctx, "dx").String()
- }
- } else {
- return pctx.HostBinToolPath(ctx, "d8-compat-dx").String()
- }
- })
pctx.HostBinToolVariable("D8Cmd", "d8")
pctx.HostBinToolVariable("R8Cmd", "r8-compat-proguard")
@@ -118,7 +106,6 @@
})
pctx.HostJavaToolVariable("JarjarCmd", "jarjar.jar")
- pctx.HostJavaToolVariable("DesugarJar", "desugar.jar")
pctx.HostJavaToolVariable("JsilverJar", "jsilver.jar")
pctx.HostJavaToolVariable("DoclavaJar", "doclava.jar")
pctx.HostJavaToolVariable("MetalavaJar", "metalava.jar")
diff --git a/java/config/error_prone.go b/java/config/error_prone.go
index f203234..2c1c002 100644
--- a/java/config/error_prone.go
+++ b/java/config/error_prone.go
@@ -18,11 +18,13 @@
var (
// These will be filled out by external/error_prone/soong/error_prone.go if it is available
- ErrorProneJavacJar string
- ErrorProneJar string
- ErrorProneClasspath string
- ErrorProneChecksError string
- ErrorProneFlags string
+ ErrorProneJavacJar string
+ ErrorProneJar string
+ ErrorProneClasspath string
+ ErrorProneChecksError string
+ ErrorProneChecksWarning string
+ ErrorProneChecksDefaultDisabled string
+ ErrorProneFlags string
)
// Wrapper that grabs value of val late so it can be initialized by a later module's init function
@@ -37,11 +39,14 @@
errorProneVar("ErrorProneJavacJar", &ErrorProneJavacJar)
errorProneVar("ErrorProneClasspath", &ErrorProneClasspath)
errorProneVar("ErrorProneChecksError", &ErrorProneChecksError)
+ errorProneVar("ErrorProneChecksWarning", &ErrorProneChecksWarning)
+ errorProneVar("ErrorProneChecksDefaultDisabled", &ErrorProneChecksDefaultDisabled)
errorProneVar("ErrorProneFlags", &ErrorProneFlags)
pctx.StaticVariable("ErrorProneCmd",
"${JavaCmd} -Xmx${JavacHeapSize} -Xbootclasspath/p:${ErrorProneJavacJar} "+
"-cp ${ErrorProneJar}:${ErrorProneClasspath} "+
- "${ErrorProneFlags} ${CommonJdkFlags} ${ErrorProneChecksError}")
+ "${ErrorProneFlags} ${CommonJdkFlags} "+
+ "${ErrorProneChecksError} ${ErrorProneChecksWarning} ${ErrorProneChecksDefaultDisabled}")
}
diff --git a/java/config/makevars.go b/java/config/makevars.go
index 27c7daa..4dffa02 100644
--- a/java/config/makevars.go
+++ b/java/config/makevars.go
@@ -46,15 +46,8 @@
ctx.Strict("JAVADOC", "${JavadocCmd}")
ctx.Strict("COMMON_JDK_FLAGS", "${CommonJdkFlags}")
- if ctx.Config().UseD8Desugar() {
- ctx.Strict("DX", "${D8Cmd}")
- ctx.Strict("DX_COMMAND", "${D8Cmd} -JXms16M -JXmx2048M")
- ctx.Strict("USE_D8_DESUGAR", "true")
- } else {
- ctx.Strict("DX", "${DxCmd}")
- ctx.Strict("DX_COMMAND", "${DxCmd} -JXms16M -JXmx2048M")
- ctx.Strict("USE_D8_DESUGAR", "false")
- }
+ ctx.Strict("DX", "${D8Cmd}")
+ ctx.Strict("DX_COMMAND", "${D8Cmd} -JXms16M -JXmx2048M")
ctx.Strict("R8_COMPAT_PROGUARD", "${R8Cmd}")
ctx.Strict("TURBINE", "${TurbineJar}")
diff --git a/java/dex.go b/java/dex.go
index 642dee4..f729bad 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -22,78 +22,6 @@
"android/soong/android"
)
-var desugar = pctx.AndroidStaticRule("desugar",
- blueprint.RuleParams{
- Command: `rm -rf $dumpDir && mkdir -p $dumpDir && ` +
- `${config.JavaCmd} ` +
- `-Djdk.internal.lambda.dumpProxyClasses=$$(cd $dumpDir && pwd) ` +
- `$javaFlags ` +
- `-jar ${config.DesugarJar} $classpathFlags $desugarFlags ` +
- `-i $in -o $out`,
- CommandDeps: []string{"${config.DesugarJar}", "${config.JavaCmd}"},
- },
- "javaFlags", "classpathFlags", "desugarFlags", "dumpDir")
-
-func (j *Module) desugar(ctx android.ModuleContext, flags javaBuilderFlags,
- classesJar android.Path, jarName string) android.Path {
-
- desugarFlags := []string{
- "--min_sdk_version " + j.minSdkVersionNumber(ctx),
- "--desugar_try_with_resources_if_needed=false",
- "--allow_empty_bootclasspath",
- }
-
- if inList("--core-library", j.deviceProperties.Dxflags) {
- desugarFlags = append(desugarFlags, "--core_library")
- }
-
- desugarJar := android.PathForModuleOut(ctx, "desugar", jarName)
- dumpDir := android.PathForModuleOut(ctx, "desugar", "classes")
-
- javaFlags := ""
- if ctx.Config().UseOpenJDK9() {
- javaFlags = "--add-opens java.base/java.lang.invoke=ALL-UNNAMED"
- }
-
- var classpathFlags []string
- classpathFlags = append(classpathFlags, flags.bootClasspath.FormDesugarClasspath("--bootclasspath_entry")...)
- classpathFlags = append(classpathFlags, flags.classpath.FormDesugarClasspath("--classpath_entry")...)
-
- var deps android.Paths
- deps = append(deps, flags.bootClasspath...)
- deps = append(deps, flags.classpath...)
-
- ctx.Build(pctx, android.BuildParams{
- Rule: desugar,
- Description: "desugar",
- Output: desugarJar,
- Input: classesJar,
- Implicits: deps,
- Args: map[string]string{
- "dumpDir": dumpDir.String(),
- "javaFlags": javaFlags,
- "classpathFlags": strings.Join(classpathFlags, " "),
- "desugarFlags": strings.Join(desugarFlags, " "),
- },
- })
-
- return desugarJar
-}
-
-var dx = pctx.AndroidStaticRule("dx",
- blueprint.RuleParams{
- Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
- `${config.DxCmd} --dex --output=$outDir $dxFlags $in && ` +
- `${config.SoongZipCmd} -o $outDir/classes.dex.jar -C $outDir -D $outDir && ` +
- `${config.MergeZipsCmd} -D -stripFile "*.class" $out $outDir/classes.dex.jar $in`,
- CommandDeps: []string{
- "${config.DxCmd}",
- "${config.SoongZipCmd}",
- "${config.MergeZipsCmd}",
- },
- },
- "outDir", "dxFlags")
-
var d8 = pctx.AndroidStaticRule("d8",
blueprint.RuleParams{
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
@@ -125,39 +53,24 @@
},
"outDir", "outDict", "dxFlags", "r8Flags")
-func (j *Module) dxFlags(ctx android.ModuleContext, fullD8 bool) []string {
+func (j *Module) dxFlags(ctx android.ModuleContext) []string {
flags := j.deviceProperties.Dxflags
- if fullD8 {
- // Translate all the DX flags to D8 ones until all the build files have been migrated
- // to D8 flags. See: b/69377755
- flags = android.RemoveListFromList(flags,
- []string{"--core-library", "--dex", "--multi-dex"})
- }
+ // Translate all the DX flags to D8 ones until all the build files have been migrated
+ // to D8 flags. See: b/69377755
+ flags = android.RemoveListFromList(flags,
+ []string{"--core-library", "--dex", "--multi-dex"})
if ctx.Config().Getenv("NO_OPTIMIZE_DX") != "" {
- if fullD8 {
- flags = append(flags, "--debug")
- } else {
- flags = append(flags, "--no-optimize")
- }
+ flags = append(flags, "--debug")
}
if ctx.Config().Getenv("GENERATE_DEX_DEBUG") != "" {
flags = append(flags,
"--debug",
"--verbose")
- if !fullD8 {
- flags = append(flags,
- "--dump-to="+android.PathForModuleOut(ctx, "classes.lst").String(),
- "--dump-width=1000")
- }
}
- if fullD8 {
- flags = append(flags, "--min-api "+j.minSdkVersionNumber(ctx))
- } else {
- flags = append(flags, "--min-sdk-version="+j.minSdkVersionNumber(ctx))
- }
+ flags = append(flags, "--min-api "+j.minSdkVersionNumber(ctx))
return flags
}
@@ -166,7 +79,7 @@
// When an app contains references to APIs that are not in the SDK specified by
// its LOCAL_SDK_VERSION for example added by support library or by runtime
- // classes added by desugar, we artifically raise the "SDK version" "linked" by
+ // classes added by desugaring, we artifically raise the "SDK version" "linked" by
// ProGuard, to
// - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version.
// - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version.
@@ -223,13 +136,8 @@
classesJar android.Path, jarName string) android.Path {
useR8 := Bool(j.deviceProperties.Optimize.Enabled)
- fullD8 := useR8 || ctx.Config().UseD8Desugar()
- if !fullD8 {
- classesJar = j.desugar(ctx, flags, classesJar, jarName)
- }
-
- dxFlags := j.dxFlags(ctx, fullD8)
+ dxFlags := j.dxFlags(ctx)
// Compile classes.jar into classes.dex and then javalib.jar
javalibJar := android.PathForModuleOut(ctx, "dex", jarName)
@@ -256,15 +164,9 @@
},
})
} else {
- rule := dx
- desc := "dx"
- if fullD8 {
- rule = d8
- desc = "d8"
- }
ctx.Build(pctx, android.BuildParams{
- Rule: rule,
- Description: desc,
+ Rule: d8,
+ Description: "d8",
Output: javalibJar,
Input: classesJar,
Args: map[string]string{
diff --git a/scripts/strip.sh b/scripts/strip.sh
index 318c7ad..432582f 100755
--- a/scripts/strip.sh
+++ b/scripts/strip.sh
@@ -17,15 +17,17 @@
# Script to handle the various ways soong may need to strip binaries
# Inputs:
# Environment:
+# CLANG_BIN: path to the clang bin directory
# CROSS_COMPILE: prefix added to readelf, objcopy tools
# XZ: path to the xz binary
# Arguments:
# -i ${file}: input file (required)
# -o ${file}: output file (required)
# -d ${file}: deps file (required)
-# --keep-symbols
-# --keep-mini-debug-info
# --add-gnu-debuglink
+# --keep-mini-debug-info
+# --keep-symbols
+# --use-llvm-strip
OPTSTRING=d:i:o:-:
@@ -33,25 +35,52 @@
cat <<EOF
Usage: strip.sh [options] -i in-file -o out-file -d deps-file
Options:
- --keep-symbols Keep symbols in out-file
- --keep-mini-debug-info Keep compressed debug info in out-file
--add-gnu-debuglink Add a gnu-debuglink section to out-file
+ --keep-mini-debug-info Keep compressed debug info in out-file
+ --keep-symbols Keep symbols in out-file
+ --use-llvm-strip Use llvm-{strip,objcopy} instead of strip/objcopy
EOF
exit 1
}
+# With --use-llvm-strip, GNU strip is replaced with llvm-strip to work around
+# old GNU strip bug on lld output files, b/80093681.
+# Similary, calls to objcopy are replaced with llvm-objcopy,
+# with some exceptions.
+
do_strip() {
- "${CROSS_COMPILE}strip" --strip-all "${infile}" -o "${outfile}.tmp"
+ # ${CROSS_COMPILE}strip --strip-all does not strip .ARM.attributes,
+ # so we tell llvm-strip to keep it too.
+ if [ ! -z "${use_llvm_strip}" ]; then
+ "${CLANG_BIN}/llvm-strip" --strip-all -keep=.ARM.attributes "${infile}" "${outfile}.tmp"
+ else
+ "${CROSS_COMPILE}strip" --strip-all "${infile}" -o "${outfile}.tmp"
+ fi
}
do_strip_keep_symbols() {
- "${CROSS_COMPILE}objcopy" "${infile}" "${outfile}.tmp" \
- `"${CROSS_COMPILE}readelf" -S "${infile}" | awk '/.debug_/ {print "-R " $2}' | xargs`
+ # Maybe we should replace this objcopy with llvm-objcopy, but
+ # we have not found a use case that is broken by objcopy yet.
+ REMOVE_SECTIONS=`"${CROSS_COMPILE}readelf" -S "${infile}" | awk '/.debug_/ {print "--remove-section " $2}' | xargs`
+ if [ ! -z "${use_llvm_strip}" ]; then
+ "${CROSS_COMPILE}objcopy" "${infile}" "${outfile}.tmp" ${REMOVE_SECTIONS}
+ else
+ "${CLANG_BIN}/llvm-objcopy" "${infile}" "${outfile}.tmp" ${REMOVE_SECTIONS}
+ fi
}
do_strip_keep_mini_debug_info() {
rm -f "${outfile}.dynsyms" "${outfile}.funcsyms" "${outfile}.keep_symbols" "${outfile}.debug" "${outfile}.mini_debuginfo" "${outfile}.mini_debuginfo.xz"
- if "${CROSS_COMPILE}strip" --strip-all -R .comment "${infile}" -o "${outfile}.tmp"; then
+ if [ ! -z "${use_llvm_strip}" ]; then
+ "${CLANG_BIN}/llvm-strip" --strip-all -keep=.ARM.attributes -remove-section=.comment "${infile}" "${outfile}.tmp"
+ else
+ "${CROSS_COMPILE}strip" --strip-all -R .comment "${infile}" -o "${outfile}.tmp"
+ fi
+ if [ "$?" == "0" ]; then
+ # Current prebult llvm-objcopy does not support the following flags:
+ # --only-keep-debug --rename-section --keep-symbols
+ # For the following use cases, ${CROSS_COMPILE}objcopy does fine with lld linked files,
+ # except the --add-section flag.
"${CROSS_COMPILE}objcopy" --only-keep-debug "${infile}" "${outfile}.debug"
"${CROSS_COMPILE}nm" -D "${infile}" --format=posix --defined-only | awk '{ print $$1 }' | sort >"${outfile}.dynsyms"
"${CROSS_COMPILE}nm" "${infile}" --format=posix --defined-only | awk '{ if ($$2 == "T" || $$2 == "t" || $$2 == "D") print $$1 }' | sort > "${outfile}.funcsyms"
@@ -61,14 +90,22 @@
"${CROSS_COMPILE}objcopy" -S --remove-section .gdb_index --remove-section .comment --keep-symbols="${outfile}.keep_symbols" "${outfile}.mini_debuginfo"
"${CROSS_COMPILE}objcopy" --rename-section saved_debug_frame=.debug_frame "${outfile}.mini_debuginfo"
"${XZ}" "${outfile}.mini_debuginfo"
- "${CROSS_COMPILE}objcopy" --add-section .gnu_debugdata="${outfile}.mini_debuginfo.xz" "${outfile}.tmp"
+ if [ ! -z "${use_llvm_strip}" ]; then
+ "${CLANG_BIN}/llvm-objcopy" --add-section .gnu_debugdata="${outfile}.mini_debuginfo.xz" "${outfile}.tmp"
+ else
+ "${CROSS_COMPILE}objcopy" --add-section .gnu_debugdata="${outfile}.mini_debuginfo.xz" "${outfile}.tmp"
+ fi
else
cp -f "${infile}" "${outfile}.tmp"
fi
}
do_add_gnu_debuglink() {
- "${CROSS_COMPILE}objcopy" --add-gnu-debuglink="${infile}" "${outfile}.tmp"
+ if [ ! -z "${use_llvm_strip}" ]; then
+ "${CLANG_BIN}/llvm-objcopy" --add-gnu-debuglink="${infile}" "${outfile}.tmp"
+ else
+ "${CROSS_COMPILE}objcopy" --add-gnu-debuglink="${infile}" "${outfile}.tmp"
+ fi
}
while getopts $OPTSTRING opt; do
@@ -78,9 +115,10 @@
o) outfile="${OPTARG}" ;;
-)
case "${OPTARG}" in
- keep-symbols) keep_symbols=true ;;
- keep-mini-debug-info) keep_mini_debug_info=true ;;
add-gnu-debuglink) add_gnu_debuglink=true ;;
+ keep-mini-debug-info) keep_mini_debug_info=true ;;
+ keep-symbols) keep_symbols=true ;;
+ use-llvm-strip) use_llvm_strip=true ;;
*) echo "Unknown option --${OPTARG}"; usage ;;
esac;;
?) usage ;;
@@ -130,12 +168,18 @@
rm -f "${outfile}"
mv "${outfile}.tmp" "${outfile}"
+if [ ! -z "${use_llvm_strip}" ]; then
+ USED_STRIP_OBJCOPY="${CLANG_BIN}/llvm-strip ${CLANG_BIN}/llvm-objcopy"
+else
+ USED_STRIP_OBJCOPY="${CROSS_COMPILE}strip"
+fi
+
cat <<EOF > "${depsfile}"
${outfile}: \
${infile} \
${CROSS_COMPILE}nm \
${CROSS_COMPILE}objcopy \
${CROSS_COMPILE}readelf \
- ${CROSS_COMPILE}strip
+ ${USED_STRIP_OBJCOPY}
EOF