Skip to content
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

Build issue causing raspivid to fail (components not registered) #178

Closed
ajlennon opened this issue Jun 2, 2014 · 17 comments
Closed

Build issue causing raspivid to fail (components not registered) #178

ajlennon opened this issue Jun 2, 2014 · 17 comments
Labels
Close within 30 days Issue will be closed within 30 days unless requested to stay open Waiting for internal comment

Comments

@ajlennon
Copy link

ajlennon commented Jun 2, 2014

libmmal_vc_client.so makes use of attribute(constructor) to ensure that supplier components (e.g. camera) are loaded when the static library is loaded.

raspivid, and possibly other applications, link against libmmal_vc_client.so, causing the ctor to execute, but there is no needed dependency.

Some build environments (e.g. Yocto/OpenEmbedded) pass the '--no-as-needed' linker flag which removes the dependency on libmmal_vc_client and thus needed components are not registered.

In this situation raspivid then gives an error of the form

root@raspberrypi:~# raspivid -o test
mmal: mmal_component_create_core: could not find component 'vc.ril.camera'
mmal: Failed to create camera component
mmal: main: Failed to create camera component
mmal: Failed to run camera app. Please check for firmware updates

For further details see https://lists.yoctoproject.org/pipermail/yocto/2014-June/019933.html

LongChair added a commit to plexinc/OpenELEC.tv that referenced this issue Mar 18, 2015
This will break libmpv reference to libmmal_vc_client.so

see raspberrypi/userland#178
@Ruffio
Copy link

Ruffio commented Jun 27, 2015

@ajlennon is this still an issue?

@YamSoup
Copy link

YamSoup commented Jul 14, 2015

yes

@ajlennon
Copy link
Author

@Ruffio not sure I'm afraid. I submitted a patch to meta-raspberrypi to prevent the --as-needed being used. I I get a chance I'll see if that is working

@PeterDaveHello
Copy link

+1

@Ruffio
Copy link

Ruffio commented Jul 30, 2016

@ajlennon is it working?

@JamesH65
Copy link
Collaborator

JamesH65 commented Dec 5, 2017

Anyone contributing to the thread have any further comment or possible fixes?

@PeterDaveHello
Copy link

Sorry I don't, I'm not using this for a while.

@strongheart1
Copy link

I get the same issue building from this repository on a raspberry with Ubuntu 16.04.4 LTS, gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) - so, is this a configuration issue of the build environment?

@6by9
Copy link
Contributor

6by9 commented Mar 19, 2018

so, is this a configuration issue of the build environment?

Yes, as covered in some of the linked issues.
If the linker adds the --no-as-needed flag, then it is over-eager in stripping out code from libmmal_vc_client.so to the extent of having no VideoCore components. Ideally there needs to be something extra to signal to the linker that this code is required, but it's not been a priority to resolve.

edit Correction - it's over-eager in determining that the application (raspistill/raspivid etc) doesn't use any functions from libmmal_vc_client.so, therefore drops the advertised dependency. libmmal_vc_client.so is complete with all the expected functionality.

@6by9
Copy link
Contributor

6by9 commented Mar 19, 2018

@pelwell from #303 (comment) where you point a similar VPU issue. Having had a play I don't believe that is going to help here.
As I understand it, the issue here is that the linker when processing raspistill/vid has gone through and determined that we don't call any of the libmmal_vc_client.so functions, therefore it isn't needed as a dependency to the app. It misses that the constructor will do stuff that will make a difference.

Your VPU solution (I think) was the equivalent of the compiler for libmmal_vc_client.so determining that none of the functions were exported and therefore it could optimise them out of the .so. Your mod adds in an extra use of the variables to stop it optimising them away.

I've tried various things today, but adding:

SET( CMAKE_EXE_LINKER_FLAGS "-Wl,--no-as-needed" )

