0

MY GOAL IS: to compile a static library (normally .a extension) and have internal symbols hidden (function and variable names) when I open the library file with a text editor.

Currently I am on XC32 compiler of Microchip Technology, who makes the well known PIC microcontrollers.

Actually I can't share here my lib, but I have created a very simple one to make tests. C source code is only:

int variable;

int sum (int a, int b) 
{
    return a+b;
}

and header is only:

int sum (int a, int b);

Created a library project on mplabX IDE and selected XC32 compiler. The project properties show these options:

enter image description here I did changed these option:

  • xc32-as -> Have symbols in production build. uncheked
  • xc32-gcc -> Have symbols in production build. uncheked
  • xc32-ld -> Symbols & Macros -> Symbols. Selected option "strip all symbol info"

Then compiled. Library (.a extension) was generated. I opened it with text editor and the see theat the symbols are yet being shown:

enter image description here

For each of the compiler sections (xc32-as, xc32-gcc, xc32-ld etc), There is a field "Additional options".

I tried to input these options, but no one worked to hide the symbols:

  • -fvisibility=hidden on gcc and ld
  • -fvisibility=hidden on gcc and strip -r -S -x on ld

If I try strip -r -S -x on gcc I get:

  • pic32m-gcc.exe: error: strip: No such file or directory

  • pic32m-gcc.exe: error: missing argument to '-x'

Then I removed the addicional options for ld and gcc, placed "static" in front of the variable and function, and C source become:

static int variable;

static int sum (int a, int b) 
{
    return a+b;
}

Doing this (adding static in front of all), the symbols get correctly hidden. But on the other hand I am not able to use the lib attached to my app project, because when the compiler shows "undefined reference" to the functions of the lib. This is because: [From Wikipedia] In the C programming language, static is used with global variables and functions to set their scope to the containing file.

Then, how can I reach my goal in this case? (first phrase of the topic). Regards.

EDIT: This is being shown on the project properties on the IDE, I am compiling with it.

enter image description here

All the internal symbols are being shown near the bottom of the lib file where it shows the name of the c file, only in this place shows to c filename

abomin3v3l
  • 167
  • 1
  • 10
  • 2
    You can't remove all symbols. At least not the external ones. The point of a library is that it will be used to link into other objects that use its symbols. If there are no symbols how would the linker find them? – kaylum Mar 28 '20 at 20:59
  • @kaylum I understand you. Yes, there are 3 functions that can be visible, but there are other functions that are used only inside this lib, and the variables are used only inside this lib. Then, do I need to add static to all except for the external functions? – abomin3v3l Mar 28 '20 at 21:01
  • 1
    Does this answer your question? [Restricting symbols in a Linux static library](https://stackoverflow.com/questions/393980/restricting-symbols-in-a-linux-static-library) – kaylum Mar 28 '20 at 21:11
  • 1
    Also, you may want to edit your question as it says: "have **all** symbols hidden". Which seemingly contradicts what you have in your comment (and which led to my first comment). – kaylum Mar 28 '20 at 21:17
  • @kaylum Edited... No I was not able to make it work. And after added static in front, actually did not solved, because the internal symbols are yet appearing near the bottom of the file on the editor – abomin3v3l Mar 28 '20 at 21:30
  • @kaylum please check the bottom of the topic now, I added a picture. – abomin3v3l Mar 28 '20 at 21:43

0 Answers0