-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
supplied .pc files link un-needed libraries and also don't link the dependencies of those libraries #1013
Comments
The workaround is to install fixed pkgconfig .pc files into the sysroot. The ones installed from the official Raspbian package have several problems. First, they are installed somewhere that pkg-config doesn't know about. The fixed .pc are install into $(SYSROOT)/usr/lib/pkgconfig which is part of the list of directories Qt build searches. Second, they are named like "brcmegl.pc" instead of egl.pc. The fixed configs are installed as "egl.pc" etc, because this is what Qt will look for. They still tell Qt to link to the brcm sonames. Third, they link unnecessary libraries and then don't link to the dependencies of those libraries, which means they don't work at all. The fixed versions remove all reverences to bcm_host, vchi and etc. This means they won't break the build due to no pthreads. See raspberrypi/firmware#1013 pkg-config is only used during building, so these files are only needed in the sysroot. The final binaries will "just work" without hacking paths and environment variables.
@XECDesign Is this one for you? Seems that the brcmegl.pc file has unnecessary dependencies, but I am no expert. |
IIRC, you have to call the init function from bcm_host before you can use them, so why should it be removed? Or is the idea that you should be calling pkg-config separately for bcm_host anyway? |
The problem was that configure tests check For some reason I can no longer reproduce the problem and I am not sure what changed. My toolchain seems to implicitly link pthreads now, meaning the tests work even without |
Further investigation: the problem seems related to brcmegl.pc both requiring bcm_host and also explicitly linking bcm_host and vcoshostif. brcmglesv2.pc and brcmvg.pc don't do this. I am not sure why. |
The problem is specifically caused by So I think the following should be done:
|
@ali1234 can you submit a PR? |
Which repository should it be made on? userland or firmware? |
Userland is best. It'll be cherry-picked to firmware tree on next firmware update. |
I just found out something new about this. EGL does use vchostif functions, but because it is static, they all get bundled into bcm_host. However, other people build it as a shared lib, and then it needs to be linked separately. That is why patches like this exist: https://patchwork.openembedded.org/patch/140309/ - and see the comments, they are building it as a shared lib and they want to upstream it. So vchostif can be removed from the pc in firmware as it is now. But if you make it into a shared library like some people want then you'll have to put it back. And for userland, the content of the pc should depend on how you build it. I still don't understand why bcm_host doesn't bring a dependency on pthreads if it contains all the vchostif functions, or how building vchostif as a shared library will affect configure tests when the pcs are actually used. Nobody but me seems to use them. |
The previous workaround in de70457 does a bit more than it should by removing the pkgconfig dependency links to bcm_host. This library is actually required. Qt will add it without the help from pkgconfig but keeping the dependency is still correct. This means only brcmegl.pc needs to have its contents modified. It now depends on bcm_host and also explicitly links it, which is redundant. Linking vcoshostif is still unnecessary. This patch restores the bcm_host dependencies and moves the patched .pc files into /opt/vc next to the originals. Unmodified .pcs are now symlinked instead of overlayed. The new path for .pc files is added in the build script so that the configs can be found. See raspberrypi/firmware#1013
For reference raspberrypi/userland#304 and #149 |
These pkgconfig files don't need to explicitly link bcm_host because they contain "Requires: bcm_host" which will include it and also any necessary dependencies. They don't need to link vchostif because that static library is included within bcm_host.so. If vchostif is ever made shared the pkgconfigs will need to be updated by adding -lvchostif back in. Fixes: raspberrypi/firmware#1013
Still investigating this. I found some new things. pkg-config says the libs should be:
Notice that bcm_host appears twice. If you link the test executable with those libs it works. However, something in the Qt build is de-duplicating the list of libs so it tries to link with:
This fails because now vchostif appears before bcm_host. If you swap those two libs around in the command line, the build succeeds. I assume this happens because bcm_host supplies all the needed libs, so the compiler ends up ignoring vchostif. I will keep investigating why Qt does that de-duplication. I think it should take the first appearance of a library rather than the last in order to not change the meaning when duplicates are present. I also tested shared build with pcs that don't link vchostif (ie the above patch) and it still works, so what I said before about having to put it back is not true. I suppose this is because egl.so does not directly need anything from vchostif.so. So at this point I'm fairly happy that my proposed fix is correct and I will open a pull request. |
Okay so I spoke too soon. While you dont need to link vchostif for egl, you do need to link it if it is shared and you want to call In fact all these pc files are over-linking things. EGL only needs brcmEGL.so at link time. You don't need to link bcm_host or brcmGLESv2 if they are dynamic. Seems I need to think about this some more. |
It isn't necessary to link bcm_host when linking EGL etc unless you actually want to use a function from bcm_host in your code. In that case you should be calling pkgconfig for bcm_host separately. It also isn't necessary to link GLESv2 when using EGL for the same reason. These changes have been tested for building Qt. I have not attempted to make the same fixes in MMAL etc as I don't currently know how to test them. Partially fixes: raspberrypi/firmware#1013
It isn't necessary to link bcm_host when linking EGL etc unless you actually want to use a function from bcm_host in your code. In that case you should be calling pkgconfig for bcm_host separately. It also isn't necessary to link GLESv2 when using EGL for the same reason. These changes have been tested for building Qt. I have not attempted to make the same fixes in MMAL etc as I don't currently know how to test them. Partially fixes: raspberrypi/firmware#1013
Ask pkg-config how to build a program for brcmegl:
Result:
There are two problems with the above output. The first is that brcmEGL and brcmGLESv2 don't need to link bcm_host, vchostif, bcm_host, vcos, or vchiq_arm. The second problem is that if you do link vcoshostif then you must also link pthreads, and this .pc does not. As a result, any build using it will fail:
The text was updated successfully, but these errors were encountered: