How to detect at runtime whether symbols are stripped?

前端 未结 5 1033
忘掉有多难
忘掉有多难 2021-02-15 01:36

In my C++ program, how can I detect programmatically at runtime whether symbols have been stripped via the \'strip\' gnu development tool on Linux?

I\'d like a function

5条回答
  •  渐次进展
    2021-02-15 02:21

    dlsym looks at dynamic symbols, which aren't touched by strip. The static symbol table is contained in sections that are not loaded at runtime and thus do not appear in the segment table.

    A pretty good heuristic would be to watch for the existence of a section table in the ELF header, which is usually mapped to your process memory, although the dynamic linker interfaces make it deliberately hard to find out where. On a typical system that has the dl_iterate_phdrs function (which is an extension to the standard), you might be able to walk the PHDRS and check at the vaddr for each whether there is an ELF magic number there, but that is in no way, shape or form portable.

提交回复
热议问题