aboutsummaryrefslogtreecommitdiff
path: root/reference_bytes_mixer.h
diff options
context:
space:
mode:
authorSamuel Huang <huangs@chromium.org>2021-08-05 16:46:38 +0000
committerCopybara-Service <copybara-worker@google.com>2021-08-05 10:05:02 -0700
commitfa10b05c4854c6d8a603ee47c2a213cbc23f8646 (patch)
tree94ad9d794dedc26bd0e0be4b18511d45026a0b98 /reference_bytes_mixer.h
parent3e1f64d1395c53a730475d930b663d5f6006099e (diff)
downloadzucchini-fa10b05c4854c6d8a603ee47c2a213cbc23f8646.tar.gz
[Zucchini] Add ARM support for ELF files.
This CL enables ARM-ELF (AArch32 and AArch64) support in Zucchini. * Define ARM {AArch32, AArch64}ReferenceType. * Add Rel32Finder{Arm, AArch32, AArch64} (with tests) to use previously-added ARM disassembly code to extract rel32 references. * Add DisassemblerElf{Arm, AArch32, AArch64} to parse ARM ELF files and create reference readers / writers, and reference groups. * For AArch32: Add heuristic detection of ARM vs. Thumb2 mode. * Add IsTargetOffsetInElfSectionList() (with tests) to help ARM reject false positive references. * Add ReferenceBytesMixerElfArm to remove redundant reference target information from bytewise correction data. Bug: 918867 Change-Id: I1e6d3d8b8d174c85a3d44ca6d642b7ff0bd6a6a6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2922822 Commit-Queue: Samuel Huang <huangs@chromium.org> Reviewed-by: Etienne Pierre-Doray <etiennep@chromium.org> Cr-Commit-Position: refs/heads/master@{#908913} NOKEYCHECK=True GitOrigin-RevId: 85cc8a596f183487b395a59e80b2f654f241ab2c
Diffstat (limited to 'reference_bytes_mixer.h')
-rw-r--r--reference_bytes_mixer.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/reference_bytes_mixer.h b/reference_bytes_mixer.h
index 3cbf187..f20b0ef 100644
--- a/reference_bytes_mixer.h
+++ b/reference_bytes_mixer.h
@@ -11,6 +11,7 @@
#include "components/zucchini/buffer_view.h"
#include "components/zucchini/image_utils.h"
+#include "components/zucchini/rel32_utils.h"
namespace zucchini {
@@ -83,6 +84,35 @@ class ReferenceBytesMixer {
offset_t new_offset);
};
+// In AArch32 and AArch64, instructions mix operation bits and payload bits in
+// complex ways. This is the main use case of ReferenceBytesMixer.
+class ReferenceBytesMixerElfArm : public ReferenceBytesMixer {
+ public:
+ // |exe_type| must be EXE_TYPE_ELF_ARM or EXE_TYPE_ELF_AARCH64.
+ explicit ReferenceBytesMixerElfArm(ExecutableType exe_type);
+ ReferenceBytesMixerElfArm(const ReferenceBytesMixerElfArm&) = delete;
+ const ReferenceBytesMixerElfArm& operator=(const ReferenceBytesMixerElfArm&) =
+ delete;
+ ~ReferenceBytesMixerElfArm() override;
+
+ // ReferenceBytesMixer:
+ int NumBytes(uint8_t type) const override;
+ ConstBufferView Mix(uint8_t type,
+ ConstBufferView old_view,
+ offset_t old_offset,
+ ConstBufferView new_view,
+ offset_t new_offset) override;
+
+ private:
+ ArmCopyDispFun GetCopier(uint8_t type) const;
+
+ // For simplicity, 32-bit vs. 64-bit distinction is represented by state
+ // |exe_type_|, instead of creating derived classes.
+ const ExecutableType exe_type_;
+
+ std::vector<uint8_t> out_buffer_;
+};
+
} // namespace zucchini
#endif // COMPONENTS_ZUCCHINI_REFERENCE_BYTES_MIXER_H_