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/TM4C1294NCPDT: Does TI linker generate something like etext, edata and end?

Part Number: TM4C1294NCPDT

Tool/software: TI C/C++ Compiler

Usually linkers provide the symbols etext, edata and end to indicate the one-past-the-last address of sections text, data and bss, respectively, so a programmer can use those symbols in a C program.

I'd like to have access to those symbols to be able to know what is the address of ram memory that corresponds to the first address of free memory, so I can use end as the start of heap.

Is there a flag that makes the linker provide those symbols to a C program? Is there an easier way of knowing what is the free memory region?

P.S.: I know the compiler libraries probably implement basic memory management and I could just use the standard C functions for dynamic memory allocation. But I want to implement it on my own for two reasons:

  1. I want to learn how to do it;
  2. I'm writing an OS and I want the OS to manage the memory.

  • rrd said:
    Is there a flag that makes the linker provide those symbols to a C program?

    There is no flag.  There is a list of symbols which are always defined.  Please see the section titled Symbols Defined by the Linker in the ARM assembly language tools manual.

    rrd said:
    I'd like to have access to those symbols to be able to know what is the address of ram memory that corresponds to the first address of free memory, so I can use end as the start of heap.

    One of the symbols is named end.  But it doesn't work like that.  The symbol end marks the end of the .bss section.  The linker cannot guarantee that the .bss section is located at the highest address.  But there are ways the user can do that.

    One way ... Put only .bss in the highest memory range.  No other section can go in that memory range.

    Another way ... If multiple sections need to go in the highest memory range, then you can apply the high specifier to only the .bss section.  For details, see the section titled Controlling Placement Using The HIGH Location Specifier in the same manual.  

    There are other methods.  But these two give you the general idea.

    Thanks and regards,

    -George

  • Hi George,

    You said end is one of the symbols that are always defined by the linker. So I may be doing something wrong here.

    Section 8.6.1 Using Linker Symbols in C/C++ Applications of ARM Assembly Language Tools says that linker symbols are declared in C code using extern char symbol_name;. The same section says that C code can refer to the linker symbol using _symval(&symbol_name). Following those instructions I'm testing if I can access end with the following code, but the compiler returns an error saying end is not defined. 

    extern char end;
    
    int main()
    {
        int a = _symval(&end);
        return 0;
    }

    What am I missing?

  • I apologize.  The documentation is incorrect.  The symbol end is not automatically created.  I filed CODEGEN-4621 in the SDOWP system to have this corrected.  You are welcome to follow it with the SDOWP link below in my signature.

    You can create your own symbols with the operator RUN_END. 

        .bss > RAM, RUN_END(end)

    Please read more about this feature in the section titled Address and Dimension Operators in the ARM assembly language tools manual.

    Thanks and regards,

    -George