<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 08/04/2020 19:34, Jonathan
Brandmeyer wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CA+XzfkqsyT7mJsEM2Z8VaC+FX7aGtbSrKiFChSD2M8n7ac7LZQ@mail.gmail.com">
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">If
you encounter problems like this, then <br>
weak functions are used for the wrong thing.<br>
</blockquote>
<div><br>
</div>
<div>Exhibit A: zynq_setup_mmu_and_cache. It is referred to only
by the BSP's startup sequence. So it is a reference from
librtemsbsp to librtemsbsp by default. I don't think it's being
used for the wrong thing.<br>
</div>
</blockquote>
You could move zynq_setup_mmu_and_cache() to a separate file and
remove the weak. The weak function here just avoids an extra file.<br>
<blockquote type="cite"
cite="mid:CA+XzfkqsyT7mJsEM2Z8VaC+FX7aGtbSrKiFChSD2M8n7ac7LZQ@mail.gmail.com">
<div> </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
I would like to use weak functions with one level of
indirection. For <br>
example an application can use two features A and B. Both use an
<br>
interface C. If only A is used, then C can be implemented via D
or E. If <br>
B is used, then C must be implemented via E. For this you can
use a weak <br>
implementation D of interface C in module of A and a strong <br>
implementation E in module of B.<br>
</blockquote>
<div><br>
</div>
<div>In the proposed case of using weak references for the heap,
which implementation gets pulled in depends on whether or not
the object files listed on the command line reference the heap
or not. If the only references are within static archives, then
the application will have difficulty choosing exactly which
implementation of the heap gets pulled in. librtemsbsp both
depends-on and provides implementations of malloc and free.</div>
<div><br>
</div>
<div>It's pretty easy to provide a definition of Init() or
POSIX_Init() that doesn't directly call malloc or free, for
example.</div>
</blockquote>
<p>In my proposed use case:</p>
<p>We could use something like this in heapallocate.c:
<br>
<br>
RTEMS_WEAK void *_Heap_Allocate_impl(size) { /* Very simple */ }
<br>
<br>
void *_Heap_Allocate(size)
<br>
<br>
{
<br>
<br>
return _Heap_Allocate_impl(size)
<br>
<br>
}
<br>
<br>
In heapfree.c:
<br>
<br>
void *_Heap_Allocate_impl(size) { /* Complex */ } <br>
</p>
<p>The application doesn't reference _Heap_Allocate_impl(). It
references _Heap_Allocate() or _Heap_Free() or both or none.<br>
</p>
<blockquote type="cite"
cite="mid:CA+XzfkqsyT7mJsEM2Z8VaC+FX7aGtbSrKiFChSD2M8n7ac7LZQ@mail.gmail.com">
<div><br>
</div>
<div>Instead of treating weak references as a single level of
indirection, I think you have to treat them as a single
overridable interface. In a dynamically-linked application, we
might try to perform an override using the LD_PRELOAD feature.
But in a statically-linked application we have to do it
differently. The overriding archive must be named in full, and
it must be named as an object to be linked instead of a library
to be searched. Furthermore, an interface can have only one
override that ends up in the linked application.</div>
</blockquote>
Yes, you can only have one strong implementation, otherwise you get
multiple definition errors.<br>
</body>
</html>