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 <mark@chromium.org>
This commit is contained in:
Adam Duke 2022-01-27 17:21:21 -05:00 committed by Mark Mentovai
parent 772cfc1db6
commit f6974b15ef
17 changed files with 34 additions and 11 deletions

View file

@ -49,8 +49,8 @@
namespace { namespace {
using google_breakpad::auto_wasteful_vector; using google_breakpad::auto_wasteful_vector;
using google_breakpad::elf::kDefaultBuildIdSize;
using google_breakpad::ExceptionHandler; using google_breakpad::ExceptionHandler;
using google_breakpad::kDefaultBuildIdSize;
using google_breakpad::LinuxDumper; using google_breakpad::LinuxDumper;
using google_breakpad::LinuxPtraceDumper; using google_breakpad::LinuxPtraceDumper;
using google_breakpad::MappingInfo; using google_breakpad::MappingInfo;

View file

@ -53,6 +53,8 @@
#include "google_breakpad/common/minidump_exception_linux.h" #include "google_breakpad/common/minidump_exception_linux.h"
#include "third_party/lss/linux_syscall_support.h" #include "third_party/lss/linux_syscall_support.h"
using google_breakpad::elf::FileID;
#if defined(__ANDROID__) #if defined(__ANDROID__)
// Android packed relocations definitions are not yet available from the // Android packed relocations definitions are not yet available from the

View file

@ -63,6 +63,8 @@
#endif #endif
using namespace google_breakpad; using namespace google_breakpad;
using google_breakpad::elf::FileID;
using google_breakpad::elf::kDefaultBuildIdSize;
namespace { namespace {

View file

@ -83,9 +83,9 @@ namespace {
using google_breakpad::AppMemoryList; using google_breakpad::AppMemoryList;
using google_breakpad::auto_wasteful_vector; using google_breakpad::auto_wasteful_vector;
using google_breakpad::elf::kDefaultBuildIdSize;
using google_breakpad::ExceptionHandler; using google_breakpad::ExceptionHandler;
using google_breakpad::CpuSet; using google_breakpad::CpuSet;
using google_breakpad::kDefaultBuildIdSize;
using google_breakpad::LineReader; using google_breakpad::LineReader;
using google_breakpad::LinuxDumper; using google_breakpad::LinuxDumper;
using google_breakpad::LinuxPtraceDumper; using google_breakpad::LinuxPtraceDumper;

View file

@ -54,6 +54,8 @@
#include "google_breakpad/processor/minidump.h" #include "google_breakpad/processor/minidump.h"
using namespace google_breakpad; using namespace google_breakpad;
using google_breakpad::elf::FileID;
using google_breakpad::elf::kDefaultBuildIdSize;
namespace { namespace {

View file

@ -62,6 +62,8 @@ using MacStringUtils::IntegerValueAtIndex;
namespace google_breakpad { namespace google_breakpad {
using mach_o::FileID;
#if defined(__LP64__) && __LP64__ #if defined(__LP64__) && __LP64__
#define LC_SEGMENT_ARCH LC_SEGMENT_64 #define LC_SEGMENT_ARCH LC_SEGMENT_64
#else #else

View file

@ -47,6 +47,7 @@
namespace { namespace {
using namespace google_breakpad; using namespace google_breakpad;
using namespace google_breakpad::elf::FileID;
// Argument for the writer function. // Argument for the writer function.
struct WriterArgument { struct WriterArgument {

View file

@ -87,11 +87,11 @@ using google_breakpad::DwarfRangeListHandler;
using google_breakpad::ElfClass; using google_breakpad::ElfClass;
using google_breakpad::ElfClass32; using google_breakpad::ElfClass32;
using google_breakpad::ElfClass64; using google_breakpad::ElfClass64;
using google_breakpad::FileID; using google_breakpad::elf::FileID;
using google_breakpad::FindElfSectionByName; using google_breakpad::FindElfSectionByName;
using google_breakpad::GetOffset; using google_breakpad::GetOffset;
using google_breakpad::IsValidElf; using google_breakpad::IsValidElf;
using google_breakpad::kDefaultBuildIdSize; using google_breakpad::elf::kDefaultBuildIdSize;
using google_breakpad::Module; using google_breakpad::Module;
using google_breakpad::PageAllocator; using google_breakpad::PageAllocator;
#ifndef NO_STABS_SUPPORT #ifndef NO_STABS_SUPPORT

View file

@ -49,6 +49,7 @@
#include "third_party/lss/linux_syscall_support.h" #include "third_party/lss/linux_syscall_support.h"
namespace google_breakpad { namespace google_breakpad {
namespace elf {
// Used in a few places for backwards-compatibility. // Used in a few places for backwards-compatibility.
const size_t kMDGUIDSize = sizeof(MDGUID); const size_t kMDGUIDSize = sizeof(MDGUID);
@ -198,4 +199,5 @@ string FileID::ConvertIdentifierToString(
return bytes_to_hex_string(&identifier[0], identifier.size()); return bytes_to_hex_string(&identifier[0], identifier.size());
} }
} // elf
} // namespace google_breakpad } // namespace google_breakpad

View file

@ -41,6 +41,7 @@
#include "common/using_std_string.h" #include "common/using_std_string.h"
namespace google_breakpad { namespace google_breakpad {
namespace elf {
// GNU binutils' ld defaults to 'sha1', which is 160 bits == 20 bytes, // GNU binutils' ld defaults to 'sha1', which is 160 bits == 20 bytes,
// so this is enough to fit that, which most binaries will use. // so this is enough to fit that, which most binaries will use.
@ -83,6 +84,7 @@ class FileID {
string path_; string path_;
}; };
} // namespace elf
} // namespace google_breakpad } // namespace google_breakpad
#endif // COMMON_LINUX_FILE_ID_H__ #endif // COMMON_LINUX_FILE_ID_H__

View file

@ -50,6 +50,8 @@
#include "breakpad_googletest_includes.h" #include "breakpad_googletest_includes.h"
using namespace google_breakpad; 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::ELF;
using google_breakpad::synth_elf::Notes; using google_breakpad::synth_elf::Notes;
using google_breakpad::test_assembler::kLittleEndian; using google_breakpad::test_assembler::kLittleEndian;

View file

@ -78,8 +78,8 @@ using google_breakpad::ByteReader;
using google_breakpad::DwarfCUToModule; using google_breakpad::DwarfCUToModule;
using google_breakpad::DwarfLineToModule; using google_breakpad::DwarfLineToModule;
using google_breakpad::DwarfRangeListHandler; using google_breakpad::DwarfRangeListHandler;
using google_breakpad::FileID;
using google_breakpad::mach_o::FatReader; using google_breakpad::mach_o::FatReader;
using google_breakpad::mach_o::FileID;
using google_breakpad::mach_o::Section; using google_breakpad::mach_o::Section;
using google_breakpad::mach_o::Segment; using google_breakpad::mach_o::Segment;
using google_breakpad::Module; using google_breakpad::Module;

View file

@ -45,7 +45,7 @@
using MacFileUtilities::MachoID; using MacFileUtilities::MachoID;
namespace google_breakpad { namespace google_breakpad {
namespace mach_o {
// Constructs a FileID given a path to a file // Constructs a FileID given a path to a file
FileID::FileID(const char* path) : memory_(nullptr), size_(0) { FileID::FileID(const char* path) : memory_(nullptr), size_(0) {
snprintf(path_, sizeof(path_), "%s", path); 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; buffer[(buffer_idx < buffer_length) ? buffer_idx : buffer_idx - 1] = 0;
} }
} // namespace mach_o
} // namespace google_breakpad } // namespace google_breakpad

View file

@ -39,6 +39,7 @@
#include <stddef.h> #include <stddef.h>
namespace google_breakpad { namespace google_breakpad {
namespace mach_o {
class FileID { class FileID {
public: public:
@ -85,6 +86,7 @@ class FileID {
size_t size_; size_t size_;
}; };
} // namespace mach_o
} // namespace google_breakpad } // namespace google_breakpad
#endif // COMMON_MAC_FILE_ID_H__ #endif // COMMON_MAC_FILE_ID_H__

View file

@ -492,7 +492,7 @@ bool WriteModuleInfo(int fd, GElf_Half arch, const std::string& obj_file) {
} }
unsigned char identifier[16]; 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)) { if (file_id.ElfFileIdentifier(identifier)) {
char identifier_str[40]; char identifier_str[40];
file_id.ConvertIdentifierToString(identifier, file_id.ConvertIdentifierToString(identifier,

View file

@ -128,10 +128,6 @@ static bool FindElfTextSection(int fd, const void* elf_base,
return false; return false;
} }
FileID::FileID(const char* path) {
strcpy(path_, path);
}
class AutoCloser { class AutoCloser {
public: public:
AutoCloser(int fd) : fd_(fd) {} AutoCloser(int fd) : fd_(fd) {}
@ -140,6 +136,12 @@ class AutoCloser {
int fd_; int fd_;
}; };
namespace elf {
FileID::FileID(const char* path) {
strcpy(path_, path);
}
bool FileID::ElfFileIdentifier(unsigned char identifier[16]) { bool FileID::ElfFileIdentifier(unsigned char identifier[16]) {
int fd = 0; int fd = 0;
if ((fd = open(path_, O_RDONLY)) < 0) if ((fd = open(path_, O_RDONLY)) < 0)
@ -194,4 +196,5 @@ bool FileID::ConvertIdentifierToString(const unsigned char identifier[16],
return true; return true;
} }
} // elf
} // namespace google_breakpad } // namespace google_breakpad

View file

@ -37,6 +37,7 @@
#include <limits.h> #include <limits.h>
namespace google_breakpad { namespace google_breakpad {
namespace elf {
class FileID { class FileID {
public: public:
@ -61,6 +62,7 @@ class FileID {
char path_[PATH_MAX]; char path_[PATH_MAX];
}; };
} // elf
} // namespace google_breakpad } // namespace google_breakpad
#endif // COMMON_SOLARIS_FILE_ID_H__ #endif // COMMON_SOLARIS_FILE_ID_H__