Skip to content

Commit

Permalink
Fix grpc build on glibc 2.30
Browse files Browse the repository at this point in the history
Closes bazelbuild#10285.

This applies this PR: [1] on grpc directory. To sync the grpc with the
latest release is outside of the scope of this CL.

[1] grpc/grpc#18950
  • Loading branch information
davido authored and laszlocsomor committed Nov 29, 2019
1 parent d3f8efc commit 302acaa
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 7 deletions.
3 changes: 2 additions & 1 deletion third_party/grpc/README.bazel.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
6. `rm -rf third_party/grpc/src/core/tsi/test_creds`
7. Update BUILD files by copying the rules from the BUILD file of gRPC;
fix macros in third_party/grpc/build_defs.bzl if necessary
8. Apply local patches if necessary: `patch -p3 < netinet_tcp_h.patch`
8. Apply local patches if necessary: `patch -p3 < netinet_tcp_h.patch`,
`patch -p1 < grpc-gettid.patch`
9. Update //third_party/nanopb if necessary


Expand Down
78 changes: 78 additions & 0 deletions third_party/grpc/grpc-gettid.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
From 57586a1ca7f17b1916aed3dea4ff8de872dbf853 Mon Sep 17 00:00:00 2001
From: Benjamin Peterson <[email protected]>
Date: Fri, 3 May 2019 08:11:00 -0700
Subject: [PATCH] Rename gettid() functions.

glibc 2.30 will declare its own gettid; see https://sourceware.org/git/?p=glibc.git;a=commit;h=1d0fc213824eaa2a8f8c4385daaa698ee8fb7c92. Rename the grpc versions to avoid naming conflicts.
---
src/core/lib/gpr/log_linux.cc | 6 ++----
src/core/lib/gpr/log_posix.cc | 4 ++--
src/core/lib/iomgr/ev_epollex_linux.cc | 4 ++--
3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/core/lib/gpr/log_linux.cc b/src/core/lib/gpr/log_linux.cc
index 81026e5689b..8b597b4cf2f 100644
--- a/src/core/lib/gpr/log_linux.cc
+++ b/src/core/lib/gpr/log_linux.cc
@@ -40,7 +40,7 @@
#include <time.h>
#include <unistd.h>

-static long gettid(void) { return syscall(__NR_gettid); }
+static long sys_gettid(void) { return syscall(__NR_gettid); }

void gpr_log(const char* file, int line, gpr_log_severity severity,
const char* format, ...) {
@@ -70,7 +70,7 @@ void gpr_default_log(gpr_log_func_args* args) {
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
struct tm tm;
static __thread long tid = 0;
- if (tid == 0) tid = gettid();
+ if (tid == 0) tid = sys_gettid();

timer = static_cast<time_t>(now.tv_sec);
final_slash = strrchr(args->file, '/');
diff --git a/src/core/lib/gpr/log_posix.cc b/src/core/lib/gpr/log_posix.cc
index b6edc14ab6b..2f7c6ce3760 100644
--- a/src/core/lib/gpr/log_posix.cc
+++ b/src/core/lib/gpr/log_posix.cc
@@ -31,7 +31,7 @@
#include <string.h>
#include <time.h>

-static intptr_t gettid(void) { return (intptr_t)pthread_self(); }
+static intptr_t sys_gettid(void) { return (intptr_t)pthread_self(); }

void gpr_log(const char* file, int line, gpr_log_severity severity,
const char* format, ...) {
@@ -86,7 +86,7 @@ void gpr_default_log(gpr_log_func_args* args) {
char* prefix;
gpr_asprintf(&prefix, "%s%s.%09d %7" PRIdPTR " %s:%d]",
gpr_log_severity_string(args->severity), time_buffer,
- (int)(now.tv_nsec), gettid(), display_file, args->line);
+ (int)(now.tv_nsec), sys_gettid(), display_file, args->line);

fprintf(stderr, "%-70s %s\n", prefix, args->message);
gpr_free(prefix);
diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc
index c2d80c08ddb..4a83cb6c215 100644
--- a/src/core/lib/iomgr/ev_epollex_linux.cc
+++ b/src/core/lib/iomgr/ev_epollex_linux.cc
@@ -1077,7 +1077,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
}

#ifndef NDEBUG
-static long gettid(void) { return syscall(__NR_gettid); }
+static long sys_gettid(void) { return syscall(__NR_gettid); }
#endif

/* pollset->mu lock must be held by the caller before calling this.
@@ -1097,7 +1097,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
#define WORKER_PTR (&worker)
#endif
#ifndef NDEBUG
- WORKER_PTR->originator = gettid();
+ WORKER_PTR->originator = sys_gettid();
#endif
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO,
4 changes: 2 additions & 2 deletions third_party/grpc/src/core/lib/gpr/log_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <time.h>
#include <unistd.h>

static long gettid(void) { return syscall(__NR_gettid); }
static long sys_gettid(void) { return syscall(__NR_gettid); }

void gpr_log(const char* file, int line, gpr_log_severity severity,
const char* format, ...) {
Expand Down Expand Up @@ -70,7 +70,7 @@ void gpr_default_log(gpr_log_func_args* args) {
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
struct tm tm;
static __thread long tid = 0;
if (tid == 0) tid = gettid();
if (tid == 0) tid = sys_gettid();

timer = static_cast<time_t>(now.tv_sec);
final_slash = strrchr(args->file, '/');
Expand Down
4 changes: 2 additions & 2 deletions third_party/grpc/src/core/lib/gpr/log_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <string.h>
#include <time.h>

static intptr_t gettid(void) { return (intptr_t)pthread_self(); }
static intptr_t sys_gettid(void) { return (intptr_t)pthread_self(); }

void gpr_log(const char* file, int line, gpr_log_severity severity,
const char* format, ...) {
Expand Down Expand Up @@ -85,7 +85,7 @@ void gpr_default_log(gpr_log_func_args* args) {
char* prefix;
gpr_asprintf(&prefix, "%s%s.%09d %7tu %s:%d]",
gpr_log_severity_string(args->severity), time_buffer,
(int)(now.tv_nsec), gettid(), display_file, args->line);
(int)(now.tv_nsec), sys_gettid(), display_file, args->line);

fprintf(stderr, "%-70s %s\n", prefix, args->message);
gpr_free(prefix);
Expand Down
4 changes: 2 additions & 2 deletions third_party/grpc/src/core/lib/iomgr/ev_epollex_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
}

#ifndef NDEBUG
static long gettid(void) { return syscall(__NR_gettid); }
static long sys_gettid(void) { return syscall(__NR_gettid); }
#endif

/* pollset->mu lock must be held by the caller before calling this.
Expand All @@ -1170,7 +1170,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
#define WORKER_PTR (&worker)
#endif
#ifndef NDEBUG
WORKER_PTR->originator = gettid();
WORKER_PTR->originator = sys_gettid();
#endif
if (grpc_polling_trace.enabled()) {
gpr_log(GPR_INFO,
Expand Down

0 comments on commit 302acaa

Please sign in to comment.