Bcc: build issues with gcc version 6.2.0 20161005 (Ubuntu 6.2.0-5ubuntu12)

Created on 25 Oct 2016  Â·  10Comments  Â·  Source: iovisor/bcc

Hitting some issues with gcc 6.2:

[ 87%] Linking C executable bcc-lua
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libluajit-5.1.a(ljamalg.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
src/lua/CMakeFiles/bcc-lua.dir/build.make:189: recipe for target 'src/lua/bcc-lua' failed
make[2]: ** [src/lua/bcc-lua] Error 1
CMakeFiles/Makefile2:673: recipe for target 'src/lua/CMakeFiles/bcc-lua.dir/all' failed
make[1]: *
* [src/lua/CMakeFiles/bcc-lua.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 6.2.0-5ubuntu12' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 6.2.0 20161005 (Ubuntu 6.2.0-5ubuntu12)

Most helpful comment

The problem is the --enable-default-pie flag that debian/ubuntu seem to configure gcc with. If they want to do that then they better be building all libs (including static ones) position independent.

Try the following patch:

diff --git a/src/lua/CMakeLists.txt b/src/lua/CMakeLists.txt
index 97e2bb4..6ad0e87 100644
--- a/src/lua/CMakeLists.txt
+++ b/src/lua/CMakeLists.txt
@@ -24,6 +24,7 @@ if (LUAJIT_LIBRARIES AND LUAJIT)
        set_target_properties(bcc-lua PROPERTIES LINKER_LANGUAGE C)
        target_link_libraries(bcc-lua ${LUAJIT_LIBRARIES})
        target_link_libraries(bcc-lua -Wl,--whole-archive bcc-static -Wl,--no-whole-archive)
+       target_link_libraries(bcc-lua -no-pie)

        install(TARGETS bcc-lua RUNTIME DESTINATION bin)
 endif()

@simevo's suggestion causes dynamic linking to libluajit instead, which goes against the goal of bcc to have as few runtime dependencies as possible.

All 10 comments

during the build (launched with dpkg-buildpackage -uc -us) it gets stuck when this command is executed in obj-x86_64-linux-gnu/src/lua:

/usr/bin/cc  -g -O2 -fdebug-prefix-map=/root/bcc/bcc_0.2.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -Wall -O3 -DNDEBUG   -Wl,-z,relro CMakeFiles/bcc-lua.dir/src/main.c.o bcc.o  -o bcc-lua -rdynamic -Wl,-Bstatic -lluajit-5.1 -Wl,-Bdynamic -ldl -lm -Wl,--whole-archive ../cc/libbcc.a -Wl,--no-whole-archive ../cc/frontends/b/libb_frontend.a ../cc/frontends/clang/libclang_frontend.a ../cc/libbcc-loader-static.a /usr/lib/llvm-3.8/lib/libclangFrontend.a /usr/lib/llvm-3.8/lib/libclangSerialization.a /usr/lib/llvm-3.8/lib/libclangDriver.a

if I modify the command as in:

/usr/bin/cc  -g -O2 -fdebug-prefix-map=/root/bcc/bcc_0.2.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -Wall -O3 -DNDEBUG  -Wl,-z,relro CMakeFiles/bcc-lua.dir/src/main.c.o bcc.o -o bcc-lua -lluajit-5.1 -ldl -lm ../cc/libbcc.a ../cc/frontends/b/libb_frontend.a ../cc/frontends/clang/libclang_frontend.a ../cc/libbcc-loader-static.a /usr/lib/llvm-3.8/lib/libclangFrontend.a /usr/lib/llvm-3.8/lib/libclangSerialization.a /usr/lib/llvm-3.8/lib/libclangDriver.a -lstdc++

it does link successfully and the produced executable runs:

./bcc-lua --version
./bcc-lua HEAD -- Running on LuaJIT 2.0.4 (Linux/x64)

not sure if all the changes I have made are OK and how to tell cmake though ..

Any ideas on how to enable -fPIC in the cmake rules? I'm not having any success as I'm not a cmake expert.

Me neither ! the point of my comment above is that it should not be necessary to add the -fPIC option to libluajit-5.1.a (this library is provided by the libluajit-5.1-dev package) but a change to the linker commands when linking bcc-lua is enough.

We still need the cmake expert to do that though ...

Ah, OK, understood. As it stands, this is a bit of a blocker for me on newer versions of Ubuntu because of the new tool chain.

The problem is the --enable-default-pie flag that debian/ubuntu seem to configure gcc with. If they want to do that then they better be building all libs (including static ones) position independent.

Try the following patch:

diff --git a/src/lua/CMakeLists.txt b/src/lua/CMakeLists.txt
index 97e2bb4..6ad0e87 100644
--- a/src/lua/CMakeLists.txt
+++ b/src/lua/CMakeLists.txt
@@ -24,6 +24,7 @@ if (LUAJIT_LIBRARIES AND LUAJIT)
        set_target_properties(bcc-lua PROPERTIES LINKER_LANGUAGE C)
        target_link_libraries(bcc-lua ${LUAJIT_LIBRARIES})
        target_link_libraries(bcc-lua -Wl,--whole-archive bcc-static -Wl,--no-whole-archive)
+       target_link_libraries(bcc-lua -no-pie)

        install(TARGETS bcc-lua RUNTIME DESTINATION bin)
 endif()

@simevo's suggestion causes dynamic linking to libluajit instead, which goes against the goal of bcc to have as few runtime dependencies as possible.

That does the trick for me! Thanks!

Hi. Can we merge this?

Hi, I appear to be hitting this issue when building on Ubuntu 17.04, is this expected? I can workaround it by applying the following patch:

diff --git a/src/lua/CMakeLists.txt b/src/lua/CMakeLists.txt
index 09e456d..48378ea 100644
--- a/src/lua/CMakeLists.txt
+++ b/src/lua/CMakeLists.txt
@@ -27,7 +27,7 @@ if (LUAJIT_LIBRARIES AND LUAJIT)
   if (CMAKE_C_COMPILER_ID MATCHES "Clang")
     target_link_libraries(bcc-lua -nopie)
   else()
-    target_link_libraries(bcc-lua --no-pie)
+    target_link_libraries(bcc-lua -no-pie)
   endif()

        install(TARGETS bcc-lua RUNTIME DESTINATION bin)

should I open a new bug? I'm building from source, using commit: https://github.com/iovisor/bcc/commit/db8353b25fc69b617ce0afc3b9e600e3d0625582

Looks like the robust way is to have runtime test which of -no-pie and
--no-pie is supported and use it.
I will try to come up with a solution. There is no need to open a new bug
for this.

On Tue, Aug 22, 2017 at 3:23 PM, Prakash Surya notifications@github.com
wrote:

Hi, I appear to be hitting this issue when building on Ubuntu 17.04, is
this expected? I can workaround it by applying the following patch:

diff --git a/src/lua/CMakeLists.txt b/src/lua/CMakeLists.txt
index 09e456d..48378ea 100644
--- a/src/lua/CMakeLists.txt
+++ b/src/lua/CMakeLists.txt
@@ -27,7 +27,7 @@ if (LUAJIT_LIBRARIES AND LUAJIT)
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
target_link_libraries(bcc-lua -nopie)
else()
- target_link_libraries(bcc-lua --no-pie)
+ target_link_libraries(bcc-lua -no-pie)
endif()

    install(TARGETS bcc-lua RUNTIME DESTINATION bin)

should I open a new bug? I'm building from source, using commit: db8353b
https://github.com/iovisor/bcc/commit/db8353b25fc69b617ce0afc3b9e600e3d0625582

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/iovisor/bcc/issues/782#issuecomment-324168453, or mute
the thread
https://github.com/notifications/unsubscribe-auth/ALq6omtUX8YwedVGcXvztqAmFgWJ2SfTks5sa1TLgaJpZM4Kfyah
.

@prakashsurya I have a patch which tries to fix this issue with cmake try_compile. Could you check whether this fixed your issue or not?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aaron-ai picture aaron-ai  Â·  8Comments

paipanka picture paipanka  Â·  6Comments

alvenwong picture alvenwong  Â·  7Comments

brendangregg picture brendangregg  Â·  4Comments

brendangregg picture brendangregg  Â·  4Comments