|
| 1 | +It seems that there is some issue with inlines and writing kernel modules in C++. |
| 2 | + |
| 3 | +Here is what we have came up with on the matter so far: |
| 4 | + |
| 5 | +When gcc and the linker find inline functions which are "big" (we do not know what that means exactly) |
| 6 | +then suddenly the link process in the kernel starts issueing "Unknown relocation: 0" error |
| 7 | +when trying to load the resulting module. |
| 8 | + |
| 9 | +If you really want to see the relations in a module you should use: |
| 10 | +objdump -r [object file or .ko file] |
| 11 | + |
| 12 | +Relocations come in 3 flavours: |
| 13 | +RX |
| 14 | +RX 386 |
| 15 | +and |
| 16 | +NONE |
| 17 | + |
| 18 | +Here is an example: |
| 19 | +objdump -r obj/modules/KFcb.ko | c++filt | grep NONE |
| 20 | +000009d8 R_386_NONE *ABS* |
| 21 | +000009ec R_386_NONE *ABS* |
| 22 | +00002b08 R_386_NONE *ABS* |
| 23 | +00002b1c R_386_NONE *ABS* |
| 24 | +00003698 R_386_NONE *ABS* |
| 25 | +.... more here .... |
| 26 | + |
| 27 | +The linux kernel knows how to handle only the first two ones. The user space dynamic linker |
| 28 | +probably knows how to handle all of them. |
| 29 | + |
| 30 | +We really don't know how to stop the compiler from doing whatever it is doing (we don't know if there is some magical --dont-do-relocation-shit flag to stop it). This needs to be ivestigated. |
| 31 | + |
| 32 | +*We did* prove that moving functions from being inline to non inline makes the problem go away. |
| 33 | + |
| 34 | +Addition (31 oct 09): |
| 35 | +===================== |
| 36 | +I have made an attempt to compile using -fpic/-fPIC to make the problem go away. |
| 37 | +It didn't. The error is: |
| 38 | +[28373.931835] KFcb: Unknown symbol _GLOBAL_OFFSET_TABLE_ |
| 39 | +It seems that -fPIC relies on the dynamic linker to provide this symbol and the kernel |
| 40 | +dynamic linker does not supply this service. |
| 41 | +I have made other efforts to make it go away (-mcmodel which does not apply - doens't work). |
| 42 | + |
| 43 | +SUCCESS!!! I have managed to make it go away by adding "-fno-exceptions". |
| 44 | +It seems that the compiler was generating exception handling code even though the code had nothing to |
| 45 | +do with exceptions. |
| 46 | + |
| 47 | + |
| 48 | + Mark Veltzer |
0 commit comments