This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

visibility of functions names in Library

Hi, I made a library. when i build executable using library, the map file created shows all functions/variables of library.

Can i strip the library, so that only functions used by executable are visible in map file ?

or when i build library, i can somehow achieve the same by some settings ?

thanks in advance for your time.

regards,
-rajan batra

Parents
  • No. Please read slower and think carefully about what has been said in this thread.

    If you want the map file not not mention symbols that aren't used by the program, the way to do it is to make sure that the linker doesn't include any code that isn't needed.

    The way to do that is _normally_ to make sure that the LIB file is a container of many small object files - each object file generated from a source file that only contains a single function.

    The linker will then see the library, but will only bring in any object file that contains a required symbol. All other object files will be ignored, so any symbols in them will not be part of the resulting binary. And so will not show up in the map file.

    And as also previously mentioned - some compilers happens to have a compiler switch where individual functions in a source file can be placed into individual sections inside a single object file, to allow the linker to not bring in the full object file but just extract individual sections from the object file. This is a feature that at least GCC has, but maybe other compilers/linkers can manage similarly.

    Anyway - to get less symbols mentioned in the map file, you need to give the linker an ability to not include any symbols that aren't needed. So it's all a question of granularity of the blocks that the linker grabs object data from. It has nothing to do with you having one or seven libraries. It has all to do with the contents of the libraries - how small pieces each individual library file can be splitted into by the linker.

Reply
  • No. Please read slower and think carefully about what has been said in this thread.

    If you want the map file not not mention symbols that aren't used by the program, the way to do it is to make sure that the linker doesn't include any code that isn't needed.

    The way to do that is _normally_ to make sure that the LIB file is a container of many small object files - each object file generated from a source file that only contains a single function.

    The linker will then see the library, but will only bring in any object file that contains a required symbol. All other object files will be ignored, so any symbols in them will not be part of the resulting binary. And so will not show up in the map file.

    And as also previously mentioned - some compilers happens to have a compiler switch where individual functions in a source file can be placed into individual sections inside a single object file, to allow the linker to not bring in the full object file but just extract individual sections from the object file. This is a feature that at least GCC has, but maybe other compilers/linkers can manage similarly.

    Anyway - to get less symbols mentioned in the map file, you need to give the linker an ability to not include any symbols that aren't needed. So it's all a question of granularity of the blocks that the linker grabs object data from. It has nothing to do with you having one or seven libraries. It has all to do with the contents of the libraries - how small pieces each individual library file can be splitted into by the linker.

Children