From 1f1ce2b31724736a7114d466a40d6ee18d17c2b9 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 14 Jul 2026 15:00:00 +0200 Subject: [PATCH 01/11] Add stab.h from Debian Trixie libc6-dev 2.41-12+deb13u3 --- src/third_party/stab/include/bits/stab.def | 233 +++++++++++++++++++++ src/third_party/stab/include/stab.h | 17 ++ 2 files changed, 250 insertions(+) create mode 100644 src/third_party/stab/include/bits/stab.def create mode 100644 src/third_party/stab/include/stab.h diff --git a/src/third_party/stab/include/bits/stab.def b/src/third_party/stab/include/bits/stab.def new file mode 100644 index 00000000..e7a61d98 --- /dev/null +++ b/src/third_party/stab/include/bits/stab.def @@ -0,0 +1,233 @@ +/* Table of DBX symbol codes for the GNU system. + Copyright (C) 1988, 1997-2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* This contains contribution from Cygnus Support. */ + +/* Global variable. Only the name is significant. + To find the address, look in the corresponding external symbol. */ +__define_stab (N_GSYM, 0x20, "GSYM") + +/* Function name for BSD Fortran. Only the name is significant. + To find the address, look in the corresponding external symbol. */ +__define_stab (N_FNAME, 0x22, "FNAME") + +/* Function name or text-segment variable for C. Value is its address. + Desc is supposedly starting line number, but GCC doesn't set it + and DBX seems not to miss it. */ +__define_stab (N_FUN, 0x24, "FUN") + +/* Data-segment variable with internal linkage. Value is its address. + "Static Sym". */ +__define_stab (N_STSYM, 0x26, "STSYM") + +/* BSS-segment variable with internal linkage. Value is its address. */ +__define_stab (N_LCSYM, 0x28, "LCSYM") + +/* Name of main routine. Only the name is significant. + This is not used in C. */ +__define_stab (N_MAIN, 0x2a, "MAIN") + +/* Global symbol in Pascal. + Supposedly the value is its line number; I'm skeptical. */ +__define_stab (N_PC, 0x30, "PC") + +/* Number of symbols: 0, files,,funcs,lines according to Ultrix V4.0. */ +__define_stab (N_NSYMS, 0x32, "NSYMS") + +/* "No DST map for sym: name, ,0,type,ignored" according to Ultrix V4.0. */ +__define_stab (N_NOMAP, 0x34, "NOMAP") + +/* New stab from Solaris. I don't know what it means, but it + don't seem to contain useful information. */ +__define_stab (N_OBJ, 0x38, "OBJ") + +/* New stab from Solaris. I don't know what it means, but it + don't seem to contain useful information. Possibly related to the + optimization flags used in this module. */ +__define_stab (N_OPT, 0x3c, "OPT") + +/* Register variable. Value is number of register. */ +__define_stab (N_RSYM, 0x40, "RSYM") + +/* Modula-2 compilation unit. Can someone say what info it contains? */ +__define_stab (N_M2C, 0x42, "M2C") + +/* Line number in text segment. Desc is the line number; + value is corresponding address. */ +__define_stab (N_SLINE, 0x44, "SLINE") + +/* Similar, for data segment. */ +__define_stab (N_DSLINE, 0x46, "DSLINE") + +/* Similar, for bss segment. */ +__define_stab (N_BSLINE, 0x48, "BSLINE") + +/* Sun's source-code browser stabs. ?? Don't know what the fields are. + Supposedly the field is "path to associated .cb file". THIS VALUE + OVERLAPS WITH N_BSLINE! */ +__define_stab (N_BROWS, 0x48, "BROWS") + +/* GNU Modula-2 definition module dependency. Value is the modification time + of the definition file. Other is non-zero if it is imported with the + GNU M2 keyword %INITIALIZE. Perhaps N_M2C can be used if there + are enough empty fields? */ +__define_stab(N_DEFD, 0x4a, "DEFD") + +/* THE FOLLOWING TWO STAB VALUES CONFLICT. Happily, one is for Modula-2 + and one is for C++. Still,... */ +/* GNU C++ exception variable. Name is variable name. */ +__define_stab (N_EHDECL, 0x50, "EHDECL") +/* Modula2 info "for imc": name,,0,0,0 according to Ultrix V4.0. */ +__define_stab (N_MOD2, 0x50, "MOD2") + +/* GNU C++ `catch' clause. Value is its address. Desc is nonzero if + this entry is immediately followed by a CAUGHT stab saying what exception + was caught. Multiple CAUGHT stabs means that multiple exceptions + can be caught here. If Desc is 0, it means all exceptions are caught + here. */ +__define_stab (N_CATCH, 0x54, "CATCH") + +/* Structure or union element. Value is offset in the structure. */ +__define_stab (N_SSYM, 0x60, "SSYM") + +/* Name of main source file. + Value is starting text address of the compilation. */ +__define_stab (N_SO, 0x64, "SO") + +/* Automatic variable in the stack. Value is offset from frame pointer. + Also used for type descriptions. */ +__define_stab (N_LSYM, 0x80, "LSYM") + +/* Beginning of an include file. Only Sun uses this. + In an object file, only the name is significant. + The Sun linker puts data into some of the other fields. */ +__define_stab (N_BINCL, 0x82, "BINCL") + +/* Name of sub-source file (#include file). + Value is starting text address of the compilation. */ +__define_stab (N_SOL, 0x84, "SOL") + +/* Parameter variable. Value is offset from argument pointer. + (On most machines the argument pointer is the same as the frame pointer. */ +__define_stab (N_PSYM, 0xa0, "PSYM") + +/* End of an include file. No name. + This and N_BINCL act as brackets around the file's output. + In an object file, there is no significant data in this entry. + The Sun linker puts data into some of the fields. */ +__define_stab (N_EINCL, 0xa2, "EINCL") + +/* Alternate entry point. Value is its address. */ +__define_stab (N_ENTRY, 0xa4, "ENTRY") + +/* Beginning of lexical block. + The desc is the nesting level in lexical blocks. + The value is the address of the start of the text for the block. + The variables declared inside the block *precede* the N_LBRAC symbol. */ +__define_stab (N_LBRAC, 0xc0, "LBRAC") + +/* Place holder for deleted include file. Replaces a N_BINCL and everything + up to the corresponding N_EINCL. The Sun linker generates these when + it finds multiple identical copies of the symbols from an include file. + This appears only in output from the Sun linker. */ +__define_stab (N_EXCL, 0xc2, "EXCL") + +/* Modula-2 scope information. Can someone say what info it contains? */ +__define_stab (N_SCOPE, 0xc4, "SCOPE") + +/* End of a lexical block. Desc matches the N_LBRAC's desc. + The value is the address of the end of the text for the block. */ +__define_stab (N_RBRAC, 0xe0, "RBRAC") + +/* Begin named common block. Only the name is significant. */ +__define_stab (N_BCOMM, 0xe2, "BCOMM") + +/* End named common block. Only the name is significant + (and it should match the N_BCOMM). */ +__define_stab (N_ECOMM, 0xe4, "ECOMM") + +/* End common (local name): value is address. + I'm not sure how this is used. */ +__define_stab (N_ECOML, 0xe8, "ECOML") + +/* These STAB's are used on Gould systems for Non-Base register symbols + or something like that. FIXME. I have assigned the values at random + since I don't have a Gould here. Fixups from Gould folk welcome... */ +__define_stab (N_NBTEXT, 0xF0, "NBTEXT") +__define_stab (N_NBDATA, 0xF2, "NBDATA") +__define_stab (N_NBBSS, 0xF4, "NBBSS") +__define_stab (N_NBSTS, 0xF6, "NBSTS") +__define_stab (N_NBLCS, 0xF8, "NBLCS") + +/* Second symbol entry containing a length-value for the preceding entry. + The value is the length. */ +__define_stab (N_LENG, 0xfe, "LENG") + +/* The above information, in matrix format. + + STAB MATRIX + _________________________________________________ + | 00 - 1F are not dbx stab symbols | + | In most cases, the low bit is the EXTernal bit| + + | 00 UNDEF | 02 ABS | 04 TEXT | 06 DATA | + | 01 |EXT | 03 |EXT | 05 |EXT | 07 |EXT | + + | 08 BSS | 0A INDR | 0C FN_SEQ | 0E | + | 09 |EXT | 0B | 0D | 0F | + + | 10 | 12 COMM | 14 SETA | 16 SETT | + | 11 | 13 | 15 | 17 | + + | 18 SETD | 1A SETB | 1C SETV | 1E WARNING| + | 19 | 1B | 1D | 1F FN | + + |_______________________________________________| + | Debug entries with bit 01 set are unused. | + | 20 GSYM | 22 FNAME | 24 FUN | 26 STSYM | + | 28 LCSYM | 2A MAIN | 2C | 2E | + | 30 PC | 32 NSYMS | 34 NOMAP | 36 | + | 38 OBJ | 3A | 3C OPT | 3E | + | 40 RSYM | 42 M2C | 44 SLINE | 46 DSLINE | + | 48 BSLINE*| 4A DEFD | 4C | 4E | + | 50 EHDECL*| 52 | 54 CATCH | 56 | + | 58 | 5A | 5C | 5E | + | 60 SSYM | 62 | 64 SO | 66 | + | 68 | 6A | 6C | 6E | + | 70 | 72 | 74 | 76 | + | 78 | 7A | 7C | 7E | + | 80 LSYM | 82 BINCL | 84 SOL | 86 | + | 88 | 8A | 8C | 8E | + | 90 | 92 | 94 | 96 | + | 98 | 9A | 9C | 9E | + | A0 PSYM | A2 EINCL | A4 ENTRY | A6 | + | A8 | AA | AC | AE | + | B0 | B2 | B4 | B6 | + | B8 | BA | BC | BE | + | C0 LBRAC | C2 EXCL | C4 SCOPE | C6 | + | C8 | CA | CC | CE | + | D0 | D2 | D4 | D6 | + | D8 | DA | DC | DE | + | E0 RBRAC | E2 BCOMM | E4 ECOMM | E6 | + | E8 ECOML | EA | EC | EE | + | F0 | F2 | F4 | F6 | + | F8 | FA | FC | FE LENG | + +-----------------------------------------------+ + * 50 EHDECL is also MOD2. + * 48 BSLINE is also BROWS. + */ diff --git a/src/third_party/stab/include/stab.h b/src/third_party/stab/include/stab.h new file mode 100644 index 00000000..9dc3c32e --- /dev/null +++ b/src/third_party/stab/include/stab.h @@ -0,0 +1,17 @@ +#ifndef __GNU_STAB__ + +/* Indicate the GNU stab.h is in use. */ + +#define __GNU_STAB__ + +#define __define_stab(NAME, CODE, STRING) NAME=CODE, + +enum __stab_debug_code +{ +#include +LAST_UNUSED_STAB_CODE +}; + +#undef __define_stab + +#endif /* __GNU_STAB_ */ From ea41ecc549a7e9f1b5e1de0f88eeadf559236c6b Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 14 Jul 2026 15:01:00 +0200 Subject: [PATCH 02/11] Add compat/elf.h --- src/common/dwarf/elf_reader.cc | 3 ++- src/common/linux/dump_symbols.cc | 3 ++- src/common/linux/elf_gnu_compat.h | 2 +- src/common/linux/elf_symbols_to_module.cc | 3 ++- src/common/linux/elfutils.h | 3 ++- src/compat/elf.h | 10 ++++++++++ 6 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 src/compat/elf.h diff --git a/src/common/dwarf/elf_reader.cc b/src/common/dwarf/elf_reader.cc index bbfdba68..a9596f0a 100644 --- a/src/common/dwarf/elf_reader.cc +++ b/src/common/dwarf/elf_reader.cc @@ -30,6 +30,8 @@ #define _GNU_SOURCE // needed for pread() #endif +#include "compat/elf.h" + #include #include #include @@ -46,7 +48,6 @@ // Also need to add configure tests for zlib. //#include "zlib.h" -#include "third_party/musl/include/elf.h" #include "elf_reader.h" #include "common/using_std_string.h" diff --git a/src/common/linux/dump_symbols.cc b/src/common/linux/dump_symbols.cc index 0514f5a2..126c1980 100644 --- a/src/common/linux/dump_symbols.cc +++ b/src/common/linux/dump_symbols.cc @@ -32,10 +32,11 @@ // dump_symbols.cc: implement google_breakpad::WriteSymbolFile: // Find all the debugging info in a file and dump it as a Breakpad symbol file. +#include "compat/elf.h" + #include "common/linux/dump_symbols.h" #include -#include #include #include #include diff --git a/src/common/linux/elf_gnu_compat.h b/src/common/linux/elf_gnu_compat.h index 0a3dfedb..5d5e3701 100644 --- a/src/common/linux/elf_gnu_compat.h +++ b/src/common/linux/elf_gnu_compat.h @@ -36,7 +36,7 @@ #ifndef COMMON_LINUX_ELF_GNU_COMPAT_H_ #define COMMON_LINUX_ELF_GNU_COMPAT_H_ -#include +#include "compat/elf.h" // A note type on GNU systems corresponding to the .note.gnu.build-id section. #ifndef NT_GNU_BUILD_ID diff --git a/src/common/linux/elf_symbols_to_module.cc b/src/common/linux/elf_symbols_to_module.cc index 81e985a7..3a7b7489 100644 --- a/src/common/linux/elf_symbols_to_module.cc +++ b/src/common/linux/elf_symbols_to_module.cc @@ -30,10 +30,11 @@ // Original author: Ted Mielczarek +#include "compat/elf.h" + #include "common/linux/elf_symbols_to_module.h" #include -#include #include #include "common/byte_cursor.h" diff --git a/src/common/linux/elfutils.h b/src/common/linux/elfutils.h index ec5872a4..0a49c772 100644 --- a/src/common/linux/elfutils.h +++ b/src/common/linux/elfutils.h @@ -33,7 +33,8 @@ #ifndef COMMON_LINUX_ELFUTILS_H_ #define COMMON_LINUX_ELFUTILS_H_ -#include +#include "compat/elf.h" + #include #include diff --git a/src/compat/elf.h b/src/compat/elf.h new file mode 100644 index 00000000..3031fe99 --- /dev/null +++ b/src/compat/elf.h @@ -0,0 +1,10 @@ +#ifndef SRC_COMPAT_ELF_H_ +#define SRC_COMPAT_ELF_H_ + +#if !defined(_WIN32) && !defined(__APPLE__) +#include +#else +#include "third_party/musl/include/elf.h" +#endif + +#endif // SRC_COMPAT_ELF_H_ From 6f5fdb5967b40b3e4551d730332984a1e89118d2 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 14 Jul 2026 15:02:00 +0200 Subject: [PATCH 03/11] Add compat/mman.h --- src/common/dwarf/elf_reader.cc | 2 +- src/common/linux/dump_symbols.cc | 2 +- src/common/linux/memory_mapped_file.cc | 3 +- src/common/memory_allocator.h | 9 +- src/compat/mman.h | 124 +++++++++++++++++++++++++ 5 files changed, 131 insertions(+), 9 deletions(-) create mode 100644 src/compat/mman.h diff --git a/src/common/dwarf/elf_reader.cc b/src/common/dwarf/elf_reader.cc index a9596f0a..be67da73 100644 --- a/src/common/dwarf/elf_reader.cc +++ b/src/common/dwarf/elf_reader.cc @@ -31,11 +31,11 @@ #endif #include "compat/elf.h" +#include "compat/mman.h" #include #include #include -#include #include #include #include diff --git a/src/common/linux/dump_symbols.cc b/src/common/linux/dump_symbols.cc index 126c1980..5cfa10d0 100644 --- a/src/common/linux/dump_symbols.cc +++ b/src/common/linux/dump_symbols.cc @@ -33,6 +33,7 @@ // Find all the debugging info in a file and dump it as a Breakpad symbol file. #include "compat/elf.h" +#include "compat/mman.h" #include "common/linux/dump_symbols.h" @@ -45,7 +46,6 @@ #include #include #include -#include #include #include diff --git a/src/common/linux/memory_mapped_file.cc b/src/common/linux/memory_mapped_file.cc index 99362945..57cf1ac6 100644 --- a/src/common/linux/memory_mapped_file.cc +++ b/src/common/linux/memory_mapped_file.cc @@ -30,10 +30,11 @@ // memory_mapped_file.cc: Implement google_breakpad::MemoryMappedFile. // See memory_mapped_file.h for details. +#include "compat/mman.h" + #include "common/linux/memory_mapped_file.h" #include -#include #if defined(__ANDROID__) #include #endif diff --git a/src/common/memory_allocator.h b/src/common/memory_allocator.h index 69055a15..3caa38d6 100644 --- a/src/common/memory_allocator.h +++ b/src/common/memory_allocator.h @@ -30,10 +30,11 @@ #ifndef GOOGLE_BREAKPAD_COMMON_MEMORY_ALLOCATOR_H_ #define GOOGLE_BREAKPAD_COMMON_MEMORY_ALLOCATOR_H_ +#include "compat/mman.h" + #include #include #include -#include #include #include @@ -42,11 +43,7 @@ #include #endif -#ifdef __APPLE__ -#define sys_mmap mmap -#define sys_munmap munmap -#define MAP_ANONYMOUS MAP_ANON -#else +#ifndef __APPLE__ #include "third_party/lss/linux_syscall_support.h" #endif diff --git a/src/compat/mman.h b/src/compat/mman.h new file mode 100644 index 00000000..ab2663d2 --- /dev/null +++ b/src/compat/mman.h @@ -0,0 +1,124 @@ +#ifndef SRC_COMPAT_MMAN_H_ +#define SRC_COMPAT_MMAN_H_ + +#if !defined(_WIN32) +#include +#endif + +#if defined(_WIN32) +#ifndef MAP_SHARED +#define MAP_SHARED 0x01 +#endif + +#ifndef MAP_PRIVATE +#define MAP_PRIVATE 0x02 +#endif + +#ifndef MAP_FAILED +#define MAP_FAILED ((void*)-1) +#endif + +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS 0x20 +#endif + +#ifndef MAP_ANON +#define MAP_ANON MAP_ANONYMOUS +#endif +#endif + +#if defined(__APPLE__) +#ifndef MAP_ANONYOUS +#define MAP_ANONYMOUS MAP_ANON +#endif +#endif + +#if defined(_WIN32) +#ifndef PROT_READ +#define PROT_READ 0x1 +#endif + +#ifndef PROT_WRITE +#define PROT_WRITE 0x2 +#endif + +static inline void* mmap(void* /*addr*/, + size_t length, + int prot, + int flags, + int fd, + breakpad_off_t offset) { + if (length == 0) { + return MAP_FAILED; + } + + if (fd == -1) { + void* result = VirtualAlloc(nullptr, length, MEM_RESERVE | MEM_COMMIT, + (prot & PROT_WRITE) ? PAGE_READWRITE : PAGE_READONLY); + + if (result) { + return result; + } + + return MAP_FAILED; + } + + HANDLE file = (HANDLE)_get_osfhandle(fd); + if (file == INVALID_HANDLE_VALUE) { + return MAP_FAILED; + } + + DWORD protect; + DWORD access; + + if (prot & PROT_WRITE) { + if (flags & MAP_PRIVATE) { + protect = PAGE_WRITECOPY; + access = FILE_MAP_COPY; + } else { + protect = PAGE_READWRITE; + access = FILE_MAP_WRITE; + } + } else { + protect = PAGE_READONLY; + access = FILE_MAP_READ; + } + + HANDLE mapping = CreateFileMapping(file, NULL, protect, 0, 0, NULL); + + if (!mapping) { + return MAP_FAILED; + } + + DWORD offset_high = static_cast((offset >> 32) & 0xffffffff); + DWORD offset_low = static_cast(offset & 0xffffffff); + + void* result = MapViewOfFile(mapping, access, offset_high, offset_low, length); + + CloseHandle(mapping); + + if (!result) { + return MAP_FAILED; + } + + return result; +} + +static inline int munmap(void* addr, + size_t /*length*/) { + if (VirtualFree(addr, 0, MEM_RELEASE)) { + return 0; + } + + if (UnmapViewOfFile(addr)) { + return 0; + } + + return -1; +} + +#define sys_mmap mmap +#define sys_munmap munmap +#endif + +#endif // SRC_COMPAT_MMAN_H_ From cb101c605e50ab07b928fa1518db981674b2f1a8 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 14 Jul 2026 15:03:00 +0200 Subject: [PATCH 04/11] Add compat/link.h --- src/common/linux/dump_symbols.cc | 2 +- src/common/linux/elfutils.h | 2 +- src/compat/link.h | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/compat/link.h diff --git a/src/common/linux/dump_symbols.cc b/src/common/linux/dump_symbols.cc index 5cfa10d0..ee9cfa4b 100644 --- a/src/common/linux/dump_symbols.cc +++ b/src/common/linux/dump_symbols.cc @@ -33,6 +33,7 @@ // Find all the debugging info in a file and dump it as a Breakpad symbol file. #include "compat/elf.h" +#include "compat/link.h" #include "compat/mman.h" #include "common/linux/dump_symbols.h" @@ -41,7 +42,6 @@ #include #include #include -#include #include #include #include diff --git a/src/common/linux/elfutils.h b/src/common/linux/elfutils.h index 0a49c772..278b8d9c 100644 --- a/src/common/linux/elfutils.h +++ b/src/common/linux/elfutils.h @@ -34,8 +34,8 @@ #define COMMON_LINUX_ELFUTILS_H_ #include "compat/elf.h" +#include "compat/link.h" -#include #include #include "common/memory_allocator.h" diff --git a/src/compat/link.h b/src/compat/link.h new file mode 100644 index 00000000..fd11457c --- /dev/null +++ b/src/compat/link.h @@ -0,0 +1,16 @@ +#ifndef SRC_COMPAT_LINK_H_ +#define SRC_COMPAT_LINK_H_ + +#if defined(__linux__) || defined(__FreeBSD__) +#include + +#else +#include +#if INTPTR_MAX == INT64_MAX +#define ElfW(type) Elf64_##type +#else +#define ElfW(type) Elf32_##type +#endif +#endif + +#endif // SRC_COMPAT_LINK_H_ From deae767d11c1a1607be317d819fdb4b3d1103af4 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 14 Jul 2026 15:04:00 +0200 Subject: [PATCH 05/11] Add compat/syscall.h --- src/common/linux/memory_mapped_file.cc | 1 + src/common/linux/safe_readlink.cc | 4 +-- src/common/memory_allocator.h | 5 +-- src/compat/syscall.h | 48 ++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 src/compat/syscall.h diff --git a/src/common/linux/memory_mapped_file.cc b/src/common/linux/memory_mapped_file.cc index 57cf1ac6..4124dd7e 100644 --- a/src/common/linux/memory_mapped_file.cc +++ b/src/common/linux/memory_mapped_file.cc @@ -31,6 +31,7 @@ // See memory_mapped_file.h for details. #include "compat/mman.h" +#include "compat/syscall.h" #include "common/linux/memory_mapped_file.h" diff --git a/src/common/linux/safe_readlink.cc b/src/common/linux/safe_readlink.cc index 870c28af..c2b26465 100644 --- a/src/common/linux/safe_readlink.cc +++ b/src/common/linux/safe_readlink.cc @@ -30,9 +30,9 @@ // safe_readlink.cc: Implement google_breakpad::SafeReadLink. // See safe_readlink.h for details. -#include +#include "compat/syscall.h" -#include "third_party/lss/linux_syscall_support.h" +#include namespace google_breakpad { diff --git a/src/common/memory_allocator.h b/src/common/memory_allocator.h index 3caa38d6..8398240e 100644 --- a/src/common/memory_allocator.h +++ b/src/common/memory_allocator.h @@ -31,6 +31,7 @@ #define GOOGLE_BREAKPAD_COMMON_MEMORY_ALLOCATOR_H_ #include "compat/mman.h" +#include "compat/syscall.h" #include #include @@ -43,10 +44,6 @@ #include #endif -#ifndef __APPLE__ -#include "third_party/lss/linux_syscall_support.h" -#endif - namespace google_breakpad { // This is very simple allocator which fetches pages from the kernel directly. diff --git a/src/compat/syscall.h b/src/compat/syscall.h new file mode 100644 index 00000000..5fad6d05 --- /dev/null +++ b/src/compat/syscall.h @@ -0,0 +1,48 @@ +#ifndef SRC_COMPAT_SYSCALL_H_ +#define SRC_COMPAT_SYSCALL_H_ + +#if defined(__linux__) +#include "third_party/lss/linux_syscall_support.h" +#endif + +#if defined(__APPLE__) || defined(__FreeBSD__) +#include +#include + +#define sys_mmap mmap +#define sys_munmap munmap + +#define sys_open open +#define sys_close close +#define sys_readlink readlink +#define sys_fstat fstat + +#define kernel_stat stat + +#elif defined(_WIN32) +#define sys_open _open +#define sys_close _close + +#define kernel_stat stat + +static inline ssize_t sys_readlink(const char* /*path*/, + char* /*buffer*/, + size_t /*buffer_size*/) { + // Windows doesn't have a LINUX readlink(). + return -1; +} + +static inline int sys_fstat(int fd, + struct kernel_stat* st) { + struct _stat64 win_st; + + if (_fstat64(fd, &win_st) != 0) { + return -1; + } + + st->st_size = win_st.st_size; + return 0; +} +#endif + +#endif // SRC_COMPAT_SYSCALL_H_ From 1b6a34a0513a37dde219b890b2b77800600c190c Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 14 Jul 2026 15:05:00 +0200 Subject: [PATCH 06/11] Add compat/inet.h --- src/common/linux/file_id.cc | 3 ++- src/compat/inet.h | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/compat/inet.h diff --git a/src/common/linux/file_id.cc b/src/common/linux/file_id.cc index 9944af7a..e989d9a5 100644 --- a/src/common/linux/file_id.cc +++ b/src/common/linux/file_id.cc @@ -32,9 +32,10 @@ // See file_id.h for documentation // +#include "compat/inet.h" + #include "common/linux/file_id.h" -#include #include #include diff --git a/src/compat/inet.h b/src/compat/inet.h new file mode 100644 index 00000000..fe5740b9 --- /dev/null +++ b/src/compat/inet.h @@ -0,0 +1,10 @@ +#ifndef SRC_COMPAT_INET_H_ +#define SRC_COMPAT_INET_H_ + +#if defined(_WIN32) +#include +#else +#include +#endif + +#endif // SRC_COMPAT_INET_H_ From b90b71c1afa4f611888b4a34f9e8726629f27746 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 14 Jul 2026 15:06:00 +0200 Subject: [PATCH 07/11] Add compat/guiddef.h --- src/common/linux/guid_creator.cc | 14 +++++++------- src/common/linux/guid_creator.h | 4 +++- src/compat/guiddef.h | 22 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 src/compat/guiddef.h diff --git a/src/common/linux/guid_creator.cc b/src/common/linux/guid_creator.cc index 63740638..4163fd60 100644 --- a/src/common/linux/guid_creator.cc +++ b/src/common/linux/guid_creator.cc @@ -92,12 +92,12 @@ class GUIDGenerator { #endif // Put in the version according to RFC 4122. - guid->data3 &= 0x0fff; - guid->data3 |= 0x4000; + guid->COMPAT_GUID_DATA3 &= 0x0fff; + guid->COMPAT_GUID_DATA3 |= 0x4000; // Put in the variant according to RFC 4122. - guid->data4[0] &= 0x3f; - guid->data4[0] |= 0x80; + guid->COMPAT_GUID_DATA4[0] &= 0x3f; + guid->COMPAT_GUID_DATA4[0] |= 0x80; return true; } @@ -178,9 +178,9 @@ bool GUIDToString(const GUID *guid, char *buf, int buf_len) { // Should allow more space the the max length of GUID. assert(buf_len > kGUIDStringLength); int num = snprintf(buf, buf_len, kGUIDFormatString, - guid->data1, guid->data2, guid->data3, - GUIDGenerator::BytesToUInt32(&(guid->data4[0])), - GUIDGenerator::BytesToUInt32(&(guid->data4[4]))); + guid->COMPAT_GUID_DATA1, guid->COMPAT_GUID_DATA2, guid->COMPAT_GUID_DATA3, + GUIDGenerator::BytesToUInt32(&(guid->COMPAT_GUID_DATA4[0])), + GUIDGenerator::BytesToUInt32(&(guid->COMPAT_GUID_DATA4[4]))); if (num != kGUIDStringLength) return false; diff --git a/src/common/linux/guid_creator.h b/src/common/linux/guid_creator.h index c86d856c..34846094 100644 --- a/src/common/linux/guid_creator.h +++ b/src/common/linux/guid_creator.h @@ -30,9 +30,11 @@ #ifndef COMMON_LINUX_GUID_CREATOR_H__ #define COMMON_LINUX_GUID_CREATOR_H__ +// Set MDGUID. #include "google_breakpad/common/minidump_format.h" -typedef MDGUID GUID; +// Use MDGUID. +#include "compat/guiddef.h" // Format string for parsing GUID. #define kGUIDFormatString "%08x-%04x-%04x-%08x-%08x" diff --git a/src/compat/guiddef.h b/src/compat/guiddef.h new file mode 100644 index 00000000..402a87e3 --- /dev/null +++ b/src/compat/guiddef.h @@ -0,0 +1,22 @@ +#ifndef SRC_COMPAT_GUIDDEF_H_ +#define SRC_COMPAT_GUIDDEF_H_ + +#if defined(_WIN32) +#include +#else +typedef MDGUID GUID; +#endif + +#if defined(_WIN32) +#define COMPAT_GUID_DATA1 Data1 +#define COMPAT_GUID_DATA2 Data2 +#define COMPAT_GUID_DATA3 Data3 +#define COMPAT_GUID_DATA4 Data4 +#else +#define COMPAT_GUID_DATA1 data1 +#define COMPAT_GUID_DATA2 data2 +#define COMPAT_GUID_DATA3 data3 +#define COMPAT_GUID_DATA4 data4 +#endif + +#endif // SRC_COMPAT_GUIDDEF_H_ From dcfda26666fe5fb866843e146b46c8c43b52fe29 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 14 Jul 2026 15:07:00 +0200 Subject: [PATCH 08/11] Add compat/paths.h --- src/compat/paths.h | 8 ++++++++ src/tools/linux/dump_syms/dump_syms.cc | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/compat/paths.h diff --git a/src/compat/paths.h b/src/compat/paths.h new file mode 100644 index 00000000..efb7c817 --- /dev/null +++ b/src/compat/paths.h @@ -0,0 +1,8 @@ +#ifndef SRC_COMPAT_PATHS_H_ +#define SRC_COMPAT_PATHS_H_ + +#if !defined(_WIN32) +#include +#endif + +#endif // SRC_COMPAT_PATHS_H_ diff --git a/src/tools/linux/dump_syms/dump_syms.cc b/src/tools/linux/dump_syms/dump_syms.cc index 42e582c6..e97b277e 100644 --- a/src/tools/linux/dump_syms/dump_syms.cc +++ b/src/tools/linux/dump_syms/dump_syms.cc @@ -27,7 +27,8 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include +#include "compat/paths.h" + #include #include From 9a1cb9f27f10dfd1f184ef73e9d020d78f99433b Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 14 Jul 2026 15:08:00 +0200 Subject: [PATCH 09/11] Add compat/linux.h --- src/common/dwarf/elf_reader.cc | 1 + src/common/linux/dump_symbols.cc | 1 + src/common/linux/elf_symbols_to_module.cc | 1 + src/common/linux/memory_mapped_file.cc | 1 + src/common/linux/safe_readlink.cc | 1 + src/common/memory_allocator.h | 1 + src/common/stabs_reader.cc | 2 + src/compat/linux.h | 49 +++++++++++++++++ src/compat/windows/linux.h | 67 +++++++++++++++++++++++ src/tools/linux/dump_syms/dump_syms.cc | 1 + 10 files changed, 125 insertions(+) create mode 100644 src/compat/linux.h create mode 100644 src/compat/windows/linux.h diff --git a/src/common/dwarf/elf_reader.cc b/src/common/dwarf/elf_reader.cc index be67da73..530f02db 100644 --- a/src/common/dwarf/elf_reader.cc +++ b/src/common/dwarf/elf_reader.cc @@ -30,6 +30,7 @@ #define _GNU_SOURCE // needed for pread() #endif +#include "compat/linux.h" #include "compat/elf.h" #include "compat/mman.h" diff --git a/src/common/linux/dump_symbols.cc b/src/common/linux/dump_symbols.cc index ee9cfa4b..05c9e7f2 100644 --- a/src/common/linux/dump_symbols.cc +++ b/src/common/linux/dump_symbols.cc @@ -32,6 +32,7 @@ // dump_symbols.cc: implement google_breakpad::WriteSymbolFile: // Find all the debugging info in a file and dump it as a Breakpad symbol file. +#include "compat/linux.h" #include "compat/elf.h" #include "compat/link.h" #include "compat/mman.h" diff --git a/src/common/linux/elf_symbols_to_module.cc b/src/common/linux/elf_symbols_to_module.cc index 3a7b7489..e79a0750 100644 --- a/src/common/linux/elf_symbols_to_module.cc +++ b/src/common/linux/elf_symbols_to_module.cc @@ -30,6 +30,7 @@ // Original author: Ted Mielczarek +#include "compat/linux.h" #include "compat/elf.h" #include "common/linux/elf_symbols_to_module.h" diff --git a/src/common/linux/memory_mapped_file.cc b/src/common/linux/memory_mapped_file.cc index 4124dd7e..3257da2c 100644 --- a/src/common/linux/memory_mapped_file.cc +++ b/src/common/linux/memory_mapped_file.cc @@ -30,6 +30,7 @@ // memory_mapped_file.cc: Implement google_breakpad::MemoryMappedFile. // See memory_mapped_file.h for details. +#include "compat/linux.h" #include "compat/mman.h" #include "compat/syscall.h" diff --git a/src/common/linux/safe_readlink.cc b/src/common/linux/safe_readlink.cc index c2b26465..ac86fb3a 100644 --- a/src/common/linux/safe_readlink.cc +++ b/src/common/linux/safe_readlink.cc @@ -30,6 +30,7 @@ // safe_readlink.cc: Implement google_breakpad::SafeReadLink. // See safe_readlink.h for details. +#include "compat/linux.h" #include "compat/syscall.h" #include diff --git a/src/common/memory_allocator.h b/src/common/memory_allocator.h index 8398240e..c845236f 100644 --- a/src/common/memory_allocator.h +++ b/src/common/memory_allocator.h @@ -30,6 +30,7 @@ #ifndef GOOGLE_BREAKPAD_COMMON_MEMORY_ALLOCATOR_H_ #define GOOGLE_BREAKPAD_COMMON_MEMORY_ALLOCATOR_H_ +#include "compat/linux.h" #include "compat/mman.h" #include "compat/syscall.h" diff --git a/src/common/stabs_reader.cc b/src/common/stabs_reader.cc index 43c40402..1c2bde37 100644 --- a/src/common/stabs_reader.cc +++ b/src/common/stabs_reader.cc @@ -31,6 +31,8 @@ // This file implements the google_breakpad::StabsReader class. // See stabs_reader.h. +#include "compat/linux.h" + #include "common/stabs_reader.h" #include diff --git a/src/compat/linux.h b/src/compat/linux.h new file mode 100644 index 00000000..f9838d81 --- /dev/null +++ b/src/compat/linux.h @@ -0,0 +1,49 @@ +#ifndef SRC_COMPAT_LINUX_H_ +#define SRC_COMPAT_LINUX_H_ + +#ifndef _SSIZE_T_DEFINED +#include +#if defined(_WIN32) +typedef __int64 ssize_t; +#elif defined(__APPLE__) +typedef __darwin_ssize_t ssize_t; +#elif defined(__FreeBSD__) +typedef __int64_t ssize_t; +#endif +#endif + +#if defined(_WIN32) || defined(__APPLE__) +#include + +static inline void* memrchr(const void* s, + int c, + size_t n) { + const unsigned char* p = static_cast(s) + n; + + while (n--) { + if (*(--p) == static_cast(c)) { + return const_cast(p); + } + } + + return nullptr; +} +#endif + +#if defined(_WIN32) +#include "compat/windows/linux.h" +#endif + +#ifndef __LITTLE_ENDIAN +#define __LITTLE_ENDIAN 1234 +#endif + +#ifndef __BIG_ENDIAN +#define __BIG_ENDIAN 4321 +#endif + +#ifndef __BYTE_ORDER +#define __BYTE_ORDER __LITTLE_ENDIAN +#endif + +#endif // SRC_COMPAT_LINUX_H_ diff --git a/src/compat/windows/linux.h b/src/compat/windows/linux.h new file mode 100644 index 00000000..94bceeaf --- /dev/null +++ b/src/compat/windows/linux.h @@ -0,0 +1,67 @@ +#ifndef SRC_COMPAT_WINDOWS_LINUX_H_ +#define SRC_COMPAT_WINDOWS_LINUX_H_ + +#if !defined(_WIN32) +#error This file is a Windows wrapper! +#endif + +#include +#include + +#ifndef N_UNDF +#define N_UNDF 0 +#endif + +#ifndef _PATH_DEVNULL +#define _PATH_DEVNULL "NUL" +#endif + +#ifndef NAME_MAX +#define NAME_MAX 255 +#endif + +typedef int64_t breakpad_off_t; + +static inline int getpagesize(void) { + SYSTEM_INFO system_info; + GetSystemInfo(&system_info); + return (int)system_info.dwPageSize; +} + +static inline ssize_t pread(int fd, + void* buf, + size_t count, + breakpad_off_t offset) { + __int64 current = _lseeki64(fd, 0, SEEK_CUR); + if (current == -1) { + return -1; + } + + if (_lseeki64(fd, offset, SEEK_SET) == -1) { + return -1; + } + + int result = _read(fd, buf, (unsigned int)count); + + _lseeki64(fd, current, SEEK_SET); + + return result; +} + +static inline char* breakpad_realpath(const char* path, + char* resolved) +{ + DWORD len = GetFullPathNameA(path, MAX_PATH, resolved, nullptr); + + if (len == 0 || len >= MAX_PATH) { + return nullptr; + } + + return resolved; +} + +#ifndef realpath +#define realpath breakpad_realpath +#endif + +#endif // SRC_COMPAT_WINDOWS_LINUX_H_ diff --git a/src/tools/linux/dump_syms/dump_syms.cc b/src/tools/linux/dump_syms/dump_syms.cc index e97b277e..65a6b72d 100644 --- a/src/tools/linux/dump_syms/dump_syms.cc +++ b/src/tools/linux/dump_syms/dump_syms.cc @@ -27,6 +27,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include "compat/linux.h" #include "compat/paths.h" #include From 5e05321a21a6d93b21d28f987230f03aa1248f08 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 14 Jul 2026 15:12:00 +0200 Subject: [PATCH 10/11] Add macOS support to configure.ac --- configure.ac | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 74e4abea..45747723 100644 --- a/configure.ac +++ b/configure.ac @@ -73,7 +73,7 @@ AC_ARG_ENABLE(m32, AC_HEADER_STDC AC_SYS_LARGEFILE AX_PTHREAD -AC_CHECK_HEADERS([a.out.h sys/random.h]) +AC_CHECK_HEADERS([a.out.h mach-o/nlist.h sys/random.h]) AC_CHECK_FUNCS([arc4random getcontext getrandom]) AM_CONDITIONAL([HAVE_GETCONTEXT], [test "x$ac_cv_func_getcontext" = xyes]) @@ -115,6 +115,9 @@ case $host in *-*-linux* | *-android* ) LINUX_HOST=true ;; + *-apple-* ) + MACOS_HOST=true + ;; *-*-cygwin* ) WINDOWS_HOST=true ;; @@ -125,6 +128,7 @@ case $host in esac AM_CONDITIONAL(LINUX_HOST, test x$LINUX_HOST = xtrue) +AM_CONDITIONAL(MACOS_HOST, test x$MACOS_HOST = xtrue) # WINDOWS_HOST means MINGW or CYGWIN AM_CONDITIONAL(WINDOWS_HOST, test x$WINDOWS_HOST = xtrue) AM_CONDITIONAL(MINGW_HOST, test x$MINGW_HOST = xtrue) From afe3f3a9eb8afdda4ce7866af2352b40a4a19b79 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 14 Jul 2026 15:18:00 +0200 Subject: [PATCH 11/11] Build ELF linux/dump_syms everywhere (also for macOS and for Windows with MinGW) --- Makefile.am | 76 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/Makefile.am b/Makefile.am index b91d0bcb..e64e0193 100644 --- a/Makefile.am +++ b/Makefile.am @@ -52,8 +52,8 @@ AM_CXXFLAGS += -fPIC endif if WINDOWS_HOST -# don't have stab.h, don't build stabs support -AM_CPPFLAGS += -DNO_STABS_SUPPORT +# Windows doesn't have stab.h +AM_CPPFLAGS += -I$(top_srcdir)/src/third_party/stab/include endif if MINGW_HOST @@ -62,6 +62,10 @@ AM_CPPFLAGS += -D_POSIX_C_SOURCE AM_CPPFLAGS += -D__USE_MINGW_ANSI_STDIO endif +if MACOS_HOST +AM_CPPFLAGS += -Wno-deprecated-declarations +endif + # Specify include paths for ac macros ACLOCAL_AMFLAGS = -I m4 @@ -391,11 +395,16 @@ bin_PROGRAMS += \ src/tools/windows/dump_syms_dwarf/dump_syms_dwarf endif +if !DISABLE_TOOLS +bin_PROGRAMS += \ + src/tools/linux/dump_syms/dump_syms +endif + if MINGW_HOST # For MinGW, use gyp to generate a Makefile to build Windows client library Configuration ?= Debug all-local: - cd $(top_srcdir)/src ; ./tools/gyp/gyp --no-circular-check --no-parallel --depth=. -f make client/windows/breakpad_client.gyp + cd $(top_srcdir)/src ; GYP_DEFINES='OS=win' ./tools/gyp/gyp --no-circular-check --no-parallel --depth=. -f make client/windows/breakpad_client.gyp cd $(top_srcdir)/src ; $(MAKE) CXX="$(CXX)" CXXFLAGS="-DUNICODE -D_UNICODE $(AM_CPPFLAGS) $(CXXFLAGS)" AR="$(AR)" RC="$(WINDRES)" BUILDTYPE="$(Configuration)" endif @@ -627,36 +636,6 @@ src_tools_linux_pid2md_pid2md_SOURCES = \ src_tools_linux_pid2md_pid2md_LDADD = \ src/client/linux/libbreakpad_client.a -src_tools_linux_dump_syms_dump_syms_SOURCES = \ - src/common/dwarf_cfi_to_module.cc \ - src/common/dwarf_cu_to_module.cc \ - src/common/dwarf_line_to_module.cc \ - src/common/dwarf_range_list_handler.cc \ - src/common/language.cc \ - src/common/module.cc \ - src/common/path_helper.cc \ - src/common/stabs_reader.cc \ - src/common/stabs_to_module.cc \ - src/common/dwarf/bytereader.cc \ - src/common/dwarf/dwarf2diehandler.cc \ - src/common/dwarf/dwarf2reader.cc \ - src/common/dwarf/elf_reader.cc \ - src/common/linux/crc32.cc \ - src/common/linux/dump_symbols.cc \ - src/common/linux/dump_symbols.h \ - src/common/linux/elf_symbols_to_module.cc \ - src/common/linux/elf_symbols_to_module.h \ - src/common/linux/elfutils.cc \ - src/common/linux/file_id.cc \ - src/common/linux/linux_libc_support.cc \ - src/common/linux/memory_mapped_file.cc \ - src/common/linux/safe_readlink.cc \ - src/tools/linux/dump_syms/dump_syms.cc -src_tools_linux_dump_syms_dump_syms_CXXFLAGS = \ - $(RUST_DEMANGLE_CFLAGS) -src_tools_linux_dump_syms_dump_syms_LDADD = \ - $(RUST_DEMANGLE_LIBS) - src_tools_linux_md2core_minidump_2_core_SOURCES = \ src/common/linux/memory_mapped_file.cc \ src/common/path_helper.cc \ @@ -855,6 +834,37 @@ src_tools_windows_dump_syms_dwarf_dump_syms_dwarf_SOURCES = \ src/tools/windows/dump_syms_dwarf/dump_syms.cc src_tools_windows_dump_syms_dwarf_dump_syms_dwarf_LDADD = \ $(SOCKET_LIBS) + +src_tools_linux_dump_syms_dump_syms_SOURCES = \ + src/common/dwarf_cfi_to_module.cc \ + src/common/dwarf_cu_to_module.cc \ + src/common/dwarf_line_to_module.cc \ + src/common/dwarf_range_list_handler.cc \ + src/common/language.cc \ + src/common/module.cc \ + src/common/path_helper.cc \ + src/common/stabs_reader.cc \ + src/common/stabs_to_module.cc \ + src/common/dwarf/bytereader.cc \ + src/common/dwarf/dwarf2diehandler.cc \ + src/common/dwarf/dwarf2reader.cc \ + src/common/dwarf/elf_reader.cc \ + src/common/linux/crc32.cc \ + src/common/linux/dump_symbols.cc \ + src/common/linux/dump_symbols.h \ + src/common/linux/elf_symbols_to_module.cc \ + src/common/linux/elf_symbols_to_module.h \ + src/common/linux/elfutils.cc \ + src/common/linux/file_id.cc \ + src/common/linux/linux_libc_support.cc \ + src/common/linux/memory_mapped_file.cc \ + src/common/linux/safe_readlink.cc \ + src/tools/linux/dump_syms/dump_syms.cc +src_tools_linux_dump_syms_dump_syms_CXXFLAGS = \ + $(RUST_DEMANGLE_CFLAGS) +src_tools_linux_dump_syms_dump_syms_LDADD = \ + $(RUST_DEMANGLE_LIBS) \ + $(SOCKET_LIBS) endif if !DISABLE_PROCESSOR