Jump to content

Compilation with LTO and as-needed.


khelban12

Recommended Posts

Greetings.

[Intro]

Lately when i ran gemrb it segfaulted in OpenALAudio:cpp:222 "context = alcCreateContext(device, NULL)";

I tried different OpenAL versions and it always segfaulted. If i modify gemrb.cfg and disable sound then it works fine. It only segfaults with OpenAL. I thought it is an openal fault so i tried to make a minimal C program that reproduces the issue. No matter what i did, i couldn't make it segfault so i came back to gemrb. I did the first thing i do when something segfaults. Recompiling it without LTO and see if it works. And of course it works fine. I could leave it at that and enjoy gemrb but i couldn't :p I needed to find why it does that. Anyway, after isolating compilation parameters to see what is the fault i found that its not LTO but the combination of LTO and as-needed linker option.

I use LTO and as-needed for a long time (at least since Feb 2017) and gemrb always worked. Something else that has changed in the mean time must trigger the problem. I used gemrb on Tumbleweed for some time now so while i compiled it on Gentoo, i didn't ran it and missed the problem. I tried Gcc 8.something, 9.2, 9.3 and all produce the segfault (hm now that i think of it, i haven't tried different linker versions). However, all programs are built with the same *FLAGS (this is Gentoo) and only gemrb segfaults.

[/Intro]

Whether OpenAL is compiled with or without LTO doesn't make any difference at all. The problem seems to be with gemrb and pthread. OpenALAudio.so is the same in all cases and correctly links with pthread. The gemrb binary however

  • With as-needed but without LTO, it is linked with pthread and works.
  • Without as-needed but with LTO, it is linked with pthread and works
  • With as-needed and with LTO, it is _not_ linked with pthread and segfaults.

With a quick search, i haven't found any calls of threading functions in the source code for the gemrb binary (so maybe that is why the linker thinks it doesn't need pthread), but it seems that libpthread is needed.

Anybody cares to try compiling germb (the latest git for example) with LTO and as-needed enabled and inform us if it works or if my findings are coincidental and something else is at foot ?

export CFLAGS="-O2 -pipe -flto"
export CXXFLAGS="${CFLAGS}"
export LDFLAGS="-Wl,--as-needed -flto"

Setting the above flags (before running cmake) should be enough to reproduce the issue i think.

Thank you for your time.

Link to comment

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...