Skip to content

Commit 28668e0

Browse files
committed
Port abseil to GNU/Hurd.
abseil has failed to build on GNU/Hurd for a long time. Now let's make it work! :) Note that `__GNU__` is the macro for detecting GNU/Hurd. And `__MACH__` is also defined there besides on Apple platform. They are both "mach" but with different implementation and platform details. Here are the works, * Mark platform features (not) supported by GNU/Hurd. * Supports `mmap` and `write`. * Not supports `vdso`. It's specific to Linux. * Not supports `ELF_SYMBOLIZE` for now. GNU/Hurd uses ELF as the binary format. But symbolizing in abseil relies on reading object file path from `/proc/self/task/<pid>/maps` (Linux specific) or `/proc/self/maps`. GNU/Hurd does have the latter. However, due to its micro-kernel design, it's currently unable to get the file path info there. * Disable stack consumption measurement. The problem behind it is that GNU/Hurd uses a very different way to implement signal handling. Due to compiler behavior, it is impossible to get a stable, valid and reliable statictic data. In my test environment, it's 96 bytes (< 100) for current codes. * GNU/Hurd uses different errno and messages than Linux. So related things are adjusted accordingly. * Fix a misuse of `__MACH__`, which should actually be `__APPLE__`. * Fix a missing including of `signal.h` for using `SIGABRT`. Otherwise compilation will fail with undefined symbol error on GNU/Hurd. Signed-off-by: Yuqian Yang <crupest@crupest.life>
1 parent 860dcf1 commit 28668e0

File tree

9 files changed

+19
-10
lines changed

9 files changed

+19
-10
lines changed

absl/base/config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,8 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
380380
defined(__asmjs__) || defined(__EMSCRIPTEN__) || defined(__Fuchsia__) || \
381381
defined(__sun) || defined(__myriad2__) || defined(__HAIKU__) || \
382382
defined(__OpenBSD__) || defined(__NetBSD__) || defined(__QNX__) || \
383-
defined(__VXWORKS__) || defined(__hexagon__) || defined(__XTENSA__)
383+
defined(__VXWORKS__) || defined(__hexagon__) || defined(__XTENSA__) || \
384+
defined(__GNU__)
384385
#define ABSL_HAVE_MMAP 1
385386
#endif
386387

absl/base/internal/raw_logging.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
4545
defined(__hexagon__) || defined(__Fuchsia__) || \
4646
defined(__native_client__) || defined(__OpenBSD__) || \
47-
defined(__EMSCRIPTEN__) || defined(__ASYLO__)
47+
defined(__EMSCRIPTEN__) || defined(__ASYLO__) || defined(__GNU__)
4848

4949
#include <unistd.h>
5050

absl/base/internal/strerror_test.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ TEST(StrErrorTest, ValidErrorCode) {
3939
TEST(StrErrorTest, InvalidErrorCode) {
4040
errno = ERANGE;
4141
EXPECT_THAT(absl::base_internal::StrError(-1),
42-
AnyOf(Eq("No error information"), Eq("Unknown error -1")));
42+
AnyOf(Eq("No error information"),
43+
Eq("Unknown error -1"),
44+
Eq("Error in unknown error system: FFFFFFFF")));
4345
EXPECT_THAT(errno, Eq(ERANGE));
4446
}
4547

absl/debugging/internal/stack_consumption.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
#ifdef ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION
2626
#error ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION cannot be set directly
2727
#elif !defined(__APPLE__) && !defined(_WIN32) && !defined(__Fuchsia__) && \
28-
(defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || \
28+
!defined(__GNU__) && \
29+
(defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || \
2930
defined(__aarch64__) || defined(__riscv))
3031
#define ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION 1
3132

absl/debugging/internal/symbolize.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#ifdef ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE
3030
#error ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE cannot be directly set
3131
#elif defined(__ELF__) && defined(__GLIBC__) && !defined(__native_client__) \
32-
&& !defined(__asmjs__) && !defined(__wasm__)
32+
&& !defined(__asmjs__) && !defined(__wasm__) && !defined(__GNU__)
3333
#define ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE 1
3434

3535
#include <elf.h>

absl/debugging/internal/vdso_support.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
#ifdef ABSL_HAVE_VDSO_SUPPORT
5050
#error ABSL_HAVE_VDSO_SUPPORT cannot be directly set
51-
#else
51+
#elif !defined(__GNU__)
5252
#define ABSL_HAVE_VDSO_SUPPORT 1
5353
#endif
5454

absl/log/internal/test_helpers.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <zircon/syscalls.h>
1919
#endif
2020

21+
#include <signal.h>
22+
2123
#include "gtest/gtest.h"
2224
#include "absl/base/config.h"
2325
#include "absl/base/log_severity.h"

absl/log/log_modifier_methods_test.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,16 @@ TEST(TailCallsModifiesTest, WithPerror) {
181181
Send(AllOf(
182182
TextMessage(AnyOf(Eq("hello world: Bad file number [9]"),
183183
Eq("hello world: Bad file descriptor [9]"),
184-
Eq("hello world: Bad file descriptor [8]"))),
184+
Eq("hello world: Bad file descriptor [8]"),
185+
Eq("hello world: Bad file descriptor [1073741833]"))),
185186
ENCODED_MESSAGE(HasValues(ElementsAre(
186187
ValueWithLiteral(Eq("hello world")), ValueWithLiteral(Eq(": ")),
187188
AnyOf(ValueWithStr(Eq("Bad file number")),
188189
ValueWithStr(Eq("Bad file descriptor"))),
189190
ValueWithLiteral(Eq(" [")),
190-
AnyOf(ValueWithStr(Eq("8")), ValueWithStr(Eq("9"))),
191+
AnyOf(ValueWithStr(Eq("8")),
192+
ValueWithStr(Eq("9")),
193+
ValueWithStr(Eq("1073741833"))),
191194
ValueWithLiteral(Eq("]"))))))));
192195

193196
test_sink.StartCapturingLogs();

absl/log/stripping_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#include <stdio.h>
3535

36-
#if defined(__MACH__)
36+
#if defined(__APPLE__)
3737
#include <mach-o/dyld.h>
3838
#elif defined(_WIN32)
3939
#include <Windows.h>
@@ -191,7 +191,7 @@ class StrippingTest : public ::testing::Test {
191191
absl::FPrintF(stderr, "Failed to open /pkg/bin/<binary name>: %s\n", err);
192192
}
193193
return fp;
194-
#elif defined(__MACH__)
194+
#elif defined(__APPLE__)
195195
uint32_t size = 0;
196196
int ret = _NSGetExecutablePath(nullptr, &size);
197197
if (ret != -1) {

0 commit comments

Comments
 (0)