qitab / bazelisp

Support for compiling Common Lisp code using bazel.io
MIT License
58 stars 9 forks source link

/usr/bin/ld.gold: error: libsbcl.a(x86-64-assem.o): requires unsupported dynamic reloc 11; recompile with -fPIC #2

Open gonzojive opened 7 years ago

gonzojive commented 7 years ago

I wasn't able to compile a hello world example. See the following error:

$ bazel build //:hello                                                                                                                                                                                                                                                   
Loading:                                                                                                                                                                                                                                                                             
Loading: 0 packages loaded                                                                                                                                                                                                                                                           
Analyzing: target //:hello (9 packages loaded)                                                                                                                                                                                                                                       
Analyzing: target //:hello (9 packages loaded)                                                                                                                                                                                                                                       
Analyzing: target //:hello (9 packages loaded)                                                                                                                                                                                                                                       
Analyzing: target //:hello (9 packages loaded)                                                                                                                                                                                                                                       
Analyzing: target //:hello (9 packages loaded)                                                                                                                                                                                                                                       
Analyzing: target //:hello (9 packages loaded)                                                                                                                                                                                                                                       
Analyzing: target //:hello (9 packages loaded)                                                                                                                                                                                                                                       
Analyzing: target //:hello (9 packages loaded)                                                                                                                                                                                                                                       
Analyzing: target //:hello (9 packages loaded)                                                                                                                                                                                                                                       
Analyzing: target //:hello (9 packages loaded)                                                                                                                                                                                                                                       
Analyzing: target //:hello (9 packages loaded)                                                                                                                                                                                                                                       
Analyzing: target //:hello (9 packages loaded)                                                                                                                                                                                                                                       
Analyzing: target //:hello (9 packages loaded)                                                                                                                                                                                                                                       
Analyzing: target //:hello (9 packages loaded)                                                                                                                                                                                                                                       
Analyzing: target //:hello (9 packages loaded)                                                                                                                                                                                                                                       
Analyzing: target //:hello (9 packages loaded)                                                                                                                                                                                                                                       
Analyzing: target //:hello (9 packages loaded)                                                                                                                                                                                                                                       
INFO: Analysed target //:hello (12 packages loaded).                                                                                                                                                                                                                                 
INFO: Found 1 target...                                                                                                                                                                                                                                                              
[2 / 4] BazelWorkspaceStatusAction stable-status.txt                                                                                                                                                                                                                                 
[61 / 89] Executing genrule @lisp__sbcl//:make-sbcl [for host]; 10s linux-sandbox ... (2 actions running)                                                                                                                                                                            
[61 / 89] Executing genrule @lisp__sbcl//:make-sbcl [for host]; 31s linux-sandbox ... (2 actions running)                                                                                                                                                                            
[61 / 89] Executing genrule @lisp__sbcl//:make-sbcl [for host]; 57s linux-sandbox ... (2 actions running)                                                                                                                                                                            
[61 / 89] Executing genrule @lisp__sbcl//:make-sbcl [for host]; 90s linux-sandbox ... (2 actions running)                                                                                                                                                                            
[61 / 89] Executing genrule @lisp__sbcl//:make-sbcl [for host]; 134s linux-sandbox ... (2 actions running)                                                                                                                                                                           
[61 / 89] Executing genrule @lisp__sbcl//:make-sbcl [for host]; 191s linux-sandbox ... (2 actions running)                                                                                                                                                                           
[61 / 89] Executing genrule @lisp__sbcl//:make-sbcl [for host]; 228s linux-sandbox ... (2 actions running)                                                                                                                                                                           
[61 / 89] Executing genrule @lisp__sbcl//:make-sbcl [for host]; 280s linux-sandbox ... (2 actions running)                                                                                                                                                                           
ERROR: /home/red/git/lispb/BUILD.bazel:5:1: Linking of rule '//:hello.rt' failed (Exit 1)                                                                                                                                                                                            
**/usr/bin/ld.gold: error: bazel-out/local-fastbuild/genfiles/external/lisp__sbcl/lib/sbcl/libsbcl.a(x86-64-assem.o): requires unsupported dynamic reloc 11; recompile with -fPIC**                                                                                                      
bazel-out/local-fastbuild/bin/_objs/hello.rt/hello.extern.pic.o(rodata+0x35c): warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'                                                                                                                          
collect2: error: ld returned 1 exit status                                                                                                                                                                                                                                           
Target //:hello failed to build                                                                                                                                                                                                                                                      
Use --verbose_failures to see the command lines of failed build steps.                                                                                                                                                                                                               
INFO: Elapsed time: 347.880s, Critical Path: 292.50s                                                                                                                                                                                                                                 
FAILED: Build did NOT complete successfully
fare commented 7 years ago

Since the lisp support is all in git, I suppose that the only moving part is what version of bazel you're using that I wasn't using earlier this year.

OK, so linking options seem to have changed. With --verbose_failures or otherwise, will it tell you what ld command was issued?

If you trace the sbcl build, can you tell what flags were used to build?

gonzojive commented 7 years ago

afaict, the ld command is this:

 ERROR: /home/red/git/lispb/BUILD.bazel:5:1: Linking of rule '//:hello.rt' failed (Exit 1): linux-sandbox failed: error executing command

  (cd /home/red/.cache/bazel/_bazel_red/6e5c7a1e566011faad345a81d57ffaf4/execroot/fun_times && \                                                                                                                                                                                     
  exec env - \
    PWD=/proc/self/cwd \  /home/red/.cache/bazel/_bazel_red/6e5c7a1e566011faad345a81d57ffaf4/execroot/fun_times/_bin/linux-sandbox -D -t 15 -w /home/red/.cache/bazel/_bazel_red/6e5c7a1e566011faad345a81d57ffaf4/bazel-sandbox/4275454517868034787/execroot/fun_times -w /dev/shm -w /tmp -- /usr/bin/gcc -o bazel-out/local-fastbuild/bin/hello.rt -Wl,--export-dynamic -Wl,--dynamic-list bazel-out/local-fastbuild/genfiles/hello.dynamic-list.lds -Wl,-u,uid_username -Wl,-u,lseek_largefile -Wl,-u,get_timezone -Wl,-u,spawn '-fuse-ld=gold' -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/usr/bin -B/usr/bin -pass-exit-codes -Wl,-S -Wl,@bazel-out/local-fastbuild/bin/hello.rt-2.params)

Bazel version 0.5.4:

$ bazel version
Build label: 0.5.4
Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Aug 25 10:00:00 2017 (1503655200)
Build timestamp: 1503655200
Build timestamp as int: 1503655200

Sorry I don't have more time to get to the bottom of the issue. I will try to take a look at some point.

gonzojive commented 7 years ago

I uncommented a line about in rules.bzl to get the build to succeed. See https://github.com/gonzojive/bazelisp/tree/position-independent-code-fix

fare commented 7 years ago

Yeah, bazel is not the only change here, but the basic C toolchain, too. If your compiler and linker defaults are now -pie, you may need -no-pie indeed. The SBCL source may or may not have evolved since 1.3.15 to take that into account, and could provide hints on how flags to compile SBCL have evolved.

Do you want to become Bazelisp maintainer, considering that you're the only current user? I could give you commit rights.

fare commented 7 years ago

It is also possible that the exact options to use depend on the architecture, and/or on llvm vs gcc, at which point you'd have to insert conditional inclusion madness. Let's assume not.