Skip to content

Build of envoy-static fails when system has libunwind installed. #1069

Closed

Description

@jrajahalme

Envoy build fails when the build system has libunwind installed:

ERROR: /home/vagrant/dev/envoy/source/exe/BUILD:17:1: Linking of rule '//source/exe:envoy-static' failed: Process exited with status 1 [sandboxed].
src/stacktrace_libunwind-inl.h:110: error: undefined reference to '_Ux86_64_getcontext'
src/stacktrace_libunwind-inl.h:114: error: undefined reference to '_ULx86_64_init_local'
src/stacktrace_libunwind-inl.h:118: error: undefined reference to '_ULx86_64_step'
src/stacktrace_libunwind-inl.h:136: error: undefined reference to '_ULx86_64_step'
src/stacktrace_libunwind-inl.h:129: error: undefined reference to '_ULx86_64_get_reg'
src/stacktrace_libunwind-inl.h:110: error: undefined reference to '_Ux86_64_getcontext'
src/stacktrace_libunwind-inl.h:114: error: undefined reference to '_ULx86_64_init_local'
src/stacktrace_libunwind-inl.h:118: error: undefined reference to '_ULx86_64_step'
src/stacktrace_libunwind-inl.h:136: error: undefined reference to '_ULx86_64_step'
src/stacktrace_libunwind-inl.h:129: error: undefined reference to '_ULx86_64_get_reg'
src/stacktrace_libunwind-inl.h:110: error: undefined reference to '_Ux86_64_getcontext'
src/stacktrace_libunwind-inl.h:114: error: undefined reference to '_ULx86_64_init_local'
src/stacktrace_libunwind-inl.h:122: error: undefined reference to '_ULx86_64_get_reg'
src/stacktrace_libunwind-inl.h:141: error: undefined reference to '_ULx86_64_get_reg'
src/stacktrace_libunwind-inl.h:110: error: undefined reference to '_Ux86_64_getcontext'
src/stacktrace_libunwind-inl.h:114: error: undefined reference to '_ULx86_64_init_local'
collect2: error: ld returned 1 exit status
Use --strategy=CppLink=standalone to disable sandboxing for the failing actions.
Target //source/exe:envoy-static failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 2.294s, Critical Path: 1.47s
$ 

This is due to glog, which in this case uses libunwind, but fails to add it to the link options, see glog issue 207. That issue has a proposed patch that fixes this, but in the meanwhile I have locally solved this by:

diff --git a/bazel/envoy_build_system.bzl b/bazel/envoy_build_system.bzl
index f176710..083289e 100644
--- a/bazel/envoy_build_system.bzl
+++ b/bazel/envoy_build_system.bzl
@@ -121,6 +121,7 @@ def envoy_cc_binary(name,
         linkopts = [
             "-pthread",
             "-lrt",
+           "-lunwind",
             # Force MD5 hash in build. This is part of the workaround for
             # https://github.com/bazelbuild/bazel/issues/2805. Bazel actually
             # does this by itself prior to
@@ -170,7 +171,7 @@ def envoy_cc_test(name,
         copts = envoy_copts(repository, test = True),
         # TODO(mattklein123): It's not great that we universally link against the following libs.
         # In particular, -latomic is not needed on all platforms. Make this more granular.
-        linkopts = ["-pthread", "-latomic"],
+        linkopts = ["-lunwind", "-pthread", "-latomic"],
         linkstatic = 1,
         malloc = tcmalloc_external_dep(repository),
         deps = [

Activity

  1. mattklein123 commented on Jun 8, 2017

    @mattklein123
    Member

    We are removing glog in #1061. Will just merge it now.

  2. mattklein123 commented on Jun 8, 2017

    @mattklein123
    Member

    Merged. Closing.

  3. jrajahalme commented on Jun 9, 2017

    @jrajahalme
    ContributorAuthor

    Unfortunately also tcmalloc links to unwind if it is found at configure time, I had to do the following to get envoy to link:

    diff --git a/ci/build_container/build_recipes/gperftools.sh b/ci/build_container/build_recipes/gperftools.sh
    index 78da24c..21867c7 100755
    --- a/ci/build_container/build_recipes/gperftools.sh
    +++ b/ci/build_container/build_recipes/gperftools.sh
    @@ -7,5 +7,5 @@ VERSION=2.5
     wget -O gperftools-$VERSION.tar.gz https://github.com/gperftools/gperftools/releases/download/gperftools-$VERSION/gperftools-$VERSION.tar.gz
     tar xf gperftools-$VERSION.tar.gz
     cd gperftools-$VERSION
    -LDFLAGS="-lpthread" ./configure --prefix=$THIRDPARTY_BUILD --enable-shared=no --enable-frame-pointers
    +LDFLAGS="-lpthread" ./configure --prefix=$THIRDPARTY_BUILD --enable-shared=no --enable-frame-pointers --disable-libunwind
     make V=1 install
    

    libunwind is disabled for gperftools by default on ARM and OSX. My reading of the configure.ac is that when frame pointers are available libunwind is not needed. We explicitly enable frame pointers already, so this change should be harmless. With this change envoy now builds both in the docker image and on my VM.

  4. jrajahalme commented on Jun 9, 2017

    @jrajahalme
    ContributorAuthor

    Not sure if anyone sees comments on closed issues, so I opened a new one (#1071).

  5. lizan commented on Jun 9, 2017

    @lizan
    Member

    This was the problem that @qiwzhang faced before.

    I don't think #1061 resolved this, since glog was never involved in any real build targets yet. @mattklein123 can reopen the issue.

  6. mattklein123 commented on Jun 9, 2017

    @mattklein123
    Member

    We can just work from the other issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions