44498

Is there any way to override the -fvisibility=hidden at link time?

Question:

We are using an third party static library, let say A.a for android development. We link it as shared library and it works fine in the one App, but when use B.so to build another C.so, some symbols in A.a cannot find. We have already use -Wl,--export-dynamic and -Wl,--whole-archive to build B.so. We have using nm to check those symbols, it exist but list as “t” instead of “T”,which means it is local symbols instead of external. Seams the A.a are build with -fvisibility=hidden after som investigation.

But because some reason it is hard for us to got an new build library immediately, so we need some workaround. Is there any way to export those symbols as global even it has been build with -fvisibility=hidden in B.so at link time.

Answer1:

<blockquote>

We have using nm to check those symbols

</blockquote>

You shouldn't: on ELF platforms, nm is <em>inadequate</em> for the job. Use readelf -Ws instead.

<blockquote>

it exist but list as “t” instead of “T”,which means it is local symbols instead of external. Seams the A.a are build with -fvisibility=hidden after som investigation.

</blockquote>

Your conclusion does not follow: there are <em>many</em> reasons a symbol may show up as a t. Being compiled with -fvisibility=hidden is only one of many possibilities.

<blockquote>

Is there any way to export those symbols as global even it has been build with -fvisibility=hidden

</blockquote>

The symbol table is just a linear table of Elf{32,64}_Sym[]s. You can find the start of this table in the object file with readelf -WS foo.o | grep '\.symtab', find the number of offending symbol from readelf -Ws, and find the offset of the symbol in the foo.o by combining the two:

sym-offset = .symtab offset + (sym-number * sizeof(Sym))

Once you have the offset, you can override its .st_info with STV_DEFAULT (if your theory is correct and you located the symbol correctly, you should find STV_HIDDEN there currently).

Once you've patched your foo.o, the symbol will no longer be hidden, and when you link foo.o into B.so, it will be global / exported.

Recommend

  • ICU library in Android NDK
  • Numpy - Finding matches across multiple co-ordinates
  • Ripple Emulator doesn't fire events
  • iOS project: Static/Dynamic code analysis and call graphs
  • import XML to HTML
  • Invalid javascript/JSONP response from Soundcloud API
  • Creating a Countdown Watch with a slider in Xcode
  • getting cpu usage of one process using c++ (win32)
  • C# Pass a Class as a parameter
  • Monotouch - Issue with QLPreviewController
  • Dump all Raima db_VISTA Version 3.20 data to text
  • url scheme for ssh: Calling command on remote host
  • Netezza Incremental load from Sql server using SSIS
  • LNK1104: cannot open file 'kernel32.lib'
  • Graceful pod termination
  • insert radio value multiple data codeigniter in database to one row?
  • Universal Image Loader reuse images
  • Cannot save model when using ember render helper
  • VBA Excel, loop through variables
  • Clear fused location provider's location for testing
  • Trying to get the char code of ENTER key
  • Using Sax parsing to edit and write XML in VB6
  • ADO and msqli connections very slow
  • Debug.DrawLine not showing in the GameView
  • PHP buffered output depending on server setting?
  • Yii2: Config params vs. const/define
  • How to delay loading a property with linq to sql external mapping?
  • Does CUDA 5 support STL or THRUST inside the device code?
  • When should I choose bucket sort over other sorting algorithms?
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • How do you troubleshoot character encoding problems?
  • Understanding cpu registers
  • -fvisibility=hidden not passed by compiler for Debug builds
  • Turn off referential integrity in Derby? is it possible?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Add sale price programmatically to product variations
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Unable to use reactive element in my shiny app
  • How do I use LINQ to get all the Items that have a particular SubItem?