Skip to content

Commit

Permalink
Export patch series to _PATCHES/
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeubank committed May 24, 2021
1 parent bb6088a commit 4f53aa1
Show file tree
Hide file tree
Showing 44 changed files with 9,328 additions and 0 deletions.
147 changes: 147 additions & 0 deletions _PATCHES/Fix-using-large-PCH.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
Handle larger precompiled headers

From: Martin Richter <xricht17@stud.fit.vutbr.cz>

From
<https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-gcc/0010-Fix-using-large-PCH.patch>

From 22a67f6b18d2854bcdf740833cf4e1a0555c7295 Mon Sep 17 00:00:00 2001
Subject: [PATCH 10/15] Fix using large PCH

The following patch fixes segfault when gt_pch_use_address
fails (returns -1). fatal_error now correctly shows an error
message and terminates the program.
I have basicly only reordered reads, and placed them after
the file mapping itself. Global pointers are changed only
after gt_pch_use_address succeeds, so in case of failure
they still contain valid addresses.

This patch is meant for the master branch. However, it
should not be hard to modify it for others.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14940
https://sourceforge.net/p/mingw-w64/bugs/382/
---
gcc/config/i386/host-mingw32.c | 10 ++-------
gcc/ggc-common.c | 45 +++++++++++++++++++++++++++++++++-------
2 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/gcc/config/i386/host-mingw32.c b/gcc/config/i386/host-mingw32.c
index 250fef59b..36b2239aa 100644
--- a/gcc/config/i386/host-mingw32.c
+++ b/gcc/config/i386/host-mingw32.c
@@ -44,9 +44,6 @@ static size_t mingw32_gt_pch_alloc_granularity (void);

static inline void w32_error(const char*, const char*, int, const char*);

-/* FIXME: Is this big enough? */
-static const size_t pch_VA_max_size = 128 * 1024 * 1024;
-
/* Granularity for reserving address space. */
static size_t va_granularity = 0x10000;

