Use weak functions in the RTEMS core?

Jonathan Brandmeyer jbrandmeyer at planetiq.com
Wed Apr 8 15:57:28 UTC 2020


There are a couple more disadvantages.

Which definition is pulled into the final link depends on the order that
the object files are listed on the command-line.  If the weak one is seen
first, then the linker will resolve the symbol against the weak definition
and it won't even search into subsequent archives for the strong one.  It
will merely suppress multiple-definition errors at link time.

We ran into this issue in our project when we over-rode some RTEMS weak
symbols in one of our static archives.  Since the dependency graph seen by
the linker was from one object in librtems.a to another object in
librtems.a, the only way we could reliably pull in our override was by
listing our archive as an object to be linked instead of as an archive to
be searched (ie, named as libour_runtime.a instead of -lour_runtime on the
link step command).

Additionally, it is not trivial to verify which implementation was actually
pulled into the linked object.  Tools like `nm` and `objdump` just list the
symbol name that ends up in the final ELF.  You have to generate a map file
and then examine it to establish which object file provided the resolved
symbol.  Maybe this difficulty can be reduced a little with symbol
versioning.

On Wed, Apr 8, 2020 at 9:28 AM Sebastian Huber <
sebastian.huber at embedded-brains.de> wrote:

> Hello,
>
> another use case for a weak function could be the heap. If you only
> allocate memory and never free it, then the implementation can be very
> simple:
>
> https://git.rtems.org/rtems/tree/cpukit/score/src/memoryallocate.c#n49
>
> We could use something like this in heapallocate.c:
>
> RTEMS_WEAK void *_Heap_Allocate_impl(size) { /* Very simple */ }
>
> void *_Heap_Allocate(size)
>
> {
>
>    return _Heap_Allocate_impl(size)
>
> }
>
> In heapfree.c:
>
> void *_Heap_Allocate_impl(size) { /* Complex */ }
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel



-- 
Jonathan Brandmeyer
PlanetiQ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20200408/60a74ce5/attachment-0001.html>


More information about the devel mailing list