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
  • Hi, you are suggesting to edit library object files and edit the names of
    functions which are not referred by Main executable. rite ?

    I have 7 Libraries ( for 7 banks ), so if i want , main executable to
    include 7 libraries, i will have to keep functions/globals used by other bank-libraries
    available for final linking. In way, again exposing most of function names and variables.

    does this option looks possible ?

    a ) Make one big library, (size == 7 bank capacity)

    b) Edit functions names in object files (as suggested by you)

    c) Break individual Libraries to fit in individual Banks.(not sure if this is possible)

    I read something similiar in this forum : http://www.keil.com/forum/17588/. but the discussion is incomplete.

    any thoughts ?

Reply
  • Hi, you are suggesting to edit library object files and edit the names of
    functions which are not referred by Main executable. rite ?

    I have 7 Libraries ( for 7 banks ), so if i want , main executable to
    include 7 libraries, i will have to keep functions/globals used by other bank-libraries
    available for final linking. In way, again exposing most of function names and variables.

    does this option looks possible ?

    a ) Make one big library, (size == 7 bank capacity)

    b) Edit functions names in object files (as suggested by you)

    c) Break individual Libraries to fit in individual Banks.(not sure if this is possible)

    I read something similiar in this forum : http://www.keil.com/forum/17588/. but the discussion is incomplete.

    any thoughts ?

Children
  • Not sure I'd characterize it as "editing" that's a bit too manual labour for me, I'm suggesting the automatic processing of files.

    You'd look to obfuscate, flatten or remove internal references, and perhaps have a white-list of function names that get exported cleanly, and then another list doing translations across multiple files/modules.

    You'd look to coalesce object/library functions into bigger anonymized lumps.

    A lot of things are possible, experience and ingenuity helps getting them done.

    Topics to review: object and library file formats, linkers and loaders.

  • It doesn't sound like the question is about obfuscation, but about how to only link in the functions that are actually used.

    The most common method for that is to split the library source code into many separate source files, so the library consists of many small object files - the linker will then only pick up the object files that are needed to fulfill any accesses to symbols within the individual object files. So the map file will then only mention symbols existing in the object files that was actually used.

    It's a very long time since I last used C51 tools - you have to check if the linker has any suitable special features to extract only parts of the contents of the individual object files from the library or if it's only possible to link in full object files.

  • Perhaps, I keyed off the "visibility" cue.

    If this is more of a dead code elimination question, then the trick with libraries is to break the objects inside into the smallest possible pieces. Some ARM/X86 tools do this using a section-per-function option for the compiler. Others do it by creating a file-per-function. Either way the goal is to allow the linker to determine the actual dependencies, and throw out everything that isn't used/required.

    If the linker isn't that smart you'd need to generate your own dependency trees, and apply that knowledge to the source and librarian tools, and remove as much cruft as possible before letting the linker do it's thing.

  • I have 7 Libraries ( for 7 banks ),

    No, you don't. Because there's no such thing as a "Library for a bank". Banking has nothing to do with libraries.

    That means that most likely what you think of as a "library" is in fact something else entirely, and we really should all take a couple steps back and figure out what the words you're using actually mean. So: what exactly is that think you're calling a "library"? How did you create it, and how do you plan on using it?

  • Hi Hans-Bernhard Broeker, Westonsupermare Pier

    my code consumes 7 banks + common bank. There is one bank left. I have arranged
    code such that, each bank has inter-related functionalities. this is to avoid much
    of bank switching code at run time.

    I have to make object files out of my code and make it available for anyone making
    an executable. executable will use code functions via set of defined APIs.

    I directly make .LIB for each bank code. This gives me common.LIB, BANK0.LIB, BANK1.LIB,
    BANK2.LIB, BANK3.LIB, BANK4.LIB,BANK5.LIB and BANK6.LIB.

    www.keil.com/.../uv4_ca_createlibraryfile.htm

    This i call as library. Main function executable will go in bank7 and it will link these .LIB.

  • Hi Per, looking at .map file linker is generating, i am able to see those
    functions/global variables which are not used by final executable.

    This probably is happening because at time of linking, i am giving bank0.LIB,
    bank1.LIB, bank2.LIB, bank3.LIB , bank4.LIB, bank5.LIB , bank6.LIB for linking with
    main function code in bank7.

    As per your comment, it seems like, to avoid seeing all functions in .map , Linking
    should have only one .LIB and final code in bank7.

    Total code in .LIB will greater then bank capacity. so final compiling will give me
    Bank overflow error.

    regards,

  • Hi Pier, Since i am having 7 .LIB files to be linked in to executable, MAP
    file created by linker will contain all functions/variables referred between 7 .LIB

    As per your suggestion, i will have to make one single .LIB for final linking.
    Size of this One .LIB will be greater then single bank size. so in final linking,using keil,
    i will get warning of .LIB being greater then bank.

    I am using LX51, LX51 creates single HEX format executable as output. Currently i split it into 8 banks before flashing.

    If i could build final executable without assigning .LIB to any bank, i can build my code into
    one big .LIB .

    so the question is

    is it possible to build program in KEIL without assigning bank to .LIB.

    regards,
    -rajan

  • Hi Pier, Since i am having 7 .LIB files to be linked in to executable, MAP
    file created by linker will contain all functions/variables referred between 7 .LIB

    As per your suggestion, i will have to make one single .LIB for final linking.
    Size of this One .LIB will be greater then single bank size. so in final linking,using keil,
    i will get warning of .LIB being greater then bank.

    I am using LX51, LX51 creates single HEX format executable as output. Currently i split it into 8 banks before flashing.

    If i could build final executable without assigning .LIB to any bank, i can build my code into
    one big .LIB .

    so the question is

    is it possible to build program in KEIL without assigning bank to .LIB.

    regards,
    -rajan

  • 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.

  • Hi Pier, I got the point. This would be uphill task for current project size. i was looking for
    more automated way of doing, some linker settings.

    regards,