[llvm] WIP: [Bolt] Add support for DT_INIT_ARRAY (PR #153196)

Ádám Kallai via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 17 01:29:54 PDT 2025


kaadam wrote:

Hi, thanks for your comment and your findings.

Glibc is a tricky Elf shared object. It can acts as a binary or as a shared object.
So _libc.so_ has an entry point which points to '__libc_main' make it directly runnable. It just prints a banner.
File from csu/version.c

```
extern void __libc_main (void) __attribute__ ((noreturn));

void __libc_main (void)
{
  __libc_print_version ();
  _exit (0);
}
```
The [draft](https://github.com/llvm/llvm-project/pull/153196) solution what I uploaded, distinguishes between whether the ELF file is a binary or a shared object based on presence of the Interp header.
In this case _libc_ is an so, and it has _Interp_ header, so Bolt just deals with Elf e_entry point which is the __libc_main, and hooking its start runtime function to that. However this never runs if _libc_ acts as **SO**.

So most probably **DT_INITARRAY** should be used here (if no **DT_INIT**), instead of e_entry.
I need to look at this example.

https://github.com/llvm/llvm-project/pull/153196


More information about the llvm-commits mailing list