-1

I have an embedded application. The platform on which the program is ran is very limited in terms of resources(code memory included).

So I have a huge open-source library(.c and .h files), which is built along with my application(user) files.

Let assume I have a simple program in main.c that never invokes any of the library functions. Example:

#include "main.h"

volatile int a;

int main()
{
  while(1)
  {
    if(a)
    {
      a=0;
    }
  }
 return 0;
}

I the example above, let say main.h includes all the library header files. The size of the the .text or ROM section (in my opinion) should be very small, because the program does not need(at the current state of development) any of the library's functions (Let assume I include them for premature design).

Will the size of the code memory be as big as to contain all the compiled symbols? Or (somehow) the linker is smart enough to know that not-referenced symbols have no place in the output?

If yes, what is the mechanism that determines what symbol (from object files pool) is to be placed in the output?

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
Hairi
  • 3,318
  • 2
  • 29
  • 68
  • 2
    Unless the compilation system is severely defective (or the headers define things that they should merely declare) the output will only include references to the symbols used by your program. – Jonathan Leffler Aug 02 '18 at 11:33
  • @ Jonathan Leffler 4 Hypothetically: What if I call pointer to a library function that should be at a given (known) address in the memory? – Hairi Aug 02 '18 at 11:37
  • If you reference the function by name, it should be included in the build. If you only reference it by address, you’re unlikely to be happy with what happens. – Jonathan Leffler Aug 02 '18 at 11:39

1 Answers1

0

I would like to add answer to my question since no one did so far just comments of the type because this is how linker works(which give no information). So after a lot of search I came across to this SO question. It explains the mechanism behind linker's decision making algorithm. Namely what stays and what goes away :).

Hairi
  • 3,318
  • 2
  • 29
  • 68