This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

selftestFailNotification not so weak?

Other Parts Discussed in Thread: HALCOGEN

I have a project where the driver code is generated by HalCoGen 4.05.02. As much as possible, I've been trying to keep my code separate, and avoid having to use the user code sections. 

I'm adding self-testing to my application, and I want to use the selftestFailNotification function to know when a test fails. It's defined with  #pragma WEAK(selftestFailNotification), but when I make my own function to override it, my function doesn't get called. The one in sys_selftest.c that I'm trying to override, gets called instead.

I've overridden many of the weak symbols in notification.c without any trouble, and they seem to be defined the same way, but for some reason selftestFailNotification isn't behaving the same way. 

Is there something I can change in the Symbol Management properties to force my function to override the default one? Is there a reason why I can override weak functions from notification.c, but not from sys_selftest.c?

  • which compiler/linker are you using?
  • I'm using the TI 5.2.0 compiler, and RM42 is the target.
  • Hmm. should work with the TI compiler .. it's a TI compiler pragma [not sure about other compilers].
    And you are saying it works for other symbols... Might need a test case from you but let me check the manual first.
  • Might be:

    "A weak definition does not change the rules by which object files are selected from libraries. However, if a
    link set contains both a weak definition and a non-weak definition, the non-weak definition is always used."

    Can you try making sure that your object comes on the linker command line before the safety library object?
  • Moving my object earlier in the command line didn't work. My application code gets compiled into a lib, and that lib is linked in with the project containing the HalCoGen code, which produces the binary. It was the .lib that I moved up in the command line.

    Inside the lib I have a file with my overridden notifications:
    void rtiNotification(uint32 notification) {...}
    void sciNotification(sciBASE_t* sci, uint32 flags) {...}
    void gioNotification(gioPORT_t* port, uint32 bit) {...}
    void pwmNotification(hetBASE_t* hetREG, uint32 pwm, uint32 notification) {...}
    void selftestFailNotification(uint32 flag) {...}
    (the rest of my functions)

    They're all in the same object, in the same lib. I can try linking the objects individually, and moving this one up, but it's already working for everything but selftestFailNotification.
  • I just did another test where I separated the file described above from the rest of the .lib, and added just that object before all the halCoGen objects on the linker command line, and got the same result.

    Could this have something to do with the fact that selftestFailNotification is called from the same function it's weakly defined in, but the rest of them are defined in a file that has no calls?
  • Hi Greg,

    Greg Davies said:

    Could this have something to do with the fact that selftestFailNotification is called from the same function it's weakly defined in, but the rest of them are defined in a file that has no calls?

    Sounds like a good thing to run down.   Honestly this might be a better question for the compiler forum:

      

    But...

    What do you mean exactly by  "is called from the same function it's weakly defined in" ?

    Would it be possible to paste the relevant code that illustrates this here?

  • Do you mean that the call to 'selftestFailNotification' and the function itself are in the same source file?
    if so that may be the problem. I think the linker only links in '.obj' files ... it doesn't break an object into functions and link at the function level. So if they are in the same .obj then probably this is the issue.
  • I meant to say it's called form the same file, not function.

    selftestFailNotification is defined in sys_selftest.c, which is generated by HalCoGen. In the same file, the very next function, ccmSelfCheck, has a call to selftestFailNotification around line 100.

    The other notification functions that are working, are all defined in notification.c. This file contains only weakly defined functions.

    As a quick test I moved selftestFailNotification into notification.c, and everything worked as I expected. I can't keep it like this because HalCoGen will continue to place this function in sys_selftest.c every time I generate the code. So it looks like there's a potential HalCoGen workaround, and a compiler bug in this issue.
  • Hi Greg,

    If the function call and the function definition are in the same file then I don't think this is a linker bug - I think it's just the way the linker operates (doesn't break down a .obj and link parts of an obj without linking other parts).

    We can confirm that on the compiler forum if you like but pretty sure this is the case from prior experience.

    Now if you think there is a *need* to override this function the maybe we need to generate a CQ report on HalCoGen just stating that it needs to be overridden therefore should be placed in a separate file.

    -Anthony
  • I posted a question to the compiler forum - if the answer is as I expect I'll put in a CQ for the HalCoGen project.
    e2e.ti.com/.../510739
  • I think the CQ report is probably the best way to do this. I posted on the compiler forum too e2e.ti.com/.../510742 but the formatting in the code examples is so bad that I don't know if it will make any sense.

    It turns out my non-weak definition works for calls from from every file except sys_selftest.c, even while the weakly defined one continues to be called from within that file.

    This issue is probably why notification.c was created in the first place, and I'm not sure why selftestFailNotification didn't get put there as well.
  • The answer to my original question was ultimately provided in this thread.
    e2e.ti.com/.../1854661

    I needed --gen_func_subsections=on

    It might still be worthwhile to tweak the output of HalCoGen to either move the function to notification.c or leave a note about the option in the source comments since it's not a default value for this option in new CCS projects.

    Thanks for the help, I really appreciate it.