aboutsummaryrefslogtreecommitdiff
path: root/c++tools/resolver.cc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2020-12-17 05:57:13 -0800
committerNathan Sidwell <nathan@acm.org>2020-12-17 05:57:13 -0800
commit096164229a4c2d1efab9f259f50be1bdcdfc8abd (patch)
tree0b12ffe2253c9c39b900696978b1b86f09927d32 /c++tools/resolver.cc
parent5357b1620c547a6f2bd81e7868c800e2eee97e51 (diff)
downloadgcc-096164229a4c2d1efab9f259f50be1bdcdfc8abd.zip
gcc-096164229a4c2d1efab9f259f50be1bdcdfc8abd.tar.gz
gcc-096164229a4c2d1efab9f259f50be1bdcdfc8abd.tar.bz2
bootstrap: Fix some windows issues [PR 98300]
When breaking out the sample server from the gcc/cp directory, it lost its check for mmap, and the sample resolver just assumed it was there. Fixed thusly. The non-mapping paths in module.cc weren't (recently) excercised, and led to a signedness warning. Finally I'd missed c++tools's config.h.in in the gcc_update script. There I took the opportunity of adding a 'tools' segment of the dependency lists. PR bootstrap/98300 contrib/ * gcc_update: Add c++tools/config.h.in. c++tools/ * configure.ac: Check for sys/mman.h. * resolver.cc: Don't assume mmap, O_CLOEXEC are available. Use xmalloc. * config.h.in: Regenerated. * configure: Regenerated. gcc/cp/ * module.cc: Fix ::read, ::write result signedness comparisons.
Diffstat (limited to 'c++tools/resolver.cc')
-rw-r--r--c++tools/resolver.cc41
1 files changed, 40 insertions, 1 deletions
diff --git a/c++tools/resolver.cc b/c++tools/resolver.cc
index 5028d2a..c8d3115 100644
--- a/c++tools/resolver.cc
+++ b/c++tools/resolver.cc
@@ -28,10 +28,36 @@ along with GCC; see the file COPYING3. If not see
// OS
#include <fcntl.h>
#include <unistd.h>
+#if 0 // 1 for testing no mmap
+#define MAPPED_READING 0
+#else
+#ifdef IN_GCC
+#if HAVE_MMAP_FILE && _POSIX_MAPPED_FILES > 0
+#define MAPPED_READING 1
+#else
+#define MAPPED_READING 0
+#endif
+#else
+#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
+#define MAPPED_READING 1
+#else
+#define MAPPED_READING 0
+#endif
+#endif
+#endif
+
#include <sys/types.h>
#include <sys/stat.h>
+#if !defined (IN_GCC) && !MAPPED_READING
+#define xmalloc(X) malloc(X)
+#endif
+
+#if !HOST_HAS_O_CLOEXEC
+#define O_CLOEXEC 0
+#endif
+
#ifndef DIR_SEPARATOR
#define DIR_SEPARATOR '/'
#endif
@@ -81,11 +107,20 @@ module_resolver::read_tuple_file (int fd, char const *prefix, bool force)
if (!stat.st_size)
return 0;
+ void *buffer = nullptr;
+#if MAPPED_READING
// Just map the file, we're gonna read all of it, so no need for
// line buffering
- void *buffer = mmap (nullptr, stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+ buffer = mmap (nullptr, stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (buffer == MAP_FAILED)
return -errno;
+#else
+ buffer = xmalloc (stat.st_size);
+ if (!buffer)
+ return -errno;
+ if (read (fd, buffer, stat.st_size) != stat.st_size)
+ return -errno;
+#endif
size_t prefix_len = prefix ? strlen (prefix) : 0;
unsigned lineno = 0;
@@ -144,7 +179,11 @@ module_resolver::read_tuple_file (int fd, char const *prefix, bool force)
}
}
+#if MAPPED_READING
munmap (buffer, stat.st_size);
+#else
+ free (buffer);
+#endif
return 0;
}