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.

Compiler: Linker , loader and initialized memory



Tool/software: TI C/C++ Compiler

Hello,

If i am defining a section in the linker command file which is mapped to one of the defined memories, in what situations will the loader (or the linker in the image itself) initialize this area to zero or some other value?

What i need to know is  if i have a program which writes to a specific section some data, and than loads another program which have this same section defined will loading the second program erase what what written by the first one (if the NOLOAD keyword is NOT used) ? if so does the only way to prevent it is using NOLOAD or is there another way?

Thanks

  • Guy Mardiks said:
     if i have a program which writes to a specific section some data, and than loads another program which have this same section defined will loading the second program erase what what written by the first one (if the NOLOAD keyword is NOT used) ?

    First, let's clarify some terms.  Please use the terms from the Glossary section of the wiki article Linker Command File Primer.  In this case, the important difference is that what you term a "section" is called a "memory range".  So, to restate your question: The first program writes data to a memory range.  Then it loads a second program which places initialized values in this same memory range.  What happens?  I presume I have stated things correctly.

    I think I fail to understand something that seems more fundamental.  Without regard to how it is implemented, what do you want to happen?  Because, if the second program uses the same memory range, I don't see any way to avoid overwriting the data from the first program.  Which leads me to conclude I misunderstand what you want to do.

    Thanks and regards,

    -George

  • Hi,
    I am sorry i was not clear enough, i will try to clear it a bit more.
    For C programs the .bss is being initialized to zero by the C platform initialization routine.
    I want to be sure that if i am defining some new section (in the SECTION part) in the linker command file that is mapped to a certain memory region (from the MEMORY part) and i have the same exact linker configuration in two program where one loads the other.
    now the first program has some code (and/or maybe data) assigned to that section (using the pragma keyword) so it is being initialized by the first program. the second program does not allocate anything to this section it only exist in its linker file so it will know where it exists in memory (it can reference the same location that the first program initialized). from what i know (and saw) since the second program do not allocate anything to the section its content should remain untouched and contain what the first program wrote there. i just want to make sure this indeed something i can count on or if this is not guaranteed (i.e. from some reason there could be some initialization for the sections always - maybe like what is being done by C init with the .bss section)

    Thanks
    Guy
  • I think something like this would work for you ...

    #pragma LOCATION(shared_variable, 0x1000)
    #ifdef PROG2   /* PROG2 defined only when building 2nd program */
    #pragma NOINIT(shared_variable)
    #endif
    int shared_variable;
    

    This appears in a source file that is used in both programs.  The preprocessor symbol PROG2 is defined, on the command line with -DPROG2, only when building the second program.  

    Read more about the LOCATION and NOINIT pragmas in the ARM compiler manual.  The LOCATION pragma means the shared variable is at the same location in both programs.  The NOINIT pragma means the second program does not initialize it.

    Thanks and regards,

    -George

  • Hi,
    Thanks a lot for the advice.
    Just to be sure - if i have the section defined in the linker command file of the second program but the second program does not assign anything on it, only uses it by pointer to read from this area, there is no reason that this area shall be somehow initialized by the second program - is that correct? (my question refers both the CODE and DATA sections)

    Thanks
    Guy
  • My proposed solution works at the granularity of one C variable.  Note this variable can be one integer, as shown.  Or any other C type, including a structure, an array, an array of structures, and so on.  This solution cannot be applied to functions, i.e. code.

    Thanks and regards,

    -George