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.

invoke one function in .lib, include functions code all?

my compiler version 6.0.19.

as I tried,  If you create one more functions in a lib project.

whether or not you invoke it, the main project 's size will be larger. why?

Do link process included all unused code into main project?

It's very strange to me.

  • I have taken a look that article.  But still have questions:

    As It says,  when you reference a single function in a lib, compiler include all functions within a same code region.

    But take the case of C standard library, when I use "memcpy()", It seemed only memcpy() is copyed into final BIN code.

    Is it implied that All C standard functions separated into many code region?

    But why I need register those code region in .CMD files?

  • Well, yes, most C standard functions are in their own .text section because for the most part each such function is in its own source file.  (Do "ar6x t <some RTS library file>" and you will see many object files, many of which will have familiar names corresponding to standard functions.)  You do not have to name each such section in the linker command file because they all match .text.

    If you have a file with many functions in it you can force each function into its own subsection (of .text) by compiling with the --gen_func_subsections option.

     

  • I should underscore the point implied by the last paragraph in my previous post.  As I said, if a file contains many functions and it is compiled with --gen_func_subsections the resulting object file has separate sections for each of the functions.  If that object file is placed in a library (archive) that is searched during a link, a reference to one of the functions will pull the section for that function into the link but will not pull in the others.