elf: Hide DT_INIT and DT_FINI functions
Hides DT_INIT and DT_FINI functions from the dynamic symbol table to resolve linker issues.
This patch proposes to hide the special functions used by the linker to define DT_INIT and DT_FINI in executables and shared libraries. The goal is to prevent these functions from appearing in the dynamic symbol table, addressing issues related to their handling. The patch includes modifications to bfd/elflink.c and adds new test cases in ld/testsuite/ld-elf.
- proposer
Submits a patch to hide DT_INIT and DT_FINI functions from the dynamic symbol table.
“Hide special functions used by linker to define DT_INIT and DT_FINI in executable and shared library so that they won't be in dynamic symbol table.”
- reviewer
Acknowledges the patch and its description.
- reviewer
Acknowledges the patch and its description.
- reviewer
Questions the necessity of the patch, noting that hidden symbols should not be in the dynamic symbol table and suggesting it might mask an underlying issue.
“I still don't quite understand: In reply to my comment on the original, combined patch you said the symbols are hidden. Hidden symbols shouldn't be making it into the dynamic symbol table anyway. IOW - are you papering over an issue elsewhere?”
- proposer
Clarifies that the symbols are hidden within glibc, implying a context-specific hiding mechanism.
“I said they are hidden in glibc.”
Technical Tradeoffs
- Hides symbols that might otherwise be useful for introspection or debugging, but are not intended for external dynamic linking.
- Addresses a potential for symbol conflicts or misinterpretation by ensuring only necessary symbols are exported.
In Details
This patch addresses linker behavior for ELF binaries, specifically concerning the DT_INIT and DT_FINI dynamic table entries. These entries point to initialization and termination functions. The change aims to prevent symbols associated with these functions from being exported to the dynamic symbol table, potentially simplifying symbol resolution and preventing conflicts, particularly when these symbols are handled differently across libraries (e.g., glibc).
- DT_INIT
- A dynamic table entry (DT_INIT) in an ELF executable or shared library that specifies the address of the initialization function to be called when the library is loaded.
- DT_FINI
- A dynamic table entry (DT_FINI) in an ELF executable or shared library that specifies the address of the termination function to be called when the library is unloaded.
- dynamic symbol table
- A section in an ELF file (usually .dynsym) that contains symbols necessary for dynamic linking, such as imported and exported functions and variables.
- linker
- A program that combines object files and libraries into an executable program, resolving external references between them.