@@ -88,9 +85,6 @@ static void *
mingw32_gt_pch_get_address (size_t size, int)
{
void* res;
- size = (size + va_granularity - 1) & ~(va_granularity - 1);
- if (size > pch_VA_max_size)
- return NULL;

/* FIXME: We let system determine base by setting first arg to NULL.
Allocating at top of available address space avoids unnecessary
@@ -100,7 +94,7 @@ mingw32_gt_pch_get_address (size_t size, int)
If we allocate at bottom we need to reserve the address as early
as possible and at the same point in each invocation. */

- res = VirtualAlloc (NULL, pch_VA_max_size,
+ res = VirtualAlloc (NULL, size,
MEM_RESERVE | MEM_TOP_DOWN,
PAGE_NOACCESS);
if (!res)
@@ -150,7 +144,7 @@ mingw32_gt_pch_use_address (void *addr, size_t size, int fd,

/* Offset must be also be a multiple of allocation granularity for
this to work. We can't change the offset. */
- if ((offset & (va_granularity - 1)) != 0 || size > pch_VA_max_size)
+ if ((offset & (va_granularity - 1)) != 0)
return -1;


diff --git a/gcc/ggc-common.c b/gcc/ggc-common.c
index 0d528cf45..8dedeb2ff 100644
--- a/gcc/ggc-common.c
+++ b/gcc/ggc-common.c
@@ -591,7 +591,9 @@ gt_pch_restore (FILE *f)
size_t i;
struct mmap_info mmi;
int result;
-
+ long pch_tabs_off;
+ long pch_data_off;
+
/* Delete any deletable objects. This makes ggc_pch_read much
faster, as it can be sure that no GCable objects remain other
than the ones just read in. */
@@ -599,20 +601,24 @@ gt_pch_restore (FILE *f)
for (rti = *rt; rti->base != NULL; rti++)
memset (rti->base, 0, rti->stride);

- /* Read in all the scalar variables. */
+ /* We need to read tables after mapping, or fatal_error will
+ segfault when gt_pch_use_address returns -1. Skip them for now. */
+ pch_tabs_off = ftell(f);
+
+ /* Skip all the scalar variables. */
for (rt = gt_pch_scalar_rtab; *rt; rt++)
for (rti = *rt; rti->base != NULL; rti++)
- if (fread (rti->base, rti->stride, 1, f) != 1)
- fatal_error (input_location, "cannot read PCH file: %m");
+ if (fseek (f, rti->stride, SEEK_CUR) != 0)
+ fatal_error (input_location, "cannot read PCH file: %m");

- /* Read in all the global pointers, in 6 easy loops. */
+ /* Skip all the global pointers. */
for (rt = gt_ggc_rtab; *rt; rt++)
for (rti = *rt; rti->base != NULL; rti++)
for (i = 0; i < rti->nelt; i++)
- if (fread ((char *)rti->base + rti->stride * i,
- sizeof (void *), 1, f) != 1)
- fatal_error (input_location, "cannot read PCH file: %m");
+ if (fseek (f, sizeof (void *), SEEK_CUR) != 0)
+ fatal_error (input_location, "cannot read PCH file: %m");

+ /* mmi still has to be read now. */
if (fread (&mmi, sizeof (mmi), 1, f) != 1)
fatal_error (input_location, "cannot read PCH file: %m");

@@ -629,6 +635,29 @@ gt_pch_restore (FILE *f)
else if (fseek (f, mmi.offset + mmi.size, SEEK_SET) != 0)
fatal_error (input_location, "cannot read PCH file: %m");

+ /* File mapping done, read tables now. */
+ pch_data_off = ftell(f);
+
+ if (fseek (f, pch_tabs_off, SEEK_SET) != 0)
+ fatal_error (input_location, "cannot read PCH file: %m");
+
+ /* Read in all the scalar variables. */
+ for (rt = gt_pch_scalar_rtab; *rt; rt++)
+ for (rti = *rt; rti->base != NULL; rti++)
+ if (fread (rti->base, rti->stride, 1, f) != 1)
+ fatal_error (input_location, "cannot read PCH file: %m");
+
+ /* Read in all the global pointers, in 6 easy loops. */
+ for (rt = gt_ggc_rtab; *rt; rt++)
+ for (rti = *rt; rti->base != NULL; rti++)
+ for (i = 0; i < rti->nelt; i++)
+ if (fread ((char *)rti->base + rti->stride * i,
+ sizeof (void *), 1, f) != 1)
+ fatal_error (input_location, "cannot read PCH file: %m");
+
+ if (fseek (f, pch_data_off, SEEK_SET) != 0)
+ fatal_error (input_location, "cannot read PCH file: %m");
+
ggc_pch_read (f, mmi.preferred_base);

gt_pch_restore_stringpool ();
61 changes: 61 additions & 0 deletions _PATCHES/Handle-spaces-in-path-for-default-manifest.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Allow spaces in specfile entries that expand to full paths if they are library files

From: J.M. Eubank <john@thesnappy.net>

From
<https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-gcc/0012-Handle-spaces-in-path-for-default-manifest.patch>

# HG changeset patch
# Parent 80c5a58ce2412b6977cd5b103e4387042fb6955a
---
gcc/gcc.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gcc/gcc.c b/gcc/gcc.c
index a648e5ba4..6ef561519 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -6130,7 +6130,6 @@ eval_spec_function (const char *func, const char *args,
int save_arg_going;
int save_delete_this_arg;
int save_this_is_output_file;
- int save_this_is_library_file;
int save_input_from_pipe;
int save_this_is_linker_script;
const char *save_suffix_subst;
@@ -6148,7 +6147,6 @@ eval_spec_function (const char *func, const char *args,
save_arg_going = arg_going;
save_delete_this_arg = delete_this_arg;
save_this_is_output_file = this_is_output_file;
- save_this_is_library_file = this_is_library_file;
save_this_is_linker_script = this_is_linker_script;
save_input_from_pipe = input_from_pipe;
save_suffix_subst = suffix_subst;
@@ -6180,13 +6178,15 @@ eval_spec_function (const char *func, const char *args,
argbuf.address ());

/* Pop the spec processing context. */
+ const char *saved_library_file = this_is_library_file ? argbuf.address()[0] : NULL;
argbuf.release ();
argbuf = save_argbuf;
+ if (saved_library_file)
+ argbuf.safe_push (saved_library_file);

arg_going = save_arg_going;
delete_this_arg = save_delete_this_arg;
this_is_output_file = save_this_is_output_file;
- this_is_library_file = save_this_is_library_file;
this_is_linker_script = save_this_is_linker_script;
input_from_pipe = save_input_from_pipe;
suffix_subst = save_suffix_subst;
@@ -6258,8 +6258,9 @@ handle_spec_function (const char *p, bool *retval_nonnull,
/* p now points to just past the end of the spec function expression. */

funcval = eval_spec_function (func, args, soft_matched_part);
- if (funcval != NULL && do_spec_1 (funcval, 0, NULL) < 0)
+ if (funcval != NULL && this_is_library_file == 0 && do_spec_1 (funcval, 0, NULL) < 0)
p = NULL;
+
if (retval_nonnull)
*retval_nonnull = funcval != NULL;

Loading

0 comments on commit 4f53aa1

Please sign in to comment.