Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build issues with gcc version 6.2.0 20161005 (Ubuntu 6.2.0-5ubuntu12) #782

Closed
ColinIanKing opened this issue Oct 25, 2016 · 10 comments

Comments

@ColinIanKing
Copy link
Contributor

commented Oct 25, 2016

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)

@simevo

This comment has been minimized.

Copy link

commented Oct 28, 2016

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 ..

@ColinIanKing

This comment has been minimized.

Copy link
Contributor Author

commented Oct 28, 2016

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

@simevo

This comment has been minimized.

Copy link

commented Oct 28, 2016

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 ...

@ColinIanKing

This comment has been minimized.

Copy link
Contributor Author

commented Oct 28, 2016

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.

@jepio

This comment has been minimized.

Copy link

commented Nov 8, 2016

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.

@ColinIanKing

This comment has been minimized.

Copy link
Contributor Author

commented Nov 14, 2016

That does the trick for me! Thanks!

@mkevac

This comment has been minimized.

Copy link

commented Feb 14, 2017

Hi. Can we merge this?

goldshtn added a commit that referenced this issue Jun 8, 2017

Fix ld error due to debian/ubuntu -pie default
Fixes #782. Solution taken verbatim from @jepio here:

#782 (comment)

I ran into the same issue attempting to compile from source on
a fresh Ubuntu 16.10/Yakkety host:

Linking C executable bcc-lua
/usr/bin/ld: 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

Build succeeded after patch was applied.
@prakashsurya

This comment has been minimized.

Copy link

commented Aug 22, 2017

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

@yonghong-song

This comment has been minimized.

Copy link
Collaborator

commented Aug 22, 2017

@yonghong-song

This comment has been minimized.

Copy link
Collaborator

commented Aug 23, 2017

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.