Limiting the size of global characters from related objects

I have a C library in an archive clib.a. I wrote a C ++ shell for it, cpp.oand would like to use this as a static library:

ar cTrvs cppwrap.a clib.a cpp.o

Code that references this will not be able to directly use the material from clib.aunless the correct header is included. However, if someone accidentally creates an appropriate prototype - for example void myCoincidentallyNamedGlobalFunction()- I’m concerned about what definition myCoincidentallyNamedGlobalFunctionwill be applied.

Since the characters from clib.ashould be available only in cpp.o, and not something related to cppwrap.a, is there a way to completely hide them so that there is no possible collision (so even including the cliff header failed)?

+4
source share
1 answer

You can manually delete unwanted characters in the last merged library:

$ objcopy -N foo cppwrap.a (delete character)

Or, if you need characters, but want to make sure that external users cannot reach them:

$ objcopy -L bar cppwrap.a (localize character)

Or, if the symbol clib.a should be visible by something in cpp.o, but you do not want anyone else to use it:

$ objcopy -W baz cppwrap.a (loosen symbol)

In this case, collisions with characters from other object files / libraries will be delayed until they are used, although the character will still be visible. To darken things or reduce the chances of even a shameful encounter, you can also use:

$ objcopy --redefine-sym old=new cppwrap.a

, , , , .

+2

Source: https://habr.com/ru/post/1540701/


All Articles