Commit 3e6fa973 authored by Will Harris's avatar Will Harris

Fix courgette ELF x86 dissembler

Courgette cannot parse files that have out of order NOBITS sections and instead
will crash. The solution to this is to skip them and encode them as raw bytes.

Also, courgette has a bug where it incorrectly emits ElfRelocationInstruction
instructions even when there are no valid R_386_RELATIVE relocations in the
file.

Added a test file that exhibits both of these symptoms.

BUG=424820,423925
TEST=courgette_unittests
R=dgarrett@chromium.org, tommi@chromium.org

Review URL: https://codereview.chromium.org/664803002

Cr-Commit-Position: refs/heads/master@{#318764}
parent 94b8fe46
...@@ -262,6 +262,9 @@ CheckBool DisassemblerElf32::ParseFile(AssemblyProgram* program) { ...@@ -262,6 +262,9 @@ CheckBool DisassemblerElf32::ParseFile(AssemblyProgram* program) {
const Elf32_Shdr *section_header = SectionHeader(section_id); const Elf32_Shdr *section_header = SectionHeader(section_id);
if (section_header->sh_type == SHT_NOBITS)
continue;
if (!ParseSimpleRegion(file_offset, if (!ParseSimpleRegion(file_offset,
section_header->sh_offset, section_header->sh_offset,
program)) program))
...@@ -282,8 +285,6 @@ CheckBool DisassemblerElf32::ParseFile(AssemblyProgram* program) { ...@@ -282,8 +285,6 @@ CheckBool DisassemblerElf32::ParseFile(AssemblyProgram* program) {
return false; return false;
file_offset = section_header->sh_offset + section_header->sh_size; file_offset = section_header->sh_offset + section_header->sh_size;
break; break;
case SHT_NOBITS:
// Fall through
case SHT_INIT_ARRAY: case SHT_INIT_ARRAY:
// Fall through // Fall through
case SHT_FINI_ARRAY: case SHT_FINI_ARRAY:
......
...@@ -91,6 +91,9 @@ CheckBool DisassemblerElf32X86::ParseRelocationSection( ...@@ -91,6 +91,9 @@ CheckBool DisassemblerElf32X86::ParseRelocationSection(
uint32 section_relocs_count = section_header->sh_size / uint32 section_relocs_count = section_header->sh_size /
section_header->sh_entsize; section_header->sh_entsize;
if (abs32_locations_.empty())
match = false;
if (abs32_locations_.size() > section_relocs_count) if (abs32_locations_.size() > section_relocs_count)
match = false; match = false;
......
...@@ -82,3 +82,8 @@ TEST_F(EncodeDecodeTest, Elf_Small) { ...@@ -82,3 +82,8 @@ TEST_F(EncodeDecodeTest, Elf_Small) {
std::string file = FileContents("elf-32-1"); std::string file = FileContents("elf-32-1");
TestAssembleToStreamDisassemble(file, 135988); TestAssembleToStreamDisassemble(file, 135988);
} }
TEST_F(EncodeDecodeTest, Elf_HighBSS) {
std::string file = FileContents("elf-32-high-bss");
TestAssembleToStreamDisassemble(file, 7308);
}
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