From patchwork Fri Jan 20 10:54:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Bj=C3=B6rn_Sch=C3=A4pers?= X-Patchwork-Id: 46290 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp129415wrn; Fri, 20 Jan 2023 02:55:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXte6wO8aGQ34nyEWCjkD4Z4hQJyzsXYJ3FuHSwk7Gq9HwTKaON/l8pexED52ZceVxu+JkGI X-Received: by 2002:a05:6402:d65:b0:45c:835b:ac4d with SMTP id ec37-20020a0564020d6500b0045c835bac4dmr15045574edb.8.1674212158794; Fri, 20 Jan 2023 02:55:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674212158; cv=none; d=google.com; s=arc-20160816; b=s0tK0DQnbVXoiL5J6wCC/eiZidiZoOvTA8VUB++voRSfJWkPzkUTnFrLgvyx7SCoIV ziU9aRGNap3AhMHQskD3hA6Gh1UzoUh9nG4KHdOZki76T7QHHRlE5Wudm1U8kxpECfYy BCWlyzR8OGh0JPf7M2F1o1vQwBMe26LllUH6hiwPa5IR9I2zhlTo8rlIGHRl+zw7IL/M 8FIEkRXXZjN8Ub0Ft2JbHgil/4a04tEGs1xyhMj2LeJrYMwHc8N98gJn2jcmuk3rDLSN L/l4muKfLimuTNH3WHD1KrVUqnt1zr0wKaiUWZlC3JvNvCrcwVGUELgh2J+XPp80nZaX oblg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dmarc-filter:delivered-to; bh=4M8ObylRJfGvNaemd4kyd0yRgikcz0LJno69sIT8KQI=; b=Pq9mxFKyjuvXgrUOE4U4DlMRE+Ga1OFkrRgfoPTNAS37BQbZwxmW6YhdDlmyoH///f Eyi9IWIwpWYYjATXJJakolNsE5lOAFCAXTG2WyLTCLg3ImI0D+rcPmDDb8aBeeLa1GMr y0+jHaS9A5jzqRhbN8eRzCoGHxEB4d9YRDL+Vvzp2Xl5PvtohJIB8ZPDOk9YO8ZuN7TU K/r9gcdG32tzVYfRsGsHDjpRgNAZhiQ4WrfZNd5wnFxD+eUb8MMlfTROzogtqv4D9Mn6 QL2FjKaIMhEFrr0XOazgv414F6GmUqVrQGFPwnWjsBWCH+llQLqs0UZ6b40xc2tmi/KO KcnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id cs2-20020a0564020c4200b00499bebec458si35771044edb.299.2023.01.20.02.55.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 02:55:58 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 19D3D3881D02 for ; Fri, 20 Jan 2023 10:54:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.hazardy.de (mail.hazardy.de [78.94.181.132]) by sourceware.org (Postfix) with ESMTPS id 769053858C62; Fri, 20 Jan 2023 10:54:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 769053858C62 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=hazardy.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=hazardy.de Received: from NB-372.intranet.mimot.com (188-136-75-197-ftth-senden-dyn.heliweb.de [188.136.75.197]) by mail.hazardy.de (Postfix) with ESMTPSA id 5D7D67004A0; Fri, 20 Jan 2023 11:54:18 +0100 (CET) From: =?utf-8?q?Bj=C3=B6rn_Sch=C3=A4pers?= To: gcc-patches@gcc.gnu.org, gcc@gcc.gnu.org Subject: [PATCH 3/4] libbacktrace: work with aslr on windows Date: Fri, 20 Jan 2023 11:54:08 +0100 Message-Id: <20230120105409.54949-3-gcc@hazardy.de> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230120105409.54949-1-gcc@hazardy.de> References: <20230120105409.54949-1-gcc@hazardy.de> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755538688688184786?= X-GMAIL-MSGID: =?utf-8?q?1755538688688184786?= From: Björn Schäpers 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 Signed-off-by: Björn Schäpers --- 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 +#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,