3

In Automatically executed functions when loading shared libraries we read:

To have a function executed whenever the shared library is loaded or unloaded, you can mark a constructor and destructor function using GCC-specific attribute syntax:

__attribute__((constructor)) void init(void) { ... }
__attribute__((destructor))  void fini(void) { ... }

The article How exactly does __attribute__((constructor)) work? also mentions .init/.fini.

Now, I have a .so module (a shared object library, no source) and I want to know which function(s) are executed when the library is loaded/unloaded. I tried nm, but it looks like these attributes are not shown in the output.

So, How do I know which function(s) are automatically executed when the shared library is loaded or unloaded?

Community
  • 1
  • 1
18446744073709551615
  • 16,368
  • 4
  • 94
  • 127

1 Answers1

0

I still have no general-case answer, but this is what I found:

The library has sections .init_array and .fini_array. (There's no .init or .ctors, but YMMV.)

; Segment type: Pure data
            AREA .init_array, DATA
            DCD sub_F5C+1
            DCB    0
            DCB    0
            DCB    0
            DCB    0
.init_array   ends

So it looks like sub_F5C() is the only function invoked while initializing. The 4 zero bytes at the end are really one zero dword; +1 is an ARM feature to select the instruction set.

More about .init_array and other special sections

18446744073709551615
  • 16,368
  • 4
  • 94
  • 127