Discussion:
[ORLinux] Transparent union semun?
Geert Uytterhoeven
2013-11-26 11:12:52 UTC
Permalink
Hi,

What's the story behind "__attribute__ ((transparent_union))" for union semun
in <linux/sem.h>?

When building for non-OpenRISC using an OpenRISC tree, I get the following
compiler warning:

include/uapi/linux/sem.h:45:7: warning: union cannot be made transparent

Thx!

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Jonas Bonn
2014-01-14 04:14:40 UTC
Permalink
Hi Geert,

I'm not quite sure what's going on but this email just appeared in my
inbox... dated 26/11/2013. Not sure where this has been hiding all this
time...
Post by Geert Uytterhoeven
Hi,
What's the story behind "__attribute__ ((transparent_union))" for union semun
in <linux/sem.h>?
When building for non-OpenRISC using an OpenRISC tree, I get the following
include/uapi/linux/sem.h:45:7: warning: union cannot be made transparent
At some point I tried posting this explanation to the kernel mailing
list. I hope it makes some sense. That said, I'm not convinced today
that this is the correct solution in general.

"The syscall handler for semctl is written under the assumption that the
toolchain will pass "small" unions as function parameters directly instead
of by reference. The union semun is "small" and thus fits this description.

Since it is assumed that the union will be passed directly and not by
reference, it is safe to access the union members without going via
get_user.

The OpenRISC architecture, however, passes all unions by reference, thus
breaking the above assumption.

The technically correct fix here is to mark the union as being transparent
so that the ABI of the union's first element determines the parameter
passing method and thus make explicit what's already implied in the function
definition."

...

I can expand on this, if necessary; but it's been a long time since I
found this problem and I'm not sure if it's still a problem with the
toolchain today (though I think it probably is).

/Jonas
Post by Geert Uytterhoeven
Thx!
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
_______________________________________________
Linux mailing list
Linux at lists.openrisc.net
http://lists.openrisc.net/listinfo/linux
Stefan Kristiansson
2014-01-14 05:56:30 UTC
Permalink
I can expand on this, if necessary; but it's been a long time since I found
this problem and I'm not sure if it's still a problem with the toolchain
today (though I think it probably is).
I can confirm that it still is, since it's not a toolchain bug, but an
ABI feature.

Stefan

Loading...