linux: add section header string table to test module

While ELF allows the section header string table to be missing,
it is required by Android API 26+.

Bug: chromium:1050178
Change-Id: I124e4356bda9c628f76944729a6c0c5e7a52561a
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2227129
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
Joshua Peraza 2020-06-02 12:20:44 -07:00 committed by Commit Bot
parent 686852d9d8
commit 86c28287d2

View File

@ -575,6 +575,8 @@ bool WriteTestModule(const base::FilePath& module_path) {
} hash_table;
struct {
} string_table;
struct {
} section_header_string_table;
struct {
Sym und_symbol;
} symbol_table;
@ -582,6 +584,7 @@ bool WriteTestModule(const base::FilePath& module_path) {
Shdr null;
Shdr dynamic;
Shdr string_table;
Shdr section_header_string_table;
} shdr_table;
} module = {};
@ -624,7 +627,9 @@ bool WriteTestModule(const base::FilePath& module_path) {
module.ehdr.e_shoff = offsetof(decltype(module), shdr_table);
module.ehdr.e_shentsize = sizeof(Shdr);
module.ehdr.e_shnum = sizeof(module.shdr_table) / sizeof(Shdr);
module.ehdr.e_shstrndx = SHN_UNDEF;
module.ehdr.e_shstrndx =
offsetof(decltype(module.shdr_table), section_header_string_table) /
sizeof(Shdr);
constexpr size_t load2_vaddr = 0x200000;
@ -690,6 +695,11 @@ bool WriteTestModule(const base::FilePath& module_path) {
module.shdr_table.string_table.sh_offset =
offsetof(decltype(module), string_table);
module.shdr_table.section_header_string_table.sh_name = 0;
module.shdr_table.section_header_string_table.sh_type = SHT_STRTAB;
module.shdr_table.section_header_string_table.sh_offset =
offsetof(decltype(module), section_header_string_table);
FileWriter writer;
if (!writer.Open(module_path,
FileWriteMode::kCreateOrFail,