Disable ScopedTrace in static libdexfile
Static libdexfile is only used for dex2oat and tests on host, and
used by simpleperf on device. Both places don't care about traces.
Static libdexfile is used in simpleperf static binary in NDK. So it
needs to avoid dlopen caused by ScopedTrace. So make below changes:
1) To avoid calling dlopen, disable ScopedTrace in static libdexfile.
2) To prevent using dlopen in static libdexfile in the future, build
art_libdexfile_static_tests as a static binary on device.
Bug: 270754876
Test: run art_libdexfile_static_tests
Change-Id: I12d6290eddac35df73ff0670b6f0a3065ace34df
diff --git a/libdexfile/dex/dex_file_loader.cc b/libdexfile/dex/dex_file_loader.cc
index 069b28b..4395474 100644
--- a/libdexfile/dex/dex_file_loader.cc
+++ b/libdexfile/dex/dex_file_loader.cc
@@ -37,6 +37,12 @@
namespace art {
+#if defined(STATIC_LIB)
+#define DEXFILE_SCOPED_TRACE(name)
+#else
+#define DEXFILE_SCOPED_TRACE(name) ScopedTrace trace(name)
+#endif
+
namespace {
// Technically we do not have a limitation with respect to the number of dex files that can be in a
@@ -186,7 +192,7 @@
bool verify,
bool verify_checksum,
std::string* error_msg) {
- ScopedTrace trace(std::string("Open dex file ") + location_);
+ DEXFILE_SCOPED_TRACE(std::string("Open dex file ") + location_);
uint32_t magic;
if (!InitAndReadMagic(&magic, error_msg) || !MapRootContainer(error_msg)) {
@@ -270,7 +276,7 @@
DexFileLoaderErrorCode* error_code,
std::string* error_msg,
std::vector<std::unique_ptr<const DexFile>>* dex_files) {
- ScopedTrace trace(std::string("Open dex file ") + location_);
+ DEXFILE_SCOPED_TRACE(std::string("Open dex file ") + location_);
DCHECK(dex_files != nullptr) << "DexFile::Open: out-param is nullptr";
@@ -381,7 +387,7 @@
}
// NB: Dex verifier does not understand the compact dex format.
if (verify && !dex_file->IsCompactDexFile()) {
- ScopedTrace trace(std::string("Verify dex file ") + location);
+ DEXFILE_SCOPED_TRACE(std::string("Verify dex file ") + location);
if (!dex::Verify(dex_file.get(), location.c_str(), verify_checksum, error_msg)) {
if (error_code != nullptr) {
*error_code = DexFileLoaderErrorCode::kVerifyError;
@@ -437,7 +443,7 @@
}
}
if (!map.IsValid()) {
- ScopedTrace trace(std::string("Extract dex file ") + location);
+ DEXFILE_SCOPED_TRACE(std::string("Extract dex file ") + location);
// Default path for compressed ZIP entries,
// and fallback for stored ZIP entries.