crates/backtrace-sys2/src/libbacktrace/macho.c in pf2-0.6.0 vs crates/backtrace-sys2/src/libbacktrace/macho.c in pf2-0.7.0
- old
+ new
@@ -1,7 +1,7 @@
/* elf.c -- Get debug data from a Mach-O file for backtraces.
- Copyright (C) 2020-2021 Free Software Foundation, Inc.
+ Copyright (C) 2020-2024 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Google.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
@@ -269,16 +269,18 @@
uint64_t n_value; /* Value */
};
/* Value found in nlist n_type field. */
-#define MACH_O_N_EXT 0x01 /* Extern symbol */
+#define MACH_O_N_STAB 0xe0 /* Stabs debugging symbol */
+#define MACH_O_N_TYPE 0x0e /* Mask for type bits */
+
+/* Values found after masking with MACH_O_N_TYPE. */
+#define MACH_O_N_UNDF 0x00 /* Undefined symbol */
#define MACH_O_N_ABS 0x02 /* Absolute symbol */
-#define MACH_O_N_SECT 0x0e /* Defined in section */
+#define MACH_O_N_SECT 0x0e /* Defined in section from n_sect field */
-#define MACH_O_N_TYPE 0x0e /* Mask for type bits */
-#define MACH_O_N_STAB 0xe0 /* Stabs debugging symbol */
/* Information we keep for a Mach-O symbol. */
struct macho_symbol
{
@@ -311,22 +313,23 @@
};
/* Forward declaration. */
static int macho_add (struct backtrace_state *, const char *, int, off_t,
- const unsigned char *, uintptr_t, int,
- backtrace_error_callback, void *, fileline *, int *);
+ const unsigned char *, struct libbacktrace_base_address,
+ int, backtrace_error_callback, void *, fileline *,
+ int *);
/* A dummy callback function used when we can't find any debug info. */
static int
macho_nodebug (struct backtrace_state *state ATTRIBUTE_UNUSED,
uintptr_t pc ATTRIBUTE_UNUSED,
backtrace_full_callback callback ATTRIBUTE_UNUSED,
backtrace_error_callback error_callback, void *data)
{
- error_callback (data, "no debug info in Mach-O executable", -1);
+ error_callback (data, "no debug info in Mach-O executable (make sure to compile with -g; may need to run dsymutil)", -1);
return 0;
}
/* A dummy callback function used when we can't find a symbol
table. */
@@ -490,14 +493,14 @@
static int
macho_defined_symbol (uint8_t type)
{
if ((type & MACH_O_N_STAB) != 0)
return 0;
- if ((type & MACH_O_N_EXT) != 0)
- return 0;
switch (type & MACH_O_N_TYPE)
{
+ case MACH_O_N_UNDF:
+ return 0;
case MACH_O_N_ABS:
return 1;
case MACH_O_N_SECT:
return 1;
default:
@@ -507,11 +510,11 @@
/* Add symbol table information for a Mach-O file. */
static int
macho_add_symtab (struct backtrace_state *state, int descriptor,
- uintptr_t base_address, int is_64,
+ struct libbacktrace_base_address base_address, int is_64,
off_t symoff, unsigned int nsyms, off_t stroff,
unsigned int strsize,
backtrace_error_callback error_callback, void *data)
{
size_t symsize;
@@ -622,11 +625,11 @@
name = (const char *) str_view.data + strx;
if (name[0] == '_')
++name;
macho_symbols[j].name = name;
- macho_symbols[j].address = value + base_address;
+ macho_symbols[j].address = libbacktrace_add_base (value, base_address);
++j;
}
sdata = ((struct macho_syminfo_data *)
backtrace_alloc (state, sizeof *sdata, error_callback, data));
@@ -672,11 +675,10 @@
while (1)
{
struct macho_syminfo_data *p;
p = backtrace_atomic_load_pointer (pp);
-
if (p == NULL)
break;
pp = &p->next;
}
@@ -755,11 +757,12 @@
on success, 0 on failure (in both cases descriptor is closed). */
static int
macho_add_fat (struct backtrace_state *state, const char *filename,
int descriptor, int swapped, off_t offset,
- const unsigned char *match_uuid, uintptr_t base_address,
+ const unsigned char *match_uuid,
+ struct libbacktrace_base_address base_address,
int skip_symtab, uint32_t nfat_arch, int is_64,
backtrace_error_callback error_callback, void *data,
fileline *fileline_fn, int *found_sym)
{
int arch_view_valid;
@@ -857,11 +860,12 @@
does not have debug info or a symbol table. Returns 1 on success,
0 on failure. */
static int
macho_add_dsym (struct backtrace_state *state, const char *filename,
- uintptr_t base_address, const unsigned char *uuid,
+ struct libbacktrace_base_address base_address,
+ const unsigned char *uuid,
backtrace_error_callback error_callback, void *data,
fileline* fileline_fn)
{
const char *p;
const char *dirname;
@@ -975,11 +979,11 @@
*/
static int
macho_add (struct backtrace_state *state, const char *filename, int descriptor,
off_t offset, const unsigned char *match_uuid,
- uintptr_t base_address, int skip_symtab,
+ struct libbacktrace_base_address base_address, int skip_symtab,
backtrace_error_callback error_callback, void *data,
fileline *fileline_fn, int *found_sym)
{
struct backtrace_view header_view;
struct macho_header_32 header;
@@ -1237,11 +1241,11 @@
macho_fileline_fn = macho_nodebug;
c = _dyld_image_count ();
for (i = 0; i < c; ++i)
{
- uintptr_t base_address;
+ struct libbacktrace_base_address base_address;
const char *name;
int d;
fileline mff;
int mfs;
@@ -1261,11 +1265,11 @@
d = backtrace_open (name, error_callback, data, &does_not_exist);
if (d < 0)
continue;
}
- base_address = _dyld_get_image_vmaddr_slide (i);
+ base_address.m = _dyld_get_image_vmaddr_slide (i);
mff = macho_nodebug;
if (!macho_add (state, name, d, 0, NULL, base_address, 0,
error_callback, data, &mff, &mfs))
continue;
@@ -1316,13 +1320,15 @@
backtrace_initialize (struct backtrace_state *state, const char *filename,
int descriptor, backtrace_error_callback error_callback,
void *data, fileline *fileline_fn)
{
fileline macho_fileline_fn;
+ struct libbacktrace_base_address zero_base_address;
int found_sym;
macho_fileline_fn = macho_nodebug;
- if (!macho_add (state, filename, descriptor, 0, NULL, 0, 0,
+ memset (&zero_base_address, 0, sizeof zero_base_address);
+ if (!macho_add (state, filename, descriptor, 0, NULL, zero_base_address, 0,
error_callback, data, &macho_fileline_fn, &found_sym))
return 0;
if (!state->threaded)
{