libbinder: support exporting fewer symbols
This commit explicitly marks symbols in the code with default visibility
if they should be part of the libbinder ABI. Later, we'll set the
default symbol visibility to hidden and so any symbols not explicitly
marked as exported will be hidden.
We are still overexporting symbols a bit. When `LIBBINDER_EXPORTED` is
applied to a class, it exports all of that class's symbols. I've tried
to only export class members, but in a few cases it didn't seem worth
the trouble, e.g. where all the members need to be exported.
Additionally, we are exporting some symbols only needed by binder test
binaries. Since those tests run against the standard libbinder.so, we
need to include the symbols as part of the ABI.
On aarch64, this reduces the size of libbinder_on_trusty_mock.so by
10.7% and libbinder.so by 7.5%, primarily in the .text, .dynstr, and
.dynsym sections (but none of this takes effect until we actually
enabled it in a later commit).
Bug: 338458975
Test: TH
Change-Id: Idc348c2b12124a8bbcebeea49920267a995367b6
diff --git a/libs/binder/UtilsHost.h b/libs/binder/UtilsHost.h
index d6fe9fa..03af1e7 100644
--- a/libs/binder/UtilsHost.h
+++ b/libs/binder/UtilsHost.h
@@ -24,6 +24,7 @@
#include <vector>
#include <android-base/macros.h>
+#include <binder/Common.h>
#include <binder/unique_fd.h>
#include <utils/Errors.h>
@@ -40,7 +41,7 @@
namespace android {
-struct CommandResult {
+struct LIBBINDER_EXPORTED CommandResult {
std::optional<int32_t> exitCode;
std::optional<int32_t> signal;
std::optional<pid_t> pid;
@@ -72,7 +73,7 @@
void operator=(const CommandResult&) = delete;
};
-std::ostream& operator<<(std::ostream& os, const CommandResult& res);
+LIBBINDER_EXPORTED std::ostream& operator<<(std::ostream& os, const CommandResult& res);
// Execute a command using tokens specified in @a argStringVec.
//
@@ -96,6 +97,7 @@
//
// If the parent process has encountered any errors for system calls, return ExecuteError with
// the proper errno set.
-std::optional<CommandResult> execute(std::vector<std::string> argStringVec,
- const std::function<bool(const CommandResult&)>& end);
+LIBBINDER_EXPORTED std::optional<CommandResult> execute(
+ std::vector<std::string> argStringVec,
+ const std::function<bool(const CommandResult&)>& end);
} // namespace android