From f6974b15ef96614e9a7df25c3ff31e350bd4e346 Mon Sep 17 00:00:00 2001 From: Adam Duke Date: Thu, 27 Jan 2022 17:21:21 -0500 Subject: [PATCH] namespace implementations of FileID In trying to create a backend service that can process both ELF and Mach-O binaries, I found that symbol collisions occur when trying to link different implementations of FileID. This change puts the different implementations into separate namespaces to avoid the collision. Change-Id: I15aabb222803f2ffbda15ed13e66793bae32ddce Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/3421417 Reviewed-by: Mark Mentovai --- src/client/linux/microdump_writer/microdump_writer.cc | 2 +- src/client/linux/minidump_writer/linux_dumper.cc | 2 ++ .../minidump_writer/linux_ptrace_dumper_unittest.cc | 2 ++ src/client/linux/minidump_writer/minidump_writer.cc | 2 +- .../linux/minidump_writer/minidump_writer_unittest.cc | 2 ++ src/client/mac/handler/minidump_generator.cc | 2 ++ src/client/solaris/handler/minidump_generator.cc | 1 + src/common/linux/dump_symbols.cc | 4 ++-- src/common/linux/file_id.cc | 2 ++ src/common/linux/file_id.h | 2 ++ src/common/linux/file_id_unittest.cc | 2 ++ src/common/mac/dump_syms.cc | 2 +- src/common/mac/file_id.cc | 3 ++- src/common/mac/file_id.h | 2 ++ src/common/solaris/dump_symbols.cc | 2 +- src/common/solaris/file_id.cc | 11 +++++++---- src/common/solaris/file_id.h | 2 ++ 17 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/client/linux/microdump_writer/microdump_writer.cc b/src/client/linux/microdump_writer/microdump_writer.cc index fa3c1713..22edb1b8 100644 --- a/src/client/linux/microdump_writer/microdump_writer.cc +++ b/src/client/linux/microdump_writer/microdump_writer.cc @@ -49,8 +49,8 @@ namespace { using google_breakpad::auto_wasteful_vector; +using google_breakpad::elf::kDefaultBuildIdSize; using google_breakpad::ExceptionHandler; -using google_breakpad::kDefaultBuildIdSize; using google_breakpad::LinuxDumper; using google_breakpad::LinuxPtraceDumper; using google_breakpad::MappingInfo; diff --git a/src/client/linux/minidump_writer/linux_dumper.cc b/src/client/linux/minidump_writer/linux_dumper.cc index 7fd6532a..44430c4e 100644 --- a/src/client/linux/minidump_writer/linux_dumper.cc +++ b/src/client/linux/minidump_writer/linux_dumper.cc @@ -53,6 +53,8 @@ #include "google_breakpad/common/minidump_exception_linux.h" #include "third_party/lss/linux_syscall_support.h" +using google_breakpad::elf::FileID; + #if defined(__ANDROID__) // Android packed relocations definitions are not yet available from the diff --git a/src/client/linux/minidump_writer/linux_ptrace_dumper_unittest.cc b/src/client/linux/minidump_writer/linux_ptrace_dumper_unittest.cc index da71e15d..11c392d8 100644 --- a/src/client/linux/minidump_writer/linux_ptrace_dumper_unittest.cc +++ b/src/client/linux/minidump_writer/linux_ptrace_dumper_unittest.cc @@ -63,6 +63,8 @@ #endif using namespace google_breakpad; +using google_breakpad::elf::FileID; +using google_breakpad::elf::kDefaultBuildIdSize; namespace { diff --git a/src/client/linux/minidump_writer/minidump_writer.cc b/src/client/linux/minidump_writer/minidump_writer.cc index 32634ef0..72a92166 100644 --- a/src/client/linux/minidump_writer/minidump_writer.cc +++ b/src/client/linux/minidump_writer/minidump_writer.cc @@ -83,9 +83,9 @@ namespace { using google_breakpad::AppMemoryList; using google_breakpad::auto_wasteful_vector; +using google_breakpad::elf::kDefaultBuildIdSize; using google_breakpad::ExceptionHandler; using google_breakpad::CpuSet; -using google_breakpad::kDefaultBuildIdSize; using google_breakpad::LineReader; using google_breakpad::LinuxDumper; using google_breakpad::LinuxPtraceDumper; diff --git a/src/client/linux/minidump_writer/minidump_writer_unittest.cc b/src/client/linux/minidump_writer/minidump_writer_unittest.cc index d192e5cb..b7a2c61e 100644 --- a/src/client/linux/minidump_writer/minidump_writer_unittest.cc +++ b/src/client/linux/minidump_writer/minidump_writer_unittest.cc @@ -54,6 +54,8 @@ #include "google_breakpad/processor/minidump.h" using namespace google_breakpad; +using google_breakpad::elf::FileID; +using google_breakpad::elf::kDefaultBuildIdSize; namespace { diff --git a/src/client/mac/handler/minidump_generator.cc b/src/client/mac/handler/minidump_generator.cc index d6b0561d..05d91b08 100644 --- a/src/client/mac/handler/minidump_generator.cc +++ b/src/client/mac/handler/minidump_generator.cc @@ -62,6 +62,8 @@ using MacStringUtils::IntegerValueAtIndex; namespace google_breakpad { +using mach_o::FileID; + #if defined(__LP64__) && __LP64__ #define LC_SEGMENT_ARCH LC_SEGMENT_64 #else diff --git a/src/client/solaris/handler/minidump_generator.cc b/src/client/solaris/handler/minidump_generator.cc index 56756665..81a53587 100644 --- a/src/client/solaris/handler/minidump_generator.cc +++ b/src/client/solaris/handler/minidump_generator.cc @@ -47,6 +47,7 @@ namespace { using namespace google_breakpad; +using namespace google_breakpad::elf::FileID; // Argument for the writer function. struct WriterArgument { diff --git a/src/common/linux/dump_symbols.cc b/src/common/linux/dump_symbols.cc index ac53ea28..75a4ceed 100644 --- a/src/common/linux/dump_symbols.cc +++ b/src/common/linux/dump_symbols.cc @@ -87,11 +87,11 @@ using google_breakpad::DwarfRangeListHandler; using google_breakpad::ElfClass; using google_breakpad::ElfClass32; using google_breakpad::ElfClass64; -using google_breakpad::FileID; +using google_breakpad::elf::FileID; using google_breakpad::FindElfSectionByName; using google_breakpad::GetOffset; using google_breakpad::IsValidElf; -using google_breakpad::kDefaultBuildIdSize; +using google_breakpad::elf::kDefaultBuildIdSize; using google_breakpad::Module; using google_breakpad::PageAllocator; #ifndef NO_STABS_SUPPORT diff --git a/src/common/linux/file_id.cc b/src/common/linux/file_id.cc index 9944af7a..b483eb5c 100644 --- a/src/common/linux/file_id.cc +++ b/src/common/linux/file_id.cc @@ -49,6 +49,7 @@ #include "third_party/lss/linux_syscall_support.h" namespace google_breakpad { +namespace elf { // Used in a few places for backwards-compatibility. const size_t kMDGUIDSize = sizeof(MDGUID); @@ -198,4 +199,5 @@ string FileID::ConvertIdentifierToString( return bytes_to_hex_string(&identifier[0], identifier.size()); } +} // elf } // namespace google_breakpad diff --git a/src/common/linux/file_id.h b/src/common/linux/file_id.h index 4aff021d..8556a2e5 100644 --- a/src/common/linux/file_id.h +++ b/src/common/linux/file_id.h @@ -41,6 +41,7 @@ #include "common/using_std_string.h" namespace google_breakpad { +namespace elf { // GNU binutils' ld defaults to 'sha1', which is 160 bits == 20 bytes, // so this is enough to fit that, which most binaries will use. @@ -83,6 +84,7 @@ class FileID { string path_; }; +} // namespace elf } // namespace google_breakpad #endif // COMMON_LINUX_FILE_ID_H__ diff --git a/src/common/linux/file_id_unittest.cc b/src/common/linux/file_id_unittest.cc index 8225e5ac..43c9af7b 100644 --- a/src/common/linux/file_id_unittest.cc +++ b/src/common/linux/file_id_unittest.cc @@ -50,6 +50,8 @@ #include "breakpad_googletest_includes.h" using namespace google_breakpad; +using google_breakpad::elf::FileID; +using google_breakpad::elf::kDefaultBuildIdSize; using google_breakpad::synth_elf::ELF; using google_breakpad::synth_elf::Notes; using google_breakpad::test_assembler::kLittleEndian; diff --git a/src/common/mac/dump_syms.cc b/src/common/mac/dump_syms.cc index bd69218d..b1cb1a30 100644 --- a/src/common/mac/dump_syms.cc +++ b/src/common/mac/dump_syms.cc @@ -78,8 +78,8 @@ using google_breakpad::ByteReader; using google_breakpad::DwarfCUToModule; using google_breakpad::DwarfLineToModule; using google_breakpad::DwarfRangeListHandler; -using google_breakpad::FileID; using google_breakpad::mach_o::FatReader; +using google_breakpad::mach_o::FileID; using google_breakpad::mach_o::Section; using google_breakpad::mach_o::Segment; using google_breakpad::Module; diff --git a/src/common/mac/file_id.cc b/src/common/mac/file_id.cc index 504e8202..9ed65e5c 100644 --- a/src/common/mac/file_id.cc +++ b/src/common/mac/file_id.cc @@ -45,7 +45,7 @@ using MacFileUtilities::MachoID; namespace google_breakpad { - +namespace mach_o { // Constructs a FileID given a path to a file FileID::FileID(const char* path) : memory_(nullptr), size_(0) { snprintf(path_, sizeof(path_), "%s", path); @@ -91,4 +91,5 @@ void FileID::ConvertIdentifierToString(const unsigned char identifier[16], buffer[(buffer_idx < buffer_length) ? buffer_idx : buffer_idx - 1] = 0; } +} // namespace mach_o } // namespace google_breakpad diff --git a/src/common/mac/file_id.h b/src/common/mac/file_id.h index 430d41d5..fc1821e7 100644 --- a/src/common/mac/file_id.h +++ b/src/common/mac/file_id.h @@ -39,6 +39,7 @@ #include namespace google_breakpad { +namespace mach_o { class FileID { public: @@ -85,6 +86,7 @@ class FileID { size_t size_; }; +} // namespace mach_o } // namespace google_breakpad #endif // COMMON_MAC_FILE_ID_H__ diff --git a/src/common/solaris/dump_symbols.cc b/src/common/solaris/dump_symbols.cc index 9524a18b..93aeed24 100644 --- a/src/common/solaris/dump_symbols.cc +++ b/src/common/solaris/dump_symbols.cc @@ -492,7 +492,7 @@ bool WriteModuleInfo(int fd, GElf_Half arch, const std::string& obj_file) { } unsigned char identifier[16]; - google_breakpad::FileID file_id(obj_file.c_str()); + google_breakpad::elf::FileID file_id(obj_file.c_str()); if (file_id.ElfFileIdentifier(identifier)) { char identifier_str[40]; file_id.ConvertIdentifierToString(identifier, diff --git a/src/common/solaris/file_id.cc b/src/common/solaris/file_id.cc index c32c73bb..837793c8 100644 --- a/src/common/solaris/file_id.cc +++ b/src/common/solaris/file_id.cc @@ -128,10 +128,6 @@ static bool FindElfTextSection(int fd, const void* elf_base, return false; } -FileID::FileID(const char* path) { - strcpy(path_, path); -} - class AutoCloser { public: AutoCloser(int fd) : fd_(fd) {} @@ -140,6 +136,12 @@ class AutoCloser { int fd_; }; +namespace elf { + +FileID::FileID(const char* path) { + strcpy(path_, path); +} + bool FileID::ElfFileIdentifier(unsigned char identifier[16]) { int fd = 0; if ((fd = open(path_, O_RDONLY)) < 0) @@ -194,4 +196,5 @@ bool FileID::ConvertIdentifierToString(const unsigned char identifier[16], return true; } +} // elf } // namespace google_breakpad diff --git a/src/common/solaris/file_id.h b/src/common/solaris/file_id.h index 375e8575..cacf17a9 100644 --- a/src/common/solaris/file_id.h +++ b/src/common/solaris/file_id.h @@ -37,6 +37,7 @@ #include namespace google_breakpad { +namespace elf { class FileID { public: @@ -61,6 +62,7 @@ class FileID { char path_[PATH_MAX]; }; +} // elf } // namespace google_breakpad #endif // COMMON_SOLARIS_FILE_ID_H__