Commit f0545bf2 authored by Calder Kitagawa's avatar Calder Kitagawa Committed by Commit Bot

[Zucchini] Buildflag control of architectures

Allows Zucchini to be built with only a subset of architectures enabled
this saves on binary size at the cost of flexibility. The idea is that
only the desired architectures would be compiled for a particular
usecases. For example the Windows setup.exe only needs Windows support.

Expected savings as a percent of total binary size at present
(868.5 kB non-debug):
- Remove DEX 3.13% (841.3 kB)
- Remove Win 6.00% (816.4 kB)
- Only Raw 9.13% (789.2 kB)

Note that in the case of Raw saving could be made significantly higher
by entirely removing the dependence on references and reference
projection. However, at present the additional messiness of the
additional buildflags all over the codebase is not worth the
maintenance costs.

Bug: 835007
Change-Id: I091cb9d76e8473340374be1a33a5df48137a3067
Reviewed-on: https://chromium-review.googlesource.com/1037922
Commit-Queue: Calder Kitagawa <ckitagawa@google.com>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556802}
parent cdc12d12
......@@ -2,9 +2,22 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/buildflag_header.gni")
import("//chrome/process_version_rc_template.gni")
import("//testing/test.gni")
buildflag_header("buildflags") {
header = "buildflags.h"
# Disable DEX on Windows Official Builds.
_enable_dex = !(is_win && is_official_build)
_enable_win = true
flags = [
"ENABLE_DEX=$_enable_dex",
"ENABLE_WIN=$_enable_win",
]
}
static_library("zucchini_lib") {
sources = [
"abs32_utils.cc",
......@@ -79,6 +92,7 @@ static_library("zucchini_lib") {
]
deps = [
":buildflags",
"//base",
]
}
......
......@@ -7,6 +7,7 @@
#include <utility>
#include "base/logging.h"
#include "components/zucchini/buildflags.h"
#include "components/zucchini/disassembler.h"
#include "components/zucchini/disassembler_dex.h"
#include "components/zucchini/disassembler_no_op.h"
......@@ -17,7 +18,7 @@ namespace zucchini {
namespace {
// Impose a minimal program size to eliminate pathological cases.
constexpr size_t kMinProgramSize = 16;
enum : size_t { kMinProgramSize = 16 };
} // namespace
......@@ -25,6 +26,7 @@ constexpr size_t kMinProgramSize = 16;
std::unique_ptr<Disassembler> MakeDisassemblerWithoutFallback(
ConstBufferView image) {
#if BUILDFLAG(ENABLE_WIN)
if (DisassemblerWin32X86::QuickDetect(image)) {
auto disasm = Disassembler::Make<DisassemblerWin32X86>(image);
if (disasm && disasm->size() >= kMinProgramSize)
......@@ -36,12 +38,15 @@ std::unique_ptr<Disassembler> MakeDisassemblerWithoutFallback(
if (disasm && disasm->size() >= kMinProgramSize)
return disasm;
}
#endif // BUILDFLAG(ENABLE_WIN)
#if BUILDFLAG(ENABLE_DEX)
if (DisassemblerDex::QuickDetect(image)) {
auto disasm = Disassembler::Make<DisassemblerDex>(image);
if (disasm && disasm->size() >= kMinProgramSize)
return disasm;
}
#endif // BUILDFLAG(ENABLE_DEX)
return nullptr;
}
......@@ -49,15 +54,20 @@ std::unique_ptr<Disassembler> MakeDisassemblerWithoutFallback(
std::unique_ptr<Disassembler> MakeDisassemblerOfType(ConstBufferView image,
ExecutableType exe_type) {
switch (exe_type) {
#if BUILDFLAG(ENABLE_WIN)
case kExeTypeWin32X86:
return Disassembler::Make<DisassemblerWin32X86>(image);
case kExeTypeWin32X64:
return Disassembler::Make<DisassemblerWin32X64>(image);
#endif // BUILDFLAG(ENABLE_WIN)
#if BUILDFLAG(ENABLE_DEX)
case kExeTypeDex:
return Disassembler::Make<DisassemblerDex>(image);
#endif // BUILDFLAG(ENABLE_DEX)
case kExeTypeNoOp:
return Disassembler::Make<DisassemblerNoOp>(image);
default:
// If an architecture is disabled then null is handled gracefully.
return nullptr;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment