From 096164229a4c2d1efab9f259f50be1bdcdfc8abd Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Thu, 17 Dec 2020 05:57:13 -0800 Subject: 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. --- c++tools/resolver.cc | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'c++tools/resolver.cc') 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 #include +#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 +#define MAPPED_READING 1 +#else +#define MAPPED_READING 0 +#endif +#endif +#endif + #include #include +#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; } -- cgit v1.1