We're creating a application that has some XC code running in parallel with some C++ code. But if the C++ code tries to call a virtual function from a par statement in the XC code then we get a linker error such as:
../src/main.xc:(.text+0x4c): Error: Meta information ("_ZN11applicationC1Ev.nstackwords") for function "_ZN11applicationC1Ev" cannot be determined.
../src/main.xc:(.text+0x4c): Error: lower bound could not be calculated (function is recursive?).
Create an XK-1 project and add the 2 files attached as the source and you'll see the error. If main() calls application_main outside of the par statement, then it builds fine or if you call d.virtualFunc() rather than b->virtualFunc() in application_main.
This looks like an issue with the linker. Or is there an option I can enable to allow virtual function calls such as this?
Linker error with C++ virtual functions
-
- Junior Member
- Posts: 6
- Joined: Fri Jun 17, 2011 9:31 am
Linker error with C++ virtual functions
You do not have the required permissions to view the files attached to this post.
-
- Respected Member
- Posts: 318
- Joined: Tue Dec 15, 2009 12:46 am
The stack space needed for the thread that calls the virtual function can't be calculated at compile time since it is unknown which implementation of the virtual function will be called at runtime. You can provide the required stack space using the stackfunction pragma. You might find the following thread helpful:rhind wrote:We're creating a application that has some XC code running in parallel with some C++ code. But if the C++ code tries to call a virtual function from a par statement in the XC code then we get a linker error such as:
../src/main.xc:(.text+0x4c): Error: Meta information ("_ZN11applicationC1Ev.nstackwords") for function "_ZN11applicationC1Ev" cannot be determined.
../src/main.xc:(.text+0x4c): Error: lower bound could not be calculated (function is recursive?).
https://www.xcore.com/forum/viewtopic.p ... tion#p8537
I would guess the call to d.virtualFunc() works because the compiler can see the declaration of d and so it can optimise the virtual method call into normal function call. This allows it to calculate the stack space required for the call.Create an XK-1 project and add the 2 files attached as the source and you'll see the error. If main() calls application_main outside of the par statement, then it builds fine or if you call d.virtualFunc() rather than b->virtualFunc() in application_main.
-
- Junior Member
- Posts: 6
- Joined: Fri Jun 17, 2011 9:31 am
Thanks. Putting a stackfunction pragma on function calling the virtual function works. Also, for others hitting this problem, you can put it on the thread entry function (application_main) but you're then declaring the minimum stack space required by that thread but it does mean you only have to put the pragma once.
Also, from looking at http://www.xmos.com/discuss/viewtopic.php?f=6&t=449 you can put application_main as the last entry in the par statement and then don't have to put any pragmas in (assuming you aren't going to blow the stack limit).
Cheers
Russell
Also, from looking at http://www.xmos.com/discuss/viewtopic.php?f=6&t=449 you can put application_main as the last entry in the par statement and then don't have to put any pragmas in (assuming you aren't going to blow the stack limit).
Cheers
Russell