aboutsummaryrefslogtreecommitdiff
path: root/libbacktrace
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2023-11-30 11:24:08 -0800
committerIan Lance Taylor <iant@golang.org>2023-11-30 11:24:57 -0800
commitc6f7253bcc9e792eb045940b36c113969e47e383 (patch)
tree2d4356cccd8866534c0eaf1242b0d74cf5b9cc2e /libbacktrace
parentdf8958e6bc5d050dab8bdc5954c1632fb0e98d18 (diff)
downloadgcc-c6f7253bcc9e792eb045940b36c113969e47e383.zip
gcc-c6f7253bcc9e792eb045940b36c113969e47e383.tar.gz
gcc-c6f7253bcc9e792eb045940b36c113969e47e383.tar.bz2
libbacktrace: support ASLR on Windows
Patch from Björn Schäpers. * pecoff.c: Include <windows.h> if available. (coff_add): On Windows call GetModuleHandle to get base address.
Diffstat (limited to 'libbacktrace')
-rw-r--r--libbacktrace/pecoff.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/libbacktrace/pecoff.c b/libbacktrace/pecoff.c
index 56af482..f976a96 100644
--- a/libbacktrace/pecoff.c
+++ b/libbacktrace/pecoff.c
@@ -39,6 +39,18 @@ POSSIBILITY OF SUCH DAMAGE. */
#include "backtrace.h"
#include "internal.h"
+#ifdef HAVE_WINDOWS_H
+#ifndef WIN32_MEAN_AND_LEAN
+#define WIN32_MEAN_AND_LEAN
+#endif
+
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+
+#include <windows.h>
+#endif
+
/* Coff file header. */
typedef struct {
@@ -610,6 +622,7 @@ coff_add (struct backtrace_state *state, int descriptor,
int debug_view_valid;
int is_64;
uintptr_t image_base;
+ uintptr_t base_address = 0;
struct dwarf_sections dwarf_sections;
*found_sym = 0;
@@ -856,7 +869,16 @@ coff_add (struct backtrace_state *state, int descriptor,
+ (sections[i].offset - min_offset));
}
- if (!backtrace_dwarf_add (state, /* base_address */ 0, &dwarf_sections,
+#ifdef HAVE_WINDOWS_H
+ {
+ uintptr_t module_handle;
+
+ module_handle = (uintptr_t) GetModuleHandle (NULL);
+ base_address = module_handle - image_base;
+ }
+#endif
+
+ if (!backtrace_dwarf_add (state, base_address, &dwarf_sections,
0, /* FIXME: is_bigendian */
NULL, /* altlink */
error_callback, data, fileline_fn,