tshort/StaticCompiler.jl

Linking error

Closed this issue · 2 comments

Hi, I tried to test this out the times_table example from StaticTools.jl, and hit an error with the linking step called by this package:

julia> filepath = compile_executable(times_table, (Int64, Ptr{Ptr{UInt8}}), "./")
./wrapper.c:3:5: warning: implicit declaration of function 'julia_times_table' is invalid in C99 [-Wimplicit-function-declaration]
    julia_times_table(argc, argv);
    ^
1 warning generated.
/usr/lib64/gcc/x86_64-suse-linux/12/../../../../x86_64-suse-linux/bin/ld: ./times_table.o: in function `julia_times_table':
text:(.text+0x11): undefined reference to `__stack_chk_guard'
/usr/lib64/gcc/x86_64-suse-linux/12/../../../../x86_64-suse-linux/bin/ld: text:(.text+0x21c): undefined reference to `__stack_chk_guard'
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
ERROR: failed process: Process(setenv(`/home/tec/.julia/artifacts/75ed94858c831a8af1fcfa5151509c116570ef05/tools/clang ./wrapper.c ./times_table.o -o ./times_table`,["P9K_SSH=0", "EDITOR=e -t", "PATH=/home/tec/.julia/artifacts/75ed94858c831a8af1fcfa5151509c116570ef05/tools:/home/tec/.local/share/zinit/polaris/bin:/home/tec/.local/share/cargo/bin:/home/tec/.julia/juliaup/bin:/home/tec/.local/share/go/bin:/home/tec/.local/share/npm/bin:/home/tec/.local/bin:/home/tec/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/home/tec/.local/bin:/home/tec/.local/share/cargo/bin:/home/tec/.local/share/go/bin:/home/tec/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/home/tec/.local/bin:/home/tec/bin:/usr/local/bin:/usr/bin:/bin", "CPU=x86_64", "LMOD_ROOT=/usr/share/lmod", "JRE_HOME=/usr/lib64/jvm/java", "_P9K_TTY=/dev/pts/6", "FROM_HEADER=", "G_FILENAME_ENCODING=@locale,UTF-8,ISO-8859-1,CP1252", "KITTY_PID=3961"  …  "ZINIT_HOME=/home/tec/.local/share/zinit", "AUDIODRIVER=pulseaudio", "QT_IM_SWITCHER=imsw-multi", "LMOD_COLORIZE=no", "INPUTRC=/home/tec/.config/readline/inputrc", "NODE_REPL_HISTORY=/home/tec/.local/share/node_repl_history", "JAVA_BINDIR=/usr/lib64/jvm/java/bin", "HOSTTYPE=x86_64", "KDE_SESSION_VERSION=5", "LS_COLORS=no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tgz=00;31:*.arc=00;31:*.arj=00;31:*.taz=00;31:*.lha=00;31:*.lz4=00;31:*.lzh=00;31:*.lzma=00;31:*.tlz=00;31:*.txz=00;31:*.tzo=00;31:*.t7z=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.dz=00;31:*.gz=00;31:*.lrz=00;31:*.lz=00;31:*.lzo=00;31:*.xz=00;31:*.zst=00;31:*.tzst=00;31:*.bz2=00;31:*.bz=00;31:*.tbz=00;31:*.tbz2=00;31:*.tz=00;31:*.deb=00;31:*.rpm=00;31:*.jar=00;31:*.war=00;31:*.ear=00;31:*.sar=00;31:*.rar=00;31:*.alz=00;31:*.ace=00;31:*.zoo=00;31:*.cpio=00;31:*.7z=00;31:*.rz=00;31:*.cab=00;31:*.wim=00;31:*.swm=00;31:*.dwm=00;31:*.esd=00;31:*.asf=01;35:*.avi=01;35:*.bmp=01;35:*.cgm=01;35:*.dl=01;35:*.emf=01;35:*.flc=01;35:*.fli=01;35:*.flv=01;35:*.gif=01;35:*.gl=01;35:*.jpeg=01;35:*.jpg=01;35:*.m2v=01;35:*.m4v=01;35:*.mjpeg=01;35:*.mjpg=01;35:*.mkv=01;35:*.mng=01;35:*.mov=01;35:*.mp4=01;35:*.mp4v=01;35:*.mpeg=01;35:*.mpg=01;35:*.nuv=01;35:*.ogm=01;35:*.pbm=01;35:*.pcx=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.qt=01;35:*.rm=01;35:*.rmvb=01;35:*.svg=01;35:*.svgz=01;35:*.tga=01;35:*.tif=01;35:*.tiff=01;35:*.vob=01;35:*.webm=01;35:*.webp=01;35:*.wmv=01;35:*.xbm=01;35:*.xcf=01;35:*.xpm=01;35:*.xwd=01;35:*.yuv=01;35:*.ogv=01;35:*.ogx=01;35:*.aiff=00;32:*.ape=00;32:*.aac=00;32:*.au=00;32:*.flac=00;32:*.m4a=00;32:*.mid=00;32:*.midi=00;32:*.mka=00;32:*.mp3=00;32:*.mpc=00;32:*.ogg=00;32:*.ra=00;32:*.voc=00;32:*.wav=00;32:*.wma=00;32:*.wv=00;32:*.oga=00;32:*.opus=00;32:*.spx=00;32:*.xspf=00;32:"]), ProcessExited(1)) [1]

Stacktrace:
 [1] pipeline_error
   @ ./process.jl:565 [inlined]
 [2] run(::Cmd; wait::Bool)
   @ Base ./process.jl:480
 [3] run
   @ ./process.jl:477 [inlined]
 [4] generate_executable(f::Function, tt::Type, path::String, name::String, filename::String; cflags::Cmd, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ StaticCompiler ~/.julia/packages/StaticCompiler/Avq3a/src/StaticCompiler.jl:386
 [5] compile_executable(f::Function, types::Tuple{DataType, DataType}, path::String, name::String; filename::String, cflags::Cmd, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ StaticCompiler ~/.julia/packages/StaticCompiler/Avq3a/src/StaticCompiler.jl:244
 [6] compile_executable (repeats 2 times)
   @ ~/.julia/packages/StaticCompiler/Avq3a/src/StaticCompiler.jl:229 [inlined]
 [7] top-level scope
   @ REPL[14]:1

(I'm surprised that StaticCompiler isn't using mold from Yggdrasil or the like)

I'm not really sure what to make of this, but hopefully, you can find something useful in the backtrace. Let me know if there are any tests you'd like me to run.

System Info

  • OpenSUSE Tumbleweed (20220812)
  • GNU ld 2.38
  • Julia 1.8.0-rc4

This has turned out to be a common error despite not turning up in CI. It was a bit hard to debug because __stack_chk_guard doesn't show up in the @code_llvm despite apparently getting inserted by someone or something. As far as I can tell, this appears to be due to apparently on-by-default feature in some newer compilers to enable stack smashing protection. This is a great feature to have, but requires us to set a value of __stack_chk_guard as a canary (e.g. https://antoinealb.net/programming/2016/06/01/stack-smashing-protector-on-microcontrollers.html). Once we do that, the error seems to go away. I'll PR the fix after we can finish up and merge #85

Should be fixed now, thanks for the issue @tecosaur!