Honored Contributor II
12-04-2017 01:15 PM
Hello all,I posted a similar question on a different subforum about 2 weeks back, but since then I've found out more information about the problem, and also found that this subforum is probably more suitable for it. context: I'm working on a project employing the Nios II processor, and in my software part, in the BSP, when the _do_ctors() function runs (in alt_main()), the array bookended by __CTOR_LIST__ and __CTOR_END__ seems to contain bad data. When I ask for it to be logged, I get 49 values, 16 of which are 0x800683a (which I believe is misaligned and cannot be a valid function pointer, and even if it were, it doesn't point to a valid instruction) and 16 of which are 0x440034. The rest seem to be reasonable function pointers, with values ranging from 0x8411404 to 0x8459804, except one (at __CTOR_LIST__), which is 0x8dd9c, way outside the range of the others. The repeated values seem to bookend the "reasonable" values - enumerating from the end, you get 16x (0x800683a, "reasonable value", 0x440034), and at the very end (beginning) you get 0x8dd9c. Even if the contents of the array were supposed to look like that, there must be a different problem with this situation, as I end up with the following error whenever I try to run the code in debug mode: Program received signal SIGTRAP, Trace/breakpoint trap. 0x00080148 in alt_instruction_exception_entry () which appears to be triggered when calling 0x800683a as a function pointer (there's no valid instruction at this address). The program then refuses to go any further. I certainly don't have any breakpoints set there - this seems to be legitimately caused by an exception occurring. From what I understand about the system, the values at __CTOR_LIST__ are generated by the linker and correspond to calling the constructors of statically allocated C++ objects before main() starts, but I don't know how to check whether they are generated correctly. Not running _do_ctors() seems to "solve" my problem, as the SIGTRAP problem disappears, but I believe I'm leaving out some important initialization, although the code seems to run mostly fine (there isn't too much code in the constructors in this project). questions:
- Can you have a valid function pointer that is not divisible by 4?
- Do the values at __CTOR_LIST__ described above seem reasonable to you?
- Do you have any suggestions for how I can determine whether the array is generated correctly, or what might be causing this?
- Am I right in assuming that the _do_ctors() function is supposed to call the constructors of statically allocated C++ objects, which are supposed to be initialized before main() starts?
- How necessary is calling the _do_ctors() function? Can I have functioning C++ code without it, provided I move all important initialization outside of the constructors and call it explicitly?