to the relevant application CMakeLists.txt seems to be the only solution that actually works.
I fail to see how we can do anything else when the linker with ``--as-needed``` is being so enthusiastic to discard things. I'll create a PR for that and people can object if they so wish.

6by9 added a commit to 6by9/userland that referenced this issue Mar 19, 2018
Some versions of GCC have --as-needed turned on by default.
The binding of libmmal_vc_client is such that the constructor
registers the supported components with the MMAL core, and nothing
calls into it directly. The linker can't tell this, decides
it is unused, and promptly drops it as a dependency - cue no
VideoCore components.

Adding --no-as-needed means that the linker leaves it alone.
It's not nice, but there doesn't appear to be a better solution.

See raspberrypi#178.
@luked99
Copy link
Contributor

luked99 commented Mar 20, 2018

Looking at the docs for the --as-needed ld flag, it says that this switches off the DT_NEEDED flag on the library concerned.
I wonder if there's a way to add it back in to the mmal shared libraries. It's just an ELF flag.

@luked99
Copy link
Contributor

luked99 commented Mar 20, 2018

(i.e. rather than modifying every executable, just change the library).

@pelwell
Copy link
Contributor

pelwell commented Mar 20, 2018

Or, as a compromise, add the flag to all library builds.

@6by9
Copy link
Contributor

6by9 commented Mar 20, 2018

Thanks guys. I'd been trying to find a suitable flag to set on the library (because that is the nicer thing to do), but had failed. I'm still not convinced that there is a suitable flag on the library.

From man ld

       --as-needed
       --no-as-needed
           This option affects ELF DT_NEEDED tags for dynamic libraries mentioned on the command line after the --as-needed option.  Normally the linker will add a
           DT_NEEDED tag for each dynamic library mentioned on the command line, regardless of whether the library is actually needed or not.  --as-needed causes a
           DT_NEEDED tag to only be emitted for a library that at that point in the link satisfies a non-weak undefined symbol reference from a regular object file
           or, if the library is not found in the DT_NEEDED lists of other needed libraries, a non-weak undefined symbol reference from another needed dynamic
           library.  Object files or libraries appearing on the command line after the library in question do not affect whether the library is seen as needed.
           This is similar to the rules for extraction of object files from archives.  --no-as-needed restores the default behaviour.

As I read that, it is solely at the link stage of the application that it is making up the list of libraries to include. The DT_NEEDED tag itself doesn't exist outside of the linker until the link is complete and the ELF file written.
Without some explicit call into the mmal_vc_client, ld will drop the dependency. We don't want an explicit call as the constructor is the bit that registers the components for general use.

The DT_NEEDED flags on libmmal_vc_client list just the things it depends on, which is as expected:

ubuntu@ubuntu:~/userland$ readelf -d ./build/lib/libmmal_vc_client.so 

Dynamic section at offset 0x6ee8 contains 31 entries:
  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: [libvchiq_arm.so]
 0x00000001 (NEEDED)                     Shared library: [libvcsm.so]
 0x00000001 (NEEDED)                     Shared library: [libvcos.so]
 0x00000001 (NEEDED)                     Shared library: [libpthread.so.0]
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]
 0x00000001 (NEEDED)                     Shared library: [ld-linux-armhf.so.3]
 0x0000000e (SONAME)                     Library soname: [libmmal_vc_client.so]
 0x0000000f (RPATH)                      Library rpath: [/home/ubuntu/userland/build/lib:]

On raspistill, it has totally thrown away libmmal_vc_client.so

ubuntu@ubuntu:~/userland$ readelf -d ./build/bin/raspistill

Dynamic section at offset 0x10ec0 contains 35 entries:
  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: [libmmal_core.so]
 0x00000001 (NEEDED)                     Shared library: [libmmal_util.so]
 0x00000001 (NEEDED)                     Shared library: [libbrcmGLESv2.so]
 0x00000001 (NEEDED)                     Shared library: [libbrcmEGL.so]
 0x00000001 (NEEDED)                     Shared library: [libm.so.6]
 0x00000001 (NEEDED)                     Shared library: [libvcsm.so]
 0x00000001 (NEEDED)                     Shared library: [libbcm_host.so]
 0x00000001 (NEEDED)                     Shared library: [libvcos.so]
 0x00000001 (NEEDED)                     Shared library: [libpthread.so.0]
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]
 0x00000001 (NEEDED)                     Shared library: [ld-linux-armhf.so.3]
 0x0000000f (RPATH)                      Library rpath: [/home/ubuntu/userland/build/lib:]

I guess the other approach is to throw the towel in and make all the components dependencies on mmal_core. mmal_core then needs to be built with --no-as-needed so that ld doesn't throw the dependencies away from that. It bloats sizes though,as we'd have to include all the ARM side components in the list of dependencies too, otherwise the problem still remains for them.
In reality we don't build MMAL for other platforms any more, so don't care about it only being valid for VideoCore.

Thoughts?

6by9 added a commit to 6by9/userland that referenced this issue Aug 23, 2018
Some versions of GCC have --as-needed turned on by default.
The binding of libmmal_vc_client is such that the constructor
registers the supported components with the MMAL core, and nothing
calls into it directly. The linker can't tell this, decides
it is unused, and promptly drops it as a dependency - cue no
VideoCore components.

Adding --no-as-needed means that the linker leaves it alone.
It's not nice, but there doesn't appear to be a better solution.

See raspberrypi#178.
popcornmix pushed a commit that referenced this issue Sep 7, 2018
Some versions of GCC have --as-needed turned on by default.
The binding of libmmal_vc_client is such that the constructor
registers the supported components with the MMAL core, and nothing
calls into it directly. The linker can't tell this, decides
it is unused, and promptly drops it as a dependency - cue no
VideoCore components.

Adding --no-as-needed means that the linker leaves it alone.
It's not nice, but there doesn't appear to be a better solution.

See #178.
@JamesH65
Copy link
Collaborator

JamesH65 commented Dec 3, 2018

It would be nice to close this over 4 year old issue before it reaches its next birthday - is there anything that can/should be done?

@JamesH65
Copy link
Collaborator

JamesH65 commented Jan 8, 2019

This issue will be closed within 30 days unless further interactions are posted. If you wish this issue to remain open, please add a comment. A closed issue may be reopened if requested.

@JamesH65 JamesH65 added the Close within 30 days Issue will be closed within 30 days unless requested to stay open label Jan 8, 2019
andreasBihlmaier added a commit to andreasBihlmaier/raspicam_node that referenced this issue Mar 14, 2020
…l.camera"

Fixes the following error (on Ubuntu 18.04 aarch64 using Raspbian kernel8.img (4.19.97-v8+ #1294)):
mmal: mmal_component_create_core: could not find component 'vc.ril.camera'
mmal: Failed to create camera component

For details refer to raspberrypi/userland#178
@6by9
Copy link
Contributor

6by9 commented Jan 25, 2022

Closing as should be fixed by #714 due to Bullseye changing the default compiler options.

@6by9 6by9 closed this as completed Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Close within 30 days Issue will be closed within 30 days unless requested to stay open Waiting for internal comment
Projects
None yet
Development

No branches or pull requests

9 participants