From: "Björn Schäpers" <gcc@hazardy.de>
To: gcc-patches@gcc.gnu.org, iant@golang.org
Subject: [PATCH 3/4] libbacktrace: work with aslr on windows
Date: Tue, 6 Dec 2022 20:50:27 +0100 [thread overview]
Message-ID: <20221206195028.37104-3-gcc@hazardy.de> (raw)
In-Reply-To: <20221206195028.37104-1-gcc@hazardy.de>
From: Björn Schäpers <bjoern@hazardy.de>
Any underflow which might happen, will be countered by an overflow in
dwarf.c.
Tested on x86_64-linux and i686-w64-mingw32.
-- >8 --
Fixes https://github.com/ianlancetaylor/libbacktrace/issues/89 and
https://github.com/ianlancetaylor/libbacktrace/issues/82.
* pecoff.c (coff_add): Set the base_address of the module, to
find the debug information on moved applications.
Signed-off-by: Björn Schäpers <bjoern@hazardy.de>
---
libbacktrace/pecoff.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/libbacktrace/pecoff.c b/libbacktrace/pecoff.c
index 87b3c0cc647..296f1357b5f 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,8 @@ coff_add (struct backtrace_state *state, int descriptor,
int debug_view_valid;
int is_64;
uintptr_t image_base;
+ uintptr_t base_address = 0;
+ uintptr_t module_handle;
struct dwarf_sections dwarf_sections;
*found_sym = 0;
@@ -856,7 +870,12 @@ 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
+ module_handle = (uintptr_t) GetModuleHandleW (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,
--
2.38.1
next prev parent reply other threads:[~2022-12-06 19:50 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-06 19:50 [PATCH 1/4] libbacktrace: change all pc related variables to uintptr_t Björn Schäpers
2022-12-06 19:50 ` [PATCH 2/4] libbacktrace: detect executable path on windows Björn Schäpers
2022-12-06 19:50 ` Björn Schäpers [this message]
2022-12-06 19:50 ` [PATCH 4/4] libbacktrace: get debug information for loaded dlls Björn Schäpers
2023-01-20 10:54 [PATCH 1/4] libbacktrace: change all pc related variables to uintptr_t Björn Schäpers
2023-01-20 10:54 ` [PATCH 3/4] libbacktrace: work with aslr on windows Björn Schäpers
2023-01-20 13:39 ` Eli Zaretskii
2023-01-20 16:46 ` Gabriel Ravier
2023-01-20 19:19 ` Eli Zaretskii
2023-01-20 20:39 ` Gabriel Ravier
2023-01-21 4:05 ` Eli Zaretskii
2023-01-21 9:18 ` LIU Hao
2023-01-21 9:25 ` Eli Zaretskii
2023-01-21 10:47 ` Gabriel Ravier
2023-01-21 11:42 ` Eli Zaretskii
2023-11-20 19:57 ` Björn Schäpers
2023-11-20 20:07 ` Eli Zaretskii
2023-11-21 19:35 ` Björn Schäpers
2023-11-22 1:13 ` LIU Hao
2023-11-30 19:25 ` Ian Lance Taylor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221206195028.37104-3-gcc@hazardy.de \
--to=gcc@hazardy.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=iant@golang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).