diff options
author | 2022-09-30 12:28:49 +0200 | |
---|---|---|
committer | 2022-10-03 07:06:53 +0000 | |
commit | 467d570d3f4aceed70a66136814b965f48b3e4db (patch) | |
tree | b118a5fc49a863a7e53a4b5ebc365bc2d5355856 | |
parent | 1abcef8f7be84ea933bb1f61de01693babdcf549 (diff) |
Refactor Thumb2 entrypoint adjustment handling.
Reduce dependencies on `compiled_method.h` in preparation
for moving it to dex2oat/.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Test: run-gtests.sh
Test: testrunner.py --target --optimizing
Change-Id: I55ff807e0c7d729142b1a64a3a0b6c6267027dc3
-rw-r--r-- | compiler/compiled_method.cc | 21 | ||||
-rw-r--r-- | compiler/compiled_method.h | 7 | ||||
-rw-r--r-- | compiler/debug/elf_debug_loc_writer.h | 1 | ||||
-rw-r--r-- | compiler/debug/elf_debug_writer.cc | 3 | ||||
-rw-r--r-- | compiler/debug/elf_symtab_writer.h | 2 | ||||
-rw-r--r-- | compiler/jit/jit_logger.h | 1 | ||||
-rw-r--r-- | compiler/optimizing/code_generator.cc | 1 | ||||
-rw-r--r-- | compiler/optimizing/code_generator_arm64.cc | 1 | ||||
-rw-r--r-- | compiler/optimizing/code_generator_arm_vixl.cc | 1 | ||||
-rw-r--r-- | compiler/optimizing/code_generator_x86.cc | 1 | ||||
-rw-r--r-- | compiler/optimizing/code_generator_x86_64.cc | 1 | ||||
-rw-r--r-- | dex2oat/linker/arm/relative_patcher_arm_base.cc | 3 | ||||
-rw-r--r-- | dex2oat/linker/elf_writer_quick.cc | 1 | ||||
-rw-r--r-- | dex2oat/linker/image_writer.cc | 1 | ||||
-rw-r--r-- | dex2oat/linker/oat_writer.cc | 39 | ||||
-rw-r--r-- | dex2oat/linker/relative_patcher_test.h | 7 | ||||
-rw-r--r-- | dex2oat/linker/x86/relative_patcher_x86.cc | 1 | ||||
-rw-r--r-- | dex2oat/linker/x86_64/relative_patcher_x86_64.cc | 1 | ||||
-rw-r--r-- | libartbase/arch/instruction_set.h | 42 | ||||
-rw-r--r-- | oatdump/oatdump.cc | 23 |
20 files changed, 76 insertions, 82 deletions
diff --git a/compiler/compiled_method.cc b/compiler/compiled_method.cc index e7cdd6eec5..21d5ed927f 100644 --- a/compiler/compiled_method.cc +++ b/compiler/compiled_method.cc @@ -54,25 +54,8 @@ size_t CompiledCode::AlignCode(size_t offset, InstructionSet instruction_set) { return RoundUp(offset, GetInstructionSetCodeAlignment(instruction_set)); } -size_t CompiledCode::CodeDelta() const { - return CodeDelta(GetInstructionSet()); -} - -size_t CompiledCode::CodeDelta(InstructionSet instruction_set) { - switch (instruction_set) { - case InstructionSet::kArm: - case InstructionSet::kArm64: - case InstructionSet::kX86: - case InstructionSet::kX86_64: - return 0; - case InstructionSet::kThumb2: { - // +1 to set the low-order bit so a BLX will switch to Thumb mode - return 1; - } - default: - LOG(FATAL) << "Unknown InstructionSet: " << instruction_set; - UNREACHABLE(); - } +size_t CompiledCode::GetEntryPointAdjustment() const { + return GetInstructionSetEntryPointAdjustment(GetInstructionSet()); } const void* CompiledCode::CodePointer(const void* code_pointer, InstructionSet instruction_set) { diff --git a/compiler/compiled_method.h b/compiler/compiled_method.h index e92777ff12..fa80d67b40 100644 --- a/compiler/compiled_method.h +++ b/compiler/compiled_method.h @@ -58,10 +58,9 @@ class CompiledCode { size_t AlignCode(size_t offset) const; static size_t AlignCode(size_t offset, InstructionSet instruction_set); - // returns the difference between the code address and a usable PC. - // mainly to cope with kThumb2 where the lower bit must be set. - size_t CodeDelta() const; - static size_t CodeDelta(InstructionSet instruction_set); + // Returns the difference between the code address and a usable PC. + // Mainly to cope with `kThumb2` where the lower bit must be set. + size_t GetEntryPointAdjustment() const; // Returns a pointer suitable for invoking the code at the argument // code_pointer address. Mainly to cope with kThumb2 where the diff --git a/compiler/debug/elf_debug_loc_writer.h b/compiler/debug/elf_debug_loc_writer.h index 37ab948119..9be1e2402d 100644 --- a/compiler/debug/elf_debug_loc_writer.h +++ b/compiler/debug/elf_debug_loc_writer.h @@ -21,7 +21,6 @@ #include <map> #include "arch/instruction_set.h" -#include "compiled_method.h" #include "debug/method_debug_info.h" #include "dwarf/debug_info_entry_writer.h" #include "dwarf/register.h" diff --git a/compiler/debug/elf_debug_writer.cc b/compiler/debug/elf_debug_writer.cc index 765a81d4f8..d8007c09d4 100644 --- a/compiler/debug/elf_debug_writer.cc +++ b/compiler/debug/elf_debug_writer.cc @@ -208,7 +208,8 @@ std::vector<uint8_t> MakeElfFileForJIT( using Reader = ElfDebugReader<ElfTypes>; Reader reader(buffer); reader.VisitFunctionSymbols([&](Elf_Sym sym, const char*) { - DCHECK_EQ(sym.st_value, method_info.code_address + CompiledMethod::CodeDelta(isa)); + DCHECK_EQ(sym.st_value, + method_info.code_address + GetInstructionSetEntryPointAdjustment(isa)); DCHECK_EQ(sym.st_size, method_info.code_size); num_syms++; }); diff --git a/compiler/debug/elf_symtab_writer.h b/compiler/debug/elf_symtab_writer.h index 410f704582..d2acd64c2a 100644 --- a/compiler/debug/elf_symtab_writer.h +++ b/compiler/debug/elf_symtab_writer.h @@ -153,7 +153,7 @@ static void WriteDebugSymbols(ElfBuilder<ElfTypes>* builder, uint64_t address = info.code_address; address += info.is_code_address_text_relative ? text->GetAddress() : 0; // Add in code delta, e.g., thumb bit 0 for Thumb2 code. - address += CompiledMethod::CodeDelta(info.isa); + address += GetInstructionSetEntryPointAdjustment(info.isa); symtab->Add(name_offset, text, address, info.code_size, STB_GLOBAL, STT_FUNC); } // Add symbols for dex files. diff --git a/compiler/jit/jit_logger.h b/compiler/jit/jit_logger.h index f4ef75a5fe..61a4dcf4d8 100644 --- a/compiler/jit/jit_logger.h +++ b/compiler/jit/jit_logger.h @@ -21,7 +21,6 @@ #include "base/mutex.h" #include "base/os.h" -#include "compiled_method.h" namespace art { diff --git a/compiler/optimizing/code_generator.cc b/compiler/optimizing/code_generator.cc index 252e756737..bd8db30d44 100644 --- a/compiler/optimizing/code_generator.cc +++ b/compiler/optimizing/code_generator.cc @@ -39,7 +39,6 @@ #include "base/leb128.h" #include "class_linker.h" #include "class_root-inl.h" -#include "compiled_method.h" #include "dex/bytecode_utils.h" #include "dex/code_item_accessors-inl.h" #include "graph_visualizer.h" diff --git a/compiler/optimizing/code_generator_arm64.cc b/compiler/optimizing/code_generator_arm64.cc index 7fb6d3c4be..b34b613849 100644 --- a/compiler/optimizing/code_generator_arm64.cc +++ b/compiler/optimizing/code_generator_arm64.cc @@ -27,7 +27,6 @@ #include "class_root-inl.h" #include "class_table.h" #include "code_generator_utils.h" -#include "compiled_method.h" #include "entrypoints/quick/quick_entrypoints.h" #include "entrypoints/quick/quick_entrypoints_enum.h" #include "gc/accounting/card_table.h" diff --git a/compiler/optimizing/code_generator_arm_vixl.cc b/compiler/optimizing/code_generator_arm_vixl.cc index f0cca90c11..8cea5f98cf 100644 --- a/compiler/optimizing/code_generator_arm_vixl.cc +++ b/compiler/optimizing/code_generator_arm_vixl.cc @@ -26,7 +26,6 @@ #include "class_table.h" #include "code_generator_utils.h" #include "common_arm.h" -#include "compiled_method.h" #include "entrypoints/quick/quick_entrypoints.h" #include "gc/accounting/card_table.h" #include "gc/space/image_space.h" diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc index ce27083d00..04373c5600 100644 --- a/compiler/optimizing/code_generator_x86.cc +++ b/compiler/optimizing/code_generator_x86.cc @@ -20,7 +20,6 @@ #include "art_method-inl.h" #include "class_table.h" #include "code_generator_utils.h" -#include "compiled_method.h" #include "entrypoints/quick/quick_entrypoints.h" #include "entrypoints/quick/quick_entrypoints_enum.h" #include "gc/accounting/card_table.h" diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc index b1db993be1..40a1cd2293 100644 --- a/compiler/optimizing/code_generator_x86_64.cc +++ b/compiler/optimizing/code_generator_x86_64.cc @@ -21,7 +21,6 @@ #include "class_root-inl.h" #include "class_table.h" #include "code_generator_utils.h" -#include "compiled_method.h" #include "entrypoints/quick/quick_entrypoints.h" #include "gc/accounting/card_table.h" #include "gc/space/image_space.h" diff --git a/dex2oat/linker/arm/relative_patcher_arm_base.cc b/dex2oat/linker/arm/relative_patcher_arm_base.cc index 6d913228f8..d0744326fc 100644 --- a/dex2oat/linker/arm/relative_patcher_arm_base.cc +++ b/dex2oat/linker/arm/relative_patcher_arm_base.cc @@ -501,7 +501,8 @@ void ArmBaseRelativePatcher::ResolveMethodCalls(uint32_t quick_code_offset, if (!result.first) { break; } - uint32_t target_offset = result.second - CompiledCode::CodeDelta(instruction_set_); + uint32_t target_offset = + result.second - GetInstructionSetEntryPointAdjustment(instruction_set_); if (target_offset >= patch_offset) { DCHECK_LE(target_offset - patch_offset, max_positive_displacement); } else if (patch_offset - target_offset > max_negative_displacement) { diff --git a/dex2oat/linker/elf_writer_quick.cc b/dex2oat/linker/elf_writer_quick.cc index 424c252e6f..61e578368b 100644 --- a/dex2oat/linker/elf_writer_quick.cc +++ b/dex2oat/linker/elf_writer_quick.cc @@ -25,7 +25,6 @@ #include "base/globals.h" #include "base/leb128.h" #include "base/utils.h" -#include "compiled_method.h" #include "debug/elf_debug_writer.h" #include "debug/method_debug_info.h" #include "driver/compiler_options.h" diff --git a/dex2oat/linker/image_writer.cc b/dex2oat/linker/image_writer.cc index 07afa369aa..483165a762 100644 --- a/dex2oat/linker/image_writer.cc +++ b/dex2oat/linker/image_writer.cc @@ -35,7 +35,6 @@ #include "base/unix_file/fd_file.h" #include "class_linker-inl.h" #include "class_root-inl.h" -#include "compiled_method.h" #include "dex/dex_file-inl.h" #include "dex/dex_file_types.h" #include "driver/compiler_options.h" diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc index fcec2e2ef6..b12ef4f852 100644 --- a/dex2oat/linker/oat_writer.cc +++ b/dex2oat/linker/oat_writer.cc @@ -1353,7 +1353,7 @@ class OatWriter::LayoutReserveOffsetCodeMethodVisitor : public OrderedMethodVisi ArrayRef<const uint8_t> quick_code = compiled_method->GetQuickCode(); uint32_t code_size = quick_code.size() * sizeof(uint8_t); - uint32_t thumb_offset = compiled_method->CodeDelta(); + uint32_t thumb_offset = compiled_method->GetEntryPointAdjustment(); // Deduplicate code arrays if we are not producing debuggable code. bool deduped = true; @@ -1800,8 +1800,9 @@ class OatWriter::WriteCodeMethodVisitor : public OrderedMethodVisitor { } DCHECK_ALIGNED_PARAM(offset_ + sizeof(OatQuickMethodHeader), GetInstructionSetCodeAlignment(compiled_method->GetInstructionSet())); - DCHECK_EQ(method_offsets.code_offset_, - offset_ + sizeof(OatQuickMethodHeader) + compiled_method->CodeDelta()) + DCHECK_EQ( + method_offsets.code_offset_, + offset_ + sizeof(OatQuickMethodHeader) + compiled_method->GetEntryPointAdjustment()) << dex_file_->PrettyMethod(method_ref.index); const OatQuickMethodHeader& method_header = oat_class->method_headers_[method_offsets_index]; @@ -2398,22 +2399,22 @@ size_t OatWriter::InitOatCode(size_t offset) { const bool generate_debug_info = GetCompilerOptions().GenerateAnyDebugInfo(); size_t adjusted_offset = offset; - #define DO_TRAMPOLINE(field, fn_name) \ - /* Pad with at least four 0xFFs so we can do DCHECKs in OatQuickMethodHeader */ \ - offset = CompiledCode::AlignCode(offset + 4, instruction_set); \ - adjusted_offset = offset + CompiledCode::CodeDelta(instruction_set); \ - oat_header_->Set ## fn_name ## Offset(adjusted_offset); \ - (field) = compiler_driver_->Create ## fn_name(); \ - if (generate_debug_info) { \ - debug::MethodDebugInfo info = {}; \ - info.custom_name = #fn_name; \ - info.isa = instruction_set; \ - info.is_code_address_text_relative = true; \ - /* Use the code offset rather than the `adjusted_offset`. */ \ - info.code_address = offset - oat_header_->GetExecutableOffset(); \ - info.code_size = (field)->size(); \ - method_info_.push_back(std::move(info)); \ - } \ + #define DO_TRAMPOLINE(field, fn_name) \ + /* Pad with at least four 0xFFs so we can do DCHECKs in OatQuickMethodHeader */ \ + offset = CompiledCode::AlignCode(offset + 4, instruction_set); \ + adjusted_offset = offset + GetInstructionSetEntryPointAdjustment(instruction_set); \ + oat_header_->Set ## fn_name ## Offset(adjusted_offset); \ + (field) = compiler_driver_->Create ## fn_name(); \ + if (generate_debug_info) { \ + debug::MethodDebugInfo info = {}; \ + info.custom_name = #fn_name; \ + info.isa = instruction_set; \ + info.is_code_address_text_relative = true; \ + /* Use the code offset rather than the `adjusted_offset`. */ \ + info.code_address = offset - oat_header_->GetExecutableOffset(); \ + info.code_size = (field)->size(); \ + method_info_.push_back(std::move(info)); \ + } \ offset += (field)->size(); DO_TRAMPOLINE(jni_dlsym_lookup_trampoline_, JniDlsymLookupTrampoline); diff --git a/dex2oat/linker/relative_patcher_test.h b/dex2oat/linker/relative_patcher_test.h index 56e0dc19a7..f25b5012ac 100644 --- a/dex2oat/linker/relative_patcher_test.h +++ b/dex2oat/linker/relative_patcher_test.h @@ -132,7 +132,7 @@ class RelativePatcherTest : public testing::Test { offset += alignment_size; offset += sizeof(OatQuickMethodHeader); - uint32_t quick_code_offset = offset + compiled_method->CodeDelta(); + uint32_t quick_code_offset = offset + compiled_method->GetEntryPointAdjustment(); const auto code = compiled_method->GetQuickCode(); offset += code.size(); @@ -172,7 +172,8 @@ class RelativePatcherTest : public testing::Test { if (patch.GetType() == LinkerPatch::Type::kCallRelative) { auto result = method_offset_map_.FindMethodOffset(patch.TargetMethod()); uint32_t target_offset = - result.first ? result.second : kTrampolineOffset + compiled_method->CodeDelta(); + result.first ? result.second + : kTrampolineOffset + compiled_method->GetEntryPointAdjustment(); patcher_->PatchCall(&patched_code_, patch.LiteralOffset(), offset + patch.LiteralOffset(), @@ -227,7 +228,7 @@ class RelativePatcherTest : public testing::Test { auto result = method_offset_map_.FindMethodOffset(method_ref); CHECK(result.first); // Must have been linked. - size_t offset = result.second - compiled_methods_[idx]->CodeDelta(); + size_t offset = result.second - compiled_methods_[idx]->GetEntryPointAdjustment(); CHECK_LT(offset, output_.size()); CHECK_LE(offset + expected_code.size(), output_.size()); ArrayRef<const uint8_t> linked_code(&output_[offset], expected_code.size()); diff --git a/dex2oat/linker/x86/relative_patcher_x86.cc b/dex2oat/linker/x86/relative_patcher_x86.cc index e3b94b0453..a4444461a3 100644 --- a/dex2oat/linker/x86/relative_patcher_x86.cc +++ b/dex2oat/linker/x86/relative_patcher_x86.cc @@ -16,7 +16,6 @@ #include "linker/x86/relative_patcher_x86.h" -#include "compiled_method.h" #include "linker/linker_patch.h" namespace art { diff --git a/dex2oat/linker/x86_64/relative_patcher_x86_64.cc b/dex2oat/linker/x86_64/relative_patcher_x86_64.cc index 0b9d07e9cf..629affcb99 100644 --- a/dex2oat/linker/x86_64/relative_patcher_x86_64.cc +++ b/dex2oat/linker/x86_64/relative_patcher_x86_64.cc @@ -16,7 +16,6 @@ #include "linker/x86_64/relative_patcher_x86_64.h" -#include "compiled_method.h" #include "linker/linker_patch.h" namespace art { diff --git a/libartbase/arch/instruction_set.h b/libartbase/arch/instruction_set.h index 69983d2fe8..e68ff08c17 100644 --- a/libartbase/arch/instruction_set.h +++ b/libartbase/arch/instruction_set.h @@ -99,6 +99,21 @@ constexpr PointerSize GetInstructionSetPointerSize(InstructionSet isa) { InstructionSetAbort(isa); } +constexpr bool IsValidInstructionSet(InstructionSet isa) { + switch (isa) { + case InstructionSet::kArm: + case InstructionSet::kThumb2: + case InstructionSet::kArm64: + case InstructionSet::kX86: + case InstructionSet::kX86_64: + return true; + + case InstructionSet::kNone: + return false; + } + return false; +} + constexpr size_t GetInstructionSetInstructionAlignment(InstructionSet isa) { switch (isa) { case InstructionSet::kArm: @@ -118,33 +133,38 @@ constexpr size_t GetInstructionSetInstructionAlignment(InstructionSet isa) { InstructionSetAbort(isa); } -constexpr bool IsValidInstructionSet(InstructionSet isa) { +constexpr size_t GetInstructionSetCodeAlignment(InstructionSet isa) { switch (isa) { case InstructionSet::kArm: + // Fall-through. case InstructionSet::kThumb2: + return kArmCodeAlignment; case InstructionSet::kArm64: + return kArm64CodeAlignment; case InstructionSet::kX86: + // Fall-through. case InstructionSet::kX86_64: - return true; + return kX86CodeAlignment; case InstructionSet::kNone: - return false; + break; } - return false; + InstructionSetAbort(isa); } -constexpr size_t GetInstructionSetCodeAlignment(InstructionSet isa) { +// Returns the difference between the code address and a usable PC. +// Mainly to cope with `kThumb2` where the lower bit must be set. +constexpr size_t GetInstructionSetEntryPointAdjustment(InstructionSet isa) { switch (isa) { case InstructionSet::kArm: - // Fall-through. - case InstructionSet::kThumb2: - return kArmCodeAlignment; case InstructionSet::kArm64: - return kArm64CodeAlignment; case InstructionSet::kX86: - // Fall-through. case InstructionSet::kX86_64: - return kX86CodeAlignment; + return 0; + case InstructionSet::kThumb2: { + // +1 to set the low-order bit so a BLX will switch to Thumb mode + return 1; + } case InstructionSet::kNone: break; diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc index e69b32a50c..0d163bdcdc 100644 --- a/oatdump/oatdump.cc +++ b/oatdump/oatdump.cc @@ -45,7 +45,6 @@ #include "class_linker-inl.h" #include "class_linker.h" #include "class_root-inl.h" -#include "compiled_method.h" #include "debug/debug_info.h" #include "debug/elf_debug_writer.h" #include "debug/method_debug_info.h" @@ -183,17 +182,17 @@ class OatSymbolizer final { builder_->WriteDynamicSection(); const OatHeader& oat_header = oat_file_->GetOatHeader(); - #define DO_TRAMPOLINE(fn_name) \ - if (oat_header.Get ## fn_name ## Offset() != 0) { \ - debug::MethodDebugInfo info = {}; \ - info.custom_name = #fn_name; \ - info.isa = oat_header.GetInstructionSet(); \ - info.is_code_address_text_relative = true; \ - size_t code_offset = oat_header.Get ## fn_name ## Offset(); \ - code_offset -= CompiledCode::CodeDelta(oat_header.GetInstructionSet()); \ - info.code_address = code_offset - oat_header.GetExecutableOffset(); \ - info.code_size = 0; /* The symbol lasts until the next symbol. */ \ - method_debug_infos_.push_back(std::move(info)); \ + #define DO_TRAMPOLINE(fn_name) \ + if (oat_header.Get ## fn_name ## Offset() != 0) { \ + debug::MethodDebugInfo info = {}; \ + info.custom_name = #fn_name; \ + info.isa = oat_header.GetInstructionSet(); \ + info.is_code_address_text_relative = true; \ + size_t code_offset = oat_header.Get ## fn_name ## Offset(); \ + code_offset -= GetInstructionSetEntryPointAdjustment(oat_header.GetInstructionSet()); \ + info.code_address = code_offset - oat_header.GetExecutableOffset(); \ + info.code_size = 0; /* The symbol lasts until the next symbol. */ \ + method_debug_infos_.push_back(std::move(info)); \ } DO_TRAMPOLINE(JniDlsymLookupTrampoline); DO_TRAMPOLINE(JniDlsymLookupCriticalTrampoline); |