Commit ac631cbe by Aldy Hernandez Committed by Aldy Hernandez

libiberty.h (MAX_ALLOCA_SIZE): New macro.

include/
	* libiberty.h (MAX_ALLOCA_SIZE): New macro.

libiberty/
	* make-relative-prefix.c (make_relative_prefix_1): Fall back to
	malloc if alloca argument is greater than MAX_ALLOCA_SIZE.

From-SVN: r238880
parent d51553e0
2016-07-29 Aldy Hernandez <aldyh@redhat.com>
* libiberty.h (MAX_ALLOCA_SIZE): New macro.
2016-05-26 Chung-Lin Tang <cltang@codesourcery.com> 2016-05-26 Chung-Lin Tang <cltang@codesourcery.com>
* gomp-constants.h (GOMP_VERSION): Increment to 1, add comment to * gomp-constants.h (GOMP_VERSION): Increment to 1, add comment to
......
...@@ -397,6 +397,17 @@ extern void hex_init (void); ...@@ -397,6 +397,17 @@ extern void hex_init (void);
/* Save files used for communication between processes. */ /* Save files used for communication between processes. */
#define PEX_SAVE_TEMPS 0x4 #define PEX_SAVE_TEMPS 0x4
/* Max number of alloca bytes per call before we must switch to malloc.
?? Swiped from gnulib's regex_internal.h header. Is this actually
the case? This number seems arbitrary, though sane.
The OS usually guarantees only one guard page at the bottom of the stack,
and a page size can be as small as 4096 bytes. So we cannot safely
allocate anything larger than 4096 bytes. Also care for the possibility
of a few compiler-allocated temporary stack slots. */
#define MAX_ALLOCA_SIZE 4032
/* Prepare to execute one or more programs, with standard output of /* Prepare to execute one or more programs, with standard output of
each program fed to standard input of the next. each program fed to standard input of the next.
FLAGS As above. FLAGS As above.
......
2016-07-29 Aldy Hernandez <aldyh@redhat.com>
* make-relative-prefix.c (make_relative_prefix_1): Fall back to
malloc if alloca argument is greater than MAX_ALLOCA_SIZE.
2016-07-15 Jason Merrill <jason@redhat.com> 2016-07-15 Jason Merrill <jason@redhat.com>
* cp-demangle.c (cplus_demangle_operators): Add f[lrLR]. * cp-demangle.c (cplus_demangle_operators): Add f[lrLR].
......
...@@ -233,6 +233,7 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix, ...@@ -233,6 +233,7 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix,
int i, n, common; int i, n, common;
int needed_len; int needed_len;
char *ret = NULL, *ptr, *full_progname; char *ret = NULL, *ptr, *full_progname;
char *alloc_ptr = NULL;
if (progname == NULL || bin_prefix == NULL || prefix == NULL) if (progname == NULL || bin_prefix == NULL || prefix == NULL)
return NULL; return NULL;
...@@ -256,7 +257,10 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix, ...@@ -256,7 +257,10 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix,
#ifdef HAVE_HOST_EXECUTABLE_SUFFIX #ifdef HAVE_HOST_EXECUTABLE_SUFFIX
len += strlen (HOST_EXECUTABLE_SUFFIX); len += strlen (HOST_EXECUTABLE_SUFFIX);
#endif #endif
nstore = (char *) alloca (len); if (len < MAX_ALLOCA_SIZE)
nstore = (char *) alloca (len);
else
alloc_ptr = nstore = (char *) malloc (len);
startp = endp = temp; startp = endp = temp;
while (1) while (1)
...@@ -312,12 +316,12 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix, ...@@ -312,12 +316,12 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix,
else else
full_progname = strdup (progname); full_progname = strdup (progname);
if (full_progname == NULL) if (full_progname == NULL)
return NULL; goto bailout;
prog_dirs = split_directories (full_progname, &prog_num); prog_dirs = split_directories (full_progname, &prog_num);
free (full_progname); free (full_progname);
if (prog_dirs == NULL) if (prog_dirs == NULL)
return NULL; goto bailout;
bin_dirs = split_directories (bin_prefix, &bin_num); bin_dirs = split_directories (bin_prefix, &bin_num);
if (bin_dirs == NULL) if (bin_dirs == NULL)
...@@ -395,6 +399,7 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix, ...@@ -395,6 +399,7 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix,
free_split_directories (prog_dirs); free_split_directories (prog_dirs);
free_split_directories (bin_dirs); free_split_directories (bin_dirs);
free_split_directories (prefix_dirs); free_split_directories (prefix_dirs);
free (alloc_ptr);
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment