7

I've written some kernel modules in Ada, and I've hit a bit of a problem. License is defined as a c macro, and I can't work out what it actually is. Is it a suitable solution to simply have some c re-exporting all the c functions which require GPL if both the c and the ada module have GPL compatible licenses? Is there a better way to do this?

Probie
  • 1,371
  • 7
  • 15

4 Answers4

6

I'm not sure if this question is a joke or not, but if you're serious about writing kernel modules in Ada, then I can't imagine that setting the module license is much of an obstacle compared to everything else you must have hit.

In any case, the module license is just a string like "license=GPL" in the .modinfo section of the .ko file. In C code, it's built by the __MODULE_INFO() macro from <linux/moduleparam.h>, which just creates an array of char that is set to the string as above, tagged with __attribute__((section(".modinfo"))).

I would guess that there is probably some analogous way to do this in Ada; if not, in the worst case, it should be possible to do with a linker script. Presumably, you already have some way of handling this anyway, to set the "vermagic=XXX" part of the .modinfo section.

Roland
  • 6,227
  • 23
  • 29
  • Why would the question be a joke? I was also ready for just about every other obstacle I hit; I honestly didn't expect this to be a real issue. – Probie Aug 13 '12 at 11:56
  • because 1) it's really a lot easier if you just write your module in C and 2) it's a bit surprising you were able to solve everything else I'm sure you hit and then got stuck following the not-all-that-complex expansion of the MODULE_LICENSE() macro. – Roland Aug 13 '12 at 14:36
  • 2
    There's no good reason (other than political ones) why one couldn't write a kernel module in Ada. I'll agree that it at first seems surprising that something as seemingly basic as C macros would be the biggest interoperability stumbling block, but I've seen it happen myself multiple times. Macros are evil. – T.E.D. Aug 13 '12 at 14:53
  • No good reason other than political ones and all the practical ones, like having to reverse engineer these macros (and staying up-to-date as the module implementation changes). And is there any good reason to take on the pain of impedence-matching Ada code with the kernel? – Roland Aug 13 '12 at 15:34
  • 2
    @Roland - That sounds like a separate SE question. If you really want an answer, you should ask it that way. As someone who knows both languages fairly well (although I do most of my kernel programming in RTOSes, not Linux), my answer would certianly be yes. There are many situations where it would easily be worth it, once you figure out how to do it. – T.E.D. Aug 13 '12 at 16:42
  • 1
    I have proper static verification tools for ada, I can't find anything close for c. So yes. It is worth it. – Probie Aug 14 '12 at 10:18
6

Dealing with C macros is a royal PITA. I have a dream that one day C programmers will do the rest of the world a favor and quit using them.

If it were me, I'd run the macro to see what it outputs, then write some Ada code to output the equivalent.

From reading through Roland's answer, it looks to me like the implementation-defined pragma linker_section may be required.

pragma Linker_Section ( [Entity =>] LOCAL_NAME, [Section =>] static_string_EXPRESSION);

LOCAL_NAME must refer to an object that is declared at the library level. This pragma specifies the name of the linker section for the given entity. It is equivalent to __attribute__((section)) in GNU C and causes LOCAL_NAME to be placed in the static_string_EXPRESSION section of the executable (assuming the linker doesn't rename the section).

T.E.D.
  • 44,016
  • 10
  • 73
  • 134
3

As an approach to sidestepping the problem, Could you leave the license part in C and use Annex B (Interfacing with other languages) features to access it ?

This should contain the problem at least, and allow you to move on with other modules.

At best it may allow you to examine in Ada, what the license looks like and reverse engineer it that way.

NWS
  • 3,080
  • 1
  • 19
  • 34
2

As you are probably using GNAT, you may be able to use pragma License "to allow automated checking for appropriate license conditions with respect to the standard and modified GPL."

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • @Probie: I see what you mean; it only checks compatibility, but it might complement T.E.D.'s [suggestion](http://stackoverflow.com/a/11936532/230513). – trashgod Aug 13 '12 at 15:10