gcc library directory and LLVM
Someone complained to me recently that clangd was unable to find headers in multilib OE recipe sysroots even though it could do so for non-multilib OE sysroots.
I dug into the LLVM code and discovered that LLVM has a specific "hack" for OE[1] but that hack is not enabled for multilib sysroots. I proposed[2] extending this hack to cover two common multilib targets. One of the LLVM maintainers responded[3] suggesting that OE should consider moving from using its current location ("${libdir}/${TARGET_SYS}") to the (apparently) upstream default ("${libdir}/gcc/${TARGET_SYS}") or Debian's cross-compiler ("${libdir}/gcc-cross/${TARGET_SYS}") conventions. So I thought I'd better investigate that.
gcc-common.inc sets ${gcclibdir} to what looks like the right thing, but it looks like that only has an effect on gcc compiled for the target and not the cross or cross-canadian compilers and even then just controls where the recipe looks for files and not where the GCC build system writes them to.
I found a comment in libgcc-common.inc that explains one side of what's going on:
# install the runtime in /usr/lib/ not in /usr/lib/gcc on target # so that cross-gcc can find it in the sysroot
Way back in 2010 (f47eeddbd692ac3c6109c18c9f04a3ad4dc789ba) that comment used to say:
# Also need to move gcc from /usr/lib/gcc/* to /usr/lib/ else the search paths won't find the crt*.o files
which provides a bit more of a clue but doesn't explain why gcc-cross isn't capable of looking in /usr/lib/gcc. Of course, my attempts to leave install libgcc etc. in the locations that the GCC build system wrote them to (i.e. /usr/lib/gcc/${TARGET_SYS}/${gccversion}) result in the built gcc-cross compiler being unable to find it! (This was not a huge surprise to me.)
My suspicion is that OE does things the way it does because there were no conventions way back when it started and even generating a working cross-compiler was an achievement. It did whatever was necessary to make things work.
At the risk of opening a massive ancient can of worms, is there a chance that it now possible to teach gcc-cross to look for libgcc etc. in ${libdir}/gcc/${TARGET_SYS}/${gccversion} (or ../gcc-cross/..) to match other distributions?
Thanks.
Mike.
[1] https://github.com/llvm/llvm-project/blob/868c89ff0e0ef09ac504873cb9bab8197f5fca2d/clang/lib/Driver/ToolChains/Gnu.cpp#L2880
[2] https://github.com/llvm/llvm-project/pull/121302
[3] https://github.com/llvm/llvm-project/pull/121302#issuecomment-2677041092
Quoted 40 lines · Mike Crowe via lists.openembedded.org
Someone complained to me recently that clangd was unable to find headers in multilib OE recipe sysroots even though it could do so for non-multilib OE sysroots.
I dug into the LLVM code and discovered that LLVM has a specific "hack" for OE[1] but that hack is not enabled for multilib sysroots. I proposed[2] extending this hack to cover two common multilib targets. One of the LLVM maintainers responded[3] suggesting that OE should consider moving from using its current location ("${libdir}/${TARGET_SYS}") to the (apparently) upstream default ("${libdir}/gcc/${TARGET_SYS}") or Debian's cross-compiler ("${libdir}/gcc-cross/${TARGET_SYS}") conventions. So I thought I'd better investigate that.
gcc-common.inc sets ${gcclibdir} to what looks like the right thing, but it looks like that only has an effect on gcc compiled for the target and not the cross or cross-canadian compilers and even then just controls where the recipe looks for files and not where the GCC build system writes them to.
I found a comment in libgcc-common.inc that explains one side of what's going on:
# install the runtime in /usr/lib/ not in /usr/lib/gcc on target # so that cross-gcc can find it in the sysrootWay back in 2010 (
f47eeddbd692ac3c6109c18c9f04a3ad4dc789ba) that comment used to say:# Also need to move gcc from
/usr/lib/gcc/*to/usr/lib/else the search paths won't find the crt*.o fileswhich provides a bit more of a clue but doesn't explain why gcc-cross isn't capable of looking in
/usr/lib/gcc. Of course, my attempts to leave install libgcc etc. in the locations that the GCC build system wrote them to (i.e./usr/lib/gcc/${TARGET_SYS}/${gccversion}) result in the built gcc-cross compiler being unable to find it! (This was not a huge surprise to me.)My suspicion is that OE does things the way it does because there were no conventions way back when it started and even generating a working cross-compiler was an achievement. It did whatever was necessary to make things work.
Quoted 4 lines
At the risk of opening a massive ancient can of worms, is there a chance that it now possible to teach gcc-cross to look for libgcc etc. in ${libdir}/gcc/${TARGET_SYS}/${gccversion} (or ../gcc-cross/..) to match other distributions?
As someone who has poked at some of this, I suspect you're right, we managed to make it all work and we moved on to other more pressing matters.
It would probably be nice to be consistent with the target layout but I suspect there are issues with the compiler/library search paths which prevent it as we do things today.
OE is one of the few setups that has separate host system, native and target sysroots. We also use our own mechanisms of relocation of gcc, partly due to that, all of which combines to mean that this isn't a simple thing to change.
Trying to unravel the situation and then if necessary, talking to upstream gcc about how we might be able improve things is on my todo list. Sadly it is the kind of thing few people actually care enough about to invest time into and I get too many other distracting bigger fires. Sadly I struggle to explain to people why we should care about making these kinds of back end infrastructure improvements and I therefore struggle to find time to spend on it.
So yes, I suspect it would be possible but who would wade through the pain involved, perhaps other than me, I'm not sure...
Cheers,
Richard
Quoted 41 lines · Richard Purdie
Quoted 40 lines · Mike Crowe via lists.openembedded.org
Someone complained to me recently that clangd was unable to find headers in multilib OE recipe sysroots even though it could do so for non-multilib OE sysroots.
I dug into the LLVM code and discovered that LLVM has a specific "hack" for OE[1] but that hack is not enabled for multilib sysroots. I proposed[2] extending this hack to cover two common multilib targets. One of the LLVM maintainers responded[3] suggesting that OE should consider moving from using its current location ("${libdir}/${TARGET_SYS}") to the (apparently) upstream default ("${libdir}/gcc/${TARGET_SYS}") or Debian's cross-compiler ("${libdir}/gcc-cross/${TARGET_SYS}") conventions. So I thought I'd better investigate that.
gcc-common.inc sets ${gcclibdir} to what looks like the right thing, but it looks like that only has an effect on gcc compiled for the target and not the cross or cross-canadian compilers and even then just controls where the recipe looks for files and not where the GCC build system writes them to.
I found a comment in libgcc-common.inc that explains one side of what's going on:
�# install the runtime in
/usr/lib/not in/usr/lib/gccon target �# so that cross-gcc can find it in the sysrootWay back in 2010 (
f47eeddbd692ac3c6109c18c9f04a3ad4dc789ba) that comment used to say:�# Also need to move gcc from
/usr/lib/gcc/*to/usr/lib/else the search paths won't find the crt*.o fileswhich provides a bit more of a clue but doesn't explain why gcc-cross isn't capable of looking in
/usr/lib/gcc. Of course, my attempts to leave install libgcc etc. in the locations that the GCC build system wrote them to (i.e./usr/lib/gcc/${TARGET_SYS}/${gccversion}) result in the built gcc-cross compiler being unable to find it! (This was not a huge surprise to me.)My suspicion is that OE does things the way it does because there were no conventions way back when it started and even generating a working cross-compiler was an achievement. It did whatever was necessary to make things work.
Quoted 8 lines
Quoted 4 lines
At the risk of opening a massive ancient can of worms, is there a chance that it now possible to teach gcc-cross to look for libgcc etc. in ${libdir}/gcc/${TARGET_SYS}/${gccversion} (or ../gcc-cross/..) to match other distributions?
As someone who has poked at some of this, I suspect you're right, we managed to make it all work and we moved on to other more pressing matters.
I think that the phrase "poked at some of this" hugely underestimates the work you've put into this over the years. Thank you!
Quoted 17 lines
It would probably be nice to be consistent with the target layout but I suspect there are issues with the compiler/library search paths which prevent it as we do things today.
OE is one of the few setups that has separate host system, native and target sysroots. We also use our own mechanisms of relocation of gcc, partly due to that, all of which combines to mean that this isn't a simple thing to change.
Trying to unravel the situation and then if necessary, talking to upstream gcc about how we might be able improve things is on my todo list. Sadly it is the kind of thing few people actually care enough about to invest time into and I get too many other distracting bigger fires. Sadly I struggle to explain to people why we should care about making these kinds of back end infrastructure improvements and I therefore struggle to find time to spend on it.
Quoted 2 lines
So yes, I suspect it would be possible but who would wade through the pain involved, perhaps other than me, I'm not sure...
This is roughly what I was expecting.
I have only a cursory understanding of how this all works and unfortunately I don't think I'm going to be able to invest the necessary time in trying to learn enough to be useful. Nevertheless, if I get the chance to, I will.
It turns out that it is possible to trick the LLVM code into looking in the right place by creating symlinks. Unfortunately it uses ../../.. to get back from /usr/lib/gcc/${TARGET_SYS}/${gccversion}) to /usr/lib. This means that each part of the former path must be a real directory though/. :( Why it is finding /usr/lib this way rather than just using the sysroot argument I don't know.
Thanks for sending such a useful reply so quickly.
Mike.