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.

Running out of BSS space when using http_lib.lib

Other Parts Discussed in Thread: MSP430F5529

In our application, we need to link in the http_lib library.  When we do this though, we get a "program will not fit into available memory.  run placement with alignment fails for section '.bss'" error.

Does the compiler allocate space for all of the global variables within http_lib.lib... even the unused ones?  Can we work around this by using select source code files instead of linking in all of http_lib.lib?

  • Which CPU family do you use?  What ABI do you build with? 

    Dean Velasco said:
    Does the compiler allocate space for all of the global variables within http_lib.lib... even the unused ones?

    Generally speaking, no.  The linker brings an object file in from a library only when that file supplies at least one function or data variable required by the program.  But there is more to it than that.  To be more specific, I need the answers to my questions above.

    Thanks and regards,

    -George

  • We're using an MSP430F5529 and legacy COFF.

  • This explanation only pertains to COFF ABI builds.  Things are different when you build with EABI.

    Suppose a file in a library defines two global variables ...

    int lib_global_is_used;
    int lib_global_never_used;
    

    Your code needs the symbol lib_global_is_used.  When you link, this file is brought in from the library.  Space is reserved for both lib_global_is used and lib_global_never_used.  Thus some amount of data memory is wasted. 

    Suppose a file in a library defines a global variable and a function ...

    int lib_global_never_used;
    int lib_function_is_called()
    {
        /* code here */
    }
    

    Your code calls the function lib_function_is_called.  When you link, this file is brought in from the library.  Space is reserved for lib_global_never_used.  Again, some amount of data memory is wasted.

    These are the scenarios under which a library can cause data memory to wasted.

    Thanks and regards,

    -George

  • Thanks for the explanation.  How does the behavior differ if we use EABI?  

  • Under EABI, global data variables are placed in a section called the common section.  Any variable placed in the common section is removed if not used.

    The way it works is the compiler places uninitialized global variables in the common section.  The linker collects all common variables together.  Any variables not used are removed.  The remaining variables are allocated a place in system memory.

    Thanks and regards,

    -George