New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 661171 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Last visit > 30 days ago
Closed: Nov 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: ----

Blocking:
issue 656046



Sign in to add a comment

libblimp_net.cr.so doesn't link in x64 debug component builds with clang

Project Member Reported by thakis@chromium.org, Nov 1 2016

Issue description

$ cat out/gnand4//args.gn 
target_os = "android"
is_clang = true
symbol_level = 1
is_component_build = true
use_goma = true
target_cpu = "x64"

$ ninja -C out/gnand4 libblimp_net.cr.so -j500
ninja: Entering directory `out/gnand4'
[1/1] Regenerating ninja files
[14888/14888] SOLINK ./libblimp_net.cr.so
FAILED: libblimp_net.cr.so libblimp_net.cr.so.TOC lib.unstripped/libblimp_net.cr.so 
python "/usr/local/google/home/thakis/src/chrome/src/build/toolchain/gcc_solink_wrapper.py" --readelf="../../third_party/android_tools/ndk/toolchains/x86_64-4.9/prebuilt/linux-x86_64/bin/x86_64-linux-android-readelf" --nm="../../third_party/android_tools/ndk/toolchains/x86_64-4.9/prebuilt/linux-x86_64/bin/x86_64-linux-android-nm" --strip=../../third_party/android_tools/ndk/toolchains/x86_64-4.9/prebuilt/linux-x86_64/bin/x86_64-linux-android-strip --sofile="./lib.unstripped/libblimp_net.cr.so" --tocfile="./libblimp_net.cr.so.TOC" --output="./libblimp_net.cr.so"  -- ../../third_party/llvm-build/Release+Asserts/bin/clang++ -shared -Wl,--fatal-warnings -fPIC -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro -Wl,-z,defs -Wl,--as-needed --gcc-toolchain=../../third_party/android_tools/ndk/toolchains/x86_64-4.9/prebuilt/linux-x86_64 -fuse-ld=gold -Wl,--icf=all -Wl,--build-id=sha1 -Wl,--no-undefined -Wl,--exclude-libs=libgcc.a -Wl,--exclude-libs=libc++_static.a -Wl,--exclude-libs=libvpx_assembly_arm.a --target=x86_64-linux-androideabi -m64 -nostdlib -Wl,--warn-shared-textrel --sysroot=../../third_party/android_tools/ndk/platforms/android-21/arch-x86_64  -Wl,-wrap,calloc -Wl,-wrap,free -Wl,-wrap,malloc -Wl,-wrap,memalign -Wl,-wrap,posix_memalign -Wl,-wrap,pvalloc -Wl,-wrap,realloc -Wl,-wrap,valloc -L../../third_party/android_tools/ndk/sources/cxx-stl/llvm-libc++/libs/x86_64 -o "./lib.unstripped/libblimp_net.cr.so" -Wl,-soname="libblimp_net.cr.so" @"./libblimp_net.cr.so.rsp"
../../third_party/android_tools/ndk/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld.gold: error: symbol memcpy has undefined version GLIBC_2.2.5
../../third_party/grpc/src/core/lib/support/wrap_memcpy.c:46: error: undefined reference to 'memcpy', version 'GLIBC_2.2.5'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.


Works fine with gcc for some reason. Also works fine in release builds with both compilers.
 
It looks like blimp is the only client of grpc.
Cc: xyzzyz@chromium.org
Owner: xyzzyz@chromium.org
Status: Assigned (was: Untriaged)
This makes things go:

~/src/chrome/src/third_party/grpc$ git diff
diff --git a/BUILD.gn b/BUILD.gn
index 4490add..88f76ae 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -27,6 +27,7 @@ config("grpc_config") {
   cflags_c = [
     "-std=c99"
   ]
+  ldflags = [ "-Wl,-wrap,memcpy" ]
   
   if (is_android) {
     libs = [ "log" ] # For __android_log_write


But maybe not including wrap_memcpy.cc in the build is better. xyzzyz, giving this to you, you probably have a better idea what exactly to do here.  This blocks moving chrome/android/x64 to clang by default, so please take a look.


cc primiano since it interacts a bit with https://cs.chromium.org/chromium/src/base/allocator/BUILD.gn?dr=C&q=wrap,memalign&sq=package:chromium&l=294
Cc: primiano@chromium.org
actually cc primiano
Right now we don't have any wrapping and everything works. Would be great to avoid wrapping memcpy unless we really really have to.
The thing that is not clear to me right now is: how come that code doesn't fail on gcc? Maybe Android's gcc just drops the @GLIBC_2.2.5 versioning on the floor?
Happy to help, trying to build right now.

Ahh I see what's happening. GCC ends up optimizing the memcpy call with a builtin which drops any dynamic symbol requirement. clang does not.

$ objdump -d out/x64_clang/obj/third_party/grpc/gpr/wrap_memcpy.o
0000000000000000 <__wrap_memcpy>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   53                      push   %rbx
   5:   50                      push   %rax
   6:   48 89 fb                mov    %rdi,%rbx
   9:   e8 00 00 00 00          callq  e <__wrap_memcpy+0xe>
   e:   48 89 d8                mov    %rbx,%rax
  11:   48 83 c4 08             add    $0x8,%rsp
  15:   5b                      pop    %rbx
  16:   5d                      pop    %rbp
  17:   c3                      retq
$ nm out/x64_clang/obj/third_party/grpc/gpr/wrap_memcpy.o
0000000000000000 T __wrap_memcpy
                 U memcpy@GLIBC_2.2.5


$ objdump -d out/x64_gcc/obj/third_party/grpc/gpr/wrap_memcpy.o
0000000000000000 <__wrap_memcpy>:
   0:   55                      push   %rbp
   1:   48 89 f8                mov    %rdi,%rax
   4:   48 89 d1                mov    %rdx,%rcx
   7:   f3 a4                   rep movsb %ds:(%rsi),%es:(%rdi)
   9:   48 89 e5                mov    %rsp,%rbp
   c:   5d                      pop    %rbp
   d:   c3                      retq

$ nm out/x64_gcc/obj/third_party/grpc/gpr/wrap_memcpy.o
0000000000000000 T __wrap_memcpy

So, because of this, it looks to me that:
- that grpc code is unaware of Android and should be fixed upstream.
- so far we were practically ignorning that piece of code. I chatted a bit offline with thakis@. the best thing is to just exclude memcpy.c from the GN build file.
Forgot to say that this is very likely the last thing keeping compile on https://build.chromium.org/p/chromium.fyi/builders/ClangToTAndroid%20x64 red
Owner: gcasto@chromium.org
Ehm changing that BUILD.gn seems quite complicated.
The BUILD.gn is part of the third_party/grpc project. The file itself is autogenerated from a templates/BUILD.gn.template

I was trying to just get this:
-----
index 4490add..eb489d0 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -139,6 +139,11 @@ source_set("gpr") {
     "src/core/lib/support/tmpfile_windows.c",
     "src/core/lib/support/wrap_memcpy.c",
   ]
+  if (is_android) {
+    # gRPC memcpy wrapping logic isn't Android-friendly.
+    # See  https://crbug.com/661171  .
+    sources -= [ "src/core/lib/support/wrap_memcpy.c" ]
+  }
   deps = [
   ]
   configs -= [ "//build/config/compiler:chromium_code" ]
-----

But looks not that trivial. can somebody familiar with that workflow do that? I confirm that the target compiles with that change, both with gcc and clang.
Sure, I'll get to this in a few minutes.
Project Member

Comment 12 by bugdroid1@chromium.org, Nov 1 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/fbad888c3366b08ff3b8253b0c3b52e440015d50

commit fbad888c3366b08ff3b8253b0c3b52e440015d50
Author: gcasto <gcasto@chromium.org>
Date: Tue Nov 01 21:16:31 2016

Rolls DEPS for gRPC to fix an Android and Clang compilation error

BUG= 661171 

Review-Url: https://codereview.chromium.org/2472513002
Cr-Commit-Position: refs/heads/master@{#429113}

[modify] https://crrev.com/fbad888c3366b08ff3b8253b0c3b52e440015d50/DEPS

Status: Fixed (was: Assigned)
Should be fixed now. gRPC repo change was https://codereview.chromium.org/2471543002/.
Project Member

Comment 14 by bugdroid1@chromium.org, Dec 9 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/ff8a991d4cbccf1c9eb893d3e7a310767fd18058

commit ff8a991d4cbccf1c9eb893d3e7a310767fd18058
Author: tzik <tzik@chromium.org>
Date: Fri Dec 09 09:48:07 2016

Roll gRPC for LLD link fix

BUG= 661171 

Review-Url: https://codereview.chromium.org/2561753002
Cr-Commit-Position: refs/heads/master@{#437507}

[modify] https://crrev.com/ff8a991d4cbccf1c9eb893d3e7a310767fd18058/DEPS

That last roll commit picked up https://codereview.chromium.org/2554783002

Sign in to add a comment