* iproute2: iplink_ stuff cleanup
@ 2012-03-15 13:53 Yegor Yefremov
2012-03-15 16:18 ` Stephen Hemminger
0 siblings, 1 reply; 4+ messages in thread
From: Yegor Yefremov @ 2012-03-15 13:53 UTC (permalink / raw)
To: shemminger; +Cc: netdev
Hello Stephen,
I'm still struggling to get ip/iplink_* routines to show up in
Android's ip binary
(https://groups.google.com/d/topic/android-building/yjV4iYnT1Zc/discussion).
I've looked at the algorithm that is used to access those functions
(like can_parse_opt, vlan_parse_opt etc.)
snprintf(buf, sizeof(buf), LIBDIR "/ip/link_%s.so", id);
dlh = dlopen(buf, RTLD_LAZY);
if (dlh == NULL) {
/* look in current binary, only open once */
dlh = BODY;
if (dlh == NULL) {
dlh = BODY = dlopen(NULL, RTLD_LAZY);
if (dlh == NULL)
return NULL;
}
}
snprintf(buf, sizeof(buf), "%s_link_util", id);
l = dlsym(dlh, buf);
if (l == NULL)
return NULL;
as far as I can see from the ip/Makefile there are no dynamic libs
like /ip/link_%s.so. Wouldn't it be simpler to let all iplink_*
objects to export their interfaces via header files and just make a
table in ip/iplink.c to hold protocol ID and pointer at link_utils
struct.
struct link_util can_link_util = {
.id = "can",
.maxattr = IFLA_CAN_MAX,
.parse_opt = can_parse_opt,
.print_opt = can_print_opt,
.print_xstats = can_print_xstats,
};
Am I missing something?
Regards,
Yegor
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: iproute2: iplink_ stuff cleanup
2012-03-15 13:53 iproute2: iplink_ stuff cleanup Yegor Yefremov
@ 2012-03-15 16:18 ` Stephen Hemminger
2012-03-19 22:22 ` Yegor Yefremov
0 siblings, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2012-03-15 16:18 UTC (permalink / raw)
To: Yegor Yefremov; +Cc: netdev
On Thu, 15 Mar 2012 14:53:51 +0100
Yegor Yefremov <yegorslists@googlemail.com> wrote:
> Hello Stephen,
>
> I'm still struggling to get ip/iplink_* routines to show up in
> Android's ip binary
> (https://groups.google.com/d/topic/android-building/yjV4iYnT1Zc/discussion).
> I've looked at the algorithm that is used to access those functions
> (like can_parse_opt, vlan_parse_opt etc.)
>
> snprintf(buf, sizeof(buf), LIBDIR "/ip/link_%s.so", id);
> dlh = dlopen(buf, RTLD_LAZY);
> if (dlh == NULL) {
> /* look in current binary, only open once */
> dlh = BODY;
> if (dlh == NULL) {
> dlh = BODY = dlopen(NULL, RTLD_LAZY);
> if (dlh == NULL)
> return NULL;
> }
> }
>
> snprintf(buf, sizeof(buf), "%s_link_util", id);
> l = dlsym(dlh, buf);
> if (l == NULL)
> return NULL;
>
> as far as I can see from the ip/Makefile there are no dynamic libs
> like /ip/link_%s.so. Wouldn't it be simpler to let all iplink_*
> objects to export their interfaces via header files and just make a
> table in ip/iplink.c to hold protocol ID and pointer at link_utils
> struct.
>
> struct link_util can_link_util = {
> .id = "can",
> .maxattr = IFLA_CAN_MAX,
> .parse_opt = can_parse_opt,
> .print_opt = can_print_opt,
> .print_xstats = can_print_xstats,
> };
>
> Am I missing something?
>
> Regards,
> Yegor
Ip utilities have dynamic extensibility, it is possible for someone
to add shared libraries for new functionality. This is a cool feature
but isn't used directly by the standard code. It does use it indirectly
by using dlopen() to find functions locally.
Think of it as introspection in C.
I won't take it out of the standard version, but you may have to find
another way to handle it on the Android universe.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: iproute2: iplink_ stuff cleanup
2012-03-15 16:18 ` Stephen Hemminger
@ 2012-03-19 22:22 ` Yegor Yefremov
2012-03-19 22:53 ` Stephen Hemminger
0 siblings, 1 reply; 4+ messages in thread
From: Yegor Yefremov @ 2012-03-19 22:22 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
>> I'm still struggling to get ip/iplink_* routines to show up in
>> Android's ip binary
>> (https://groups.google.com/d/topic/android-building/yjV4iYnT1Zc/discussion).
>> I've looked at the algorithm that is used to access those functions
>> (like can_parse_opt, vlan_parse_opt etc.)
>>
>> snprintf(buf, sizeof(buf), LIBDIR "/ip/link_%s.so", id);
>> dlh = dlopen(buf, RTLD_LAZY);
>> if (dlh == NULL) {
>> /* look in current binary, only open once */
>> dlh = BODY;
>> if (dlh == NULL) {
>> dlh = BODY = dlopen(NULL, RTLD_LAZY);
>> if (dlh == NULL)
>> return NULL;
>> }
>> }
>>
>> snprintf(buf, sizeof(buf), "%s_link_util", id);
>> l = dlsym(dlh, buf);
>> if (l == NULL)
>> return NULL;
>>
>> as far as I can see from the ip/Makefile there are no dynamic libs
>> like /ip/link_%s.so. Wouldn't it be simpler to let all iplink_*
>> objects to export their interfaces via header files and just make a
>> table in ip/iplink.c to hold protocol ID and pointer at link_utils
>> struct.
>>
>> struct link_util can_link_util = {
>> .id = "can",
>> .maxattr = IFLA_CAN_MAX,
>> .parse_opt = can_parse_opt,
>> .print_opt = can_print_opt,
>> .print_xstats = can_print_xstats,
>> };
>>
>> Am I missing something?
>>
>> Regards,
>> Yegor
>
> Ip utilities have dynamic extensibility, it is possible for someone
> to add shared libraries for new functionality. This is a cool feature
> but isn't used directly by the standard code. It does use it indirectly
> by using dlopen() to find functions locally.
>
> Think of it as introspection in C.
>
> I won't take it out of the standard version, but you may have to find
> another way to handle it on the Android universe.
The solution turned out to be simple:
https://android-review.googlesource.com/#/c/34240/.
-Wl,--no-gc-sections did the job.
Can you suggest some more pro arguments for dynamic method of
exporting API routines?
Regards,
Yegor
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: iproute2: iplink_ stuff cleanup
2012-03-19 22:22 ` Yegor Yefremov
@ 2012-03-19 22:53 ` Stephen Hemminger
0 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2012-03-19 22:53 UTC (permalink / raw)
To: Yegor Yefremov; +Cc: netdev
On Mon, 19 Mar 2012 23:22:59 +0100
Yegor Yefremov <yegorslists@googlemail.com> wrote:
> >> I'm still struggling to get ip/iplink_* routines to show up in
> >> Android's ip binary
> >> (https://groups.google.com/d/topic/android-building/yjV4iYnT1Zc/discussion).
> >> I've looked at the algorithm that is used to access those functions
> >> (like can_parse_opt, vlan_parse_opt etc.)
> >>
> >> snprintf(buf, sizeof(buf), LIBDIR "/ip/link_%s.so", id);
> >> dlh = dlopen(buf, RTLD_LAZY);
> >> if (dlh == NULL) {
> >> /* look in current binary, only open once */
> >> dlh = BODY;
> >> if (dlh == NULL) {
> >> dlh = BODY = dlopen(NULL, RTLD_LAZY);
> >> if (dlh == NULL)
> >> return NULL;
> >> }
> >> }
> >>
> >> snprintf(buf, sizeof(buf), "%s_link_util", id);
> >> l = dlsym(dlh, buf);
> >> if (l == NULL)
> >> return NULL;
> >>
> >> as far as I can see from the ip/Makefile there are no dynamic libs
> >> like /ip/link_%s.so. Wouldn't it be simpler to let all iplink_*
> >> objects to export their interfaces via header files and just make a
> >> table in ip/iplink.c to hold protocol ID and pointer at link_utils
> >> struct.
> >>
> >> struct link_util can_link_util = {
> >> .id = "can",
> >> .maxattr = IFLA_CAN_MAX,
> >> .parse_opt = can_parse_opt,
> >> .print_opt = can_print_opt,
> >> .print_xstats = can_print_xstats,
> >> };
> >>
> >> Am I missing something?
> >>
> >> Regards,
> >> Yegor
> >
> > Ip utilities have dynamic extensibility, it is possible for someone
> > to add shared libraries for new functionality. This is a cool feature
> > but isn't used directly by the standard code. It does use it indirectly
> > by using dlopen() to find functions locally.
> >
> > Think of it as introspection in C.
> >
> > I won't take it out of the standard version, but you may have to find
> > another way to handle it on the Android universe.
>
> The solution turned out to be simple:
> https://android-review.googlesource.com/#/c/34240/.
> -Wl,--no-gc-sections did the job.
>
> Can you suggest some more pro arguments for dynamic method of
> exporting API routines?
You could make it optional on your platform, but for mainline Linux
it has been around long enough that someone surely depends on it.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-03-19 22:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-15 13:53 iproute2: iplink_ stuff cleanup Yegor Yefremov
2012-03-15 16:18 ` Stephen Hemminger
2012-03-19 22:22 ` Yegor Yefremov
2012-03-19 22:53 ` Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox