aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorThomas Schwinge <tschwinge@baylibre.com>2025-05-26 13:31:54 +0200
committerThomas Schwinge <tschwinge@baylibre.com>2025-06-04 19:47:22 +0200
commitd283eba8b886921424ef86ce1804ecfcbc49b8fc (patch)
tree71a900313da96c3e2f788f498c2f89e299b69596 /gcc
parent3f67be6a45634add47d777dcd7a5f95ed313adee (diff)
downloadgcc-d283eba8b886921424ef86ce1804ecfcbc49b8fc.zip
gcc-d283eba8b886921424ef86ce1804ecfcbc49b8fc.tar.gz
gcc-d283eba8b886921424ef86ce1804ecfcbc49b8fc.tar.bz2
Avoid SIGSEGV in nvptx 'mkoffload' for voluminous PTX code
In commit 50be486dff4ea2676ed022e9524ef190b92ae2b1 "nvptx: libgomp+mkoffload.cc: Prepare for reverse offload fn lookup", some additional tracking of the PTX code was added, and this assumes that potentially every single character of PTX code needs to be tracked as a new chunk of PTX code. That's problematic if we're dealing with voluminous PTX code (for example, non-trivial C++ code), and the 'file_idx' 'alloca'tion then causes stack overflow. For example: FAIL: libgomp.c++/target-std__valarray-1.C (test for excess errors) UNRESOLVED: libgomp.c++/target-std__valarray-1.C compilation failed to produce executable lto-wrapper: fatal error: [...]/build-gcc/gcc//accel/nvptx-none/mkoffload terminated with signal 11 [Segmentation fault], core dumped gcc/ * config/nvptx/mkoffload.cc (process): Use an 'auto_vec' for 'file_idx'. (cherry picked from commit 01044e0ee27093a3990996578b15f6ab69ed3395)
Diffstat (limited to 'gcc')
-rw-r--r--gcc/config/nvptx/mkoffload.cc12
1 files changed, 9 insertions, 3 deletions
diff --git a/gcc/config/nvptx/mkoffload.cc b/gcc/config/nvptx/mkoffload.cc
index 205bc2d..bee18e7 100644
--- a/gcc/config/nvptx/mkoffload.cc
+++ b/gcc/config/nvptx/mkoffload.cc
@@ -260,8 +260,10 @@ process (FILE *in, FILE *out, uint32_t omp_requires)
unsigned ix;
const char *sm_ver = NULL, *version = NULL;
const char *sm_ver2 = NULL, *version2 = NULL;
- size_t file_cnt = 0;
- size_t *file_idx = XALLOCAVEC (size_t, len);
+ /* To reduce the number of reallocations for 'file_idx', guess 'file_cnt'
+ (very roughly...), based on 'len'. */
+ const size_t file_cnt_guessed = 13 + len / 27720;
+ auto_vec<size_t> file_idx (file_cnt_guessed);
fprintf (out, "#include <stdint.h>\n\n");
@@ -269,9 +271,10 @@ process (FILE *in, FILE *out, uint32_t omp_requires)
terminated by a NUL. */
for (size_t i = 0; i != len;)
{
+ file_idx.safe_push (i);
+
char c;
bool output_fn_ptr = false;
- file_idx[file_cnt++] = i;
fprintf (out, "static const char ptx_code_%u[] =\n\t\"", obj_count++);
while ((c = input[i++]))
@@ -349,6 +352,9 @@ process (FILE *in, FILE *out, uint32_t omp_requires)
}
}
+ const size_t file_cnt = file_idx.length ();
+ gcc_checking_assert (file_cnt == obj_count);
+
/* Create function-pointer array, required for reverse
offload function-pointer lookup. */