[libc-commits] [libc] [libc] support PIE relocations (PR #78993)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Mon Jan 22 11:39:32 PST 2024


================
@@ -94,18 +99,26 @@ static ThreadAttributes main_thread_attrib;
     }
   }
 
+  ptrdiff_t base = 0;
   app.tls.size = 0;
+  Elf64_Phdr *tls_phdr = nullptr;
+
   for (uintptr_t i = 0; i < program_hdr_count; ++i) {
-    Elf64_Phdr *phdr = program_hdr_table + i;
-    if (phdr->p_type != PT_TLS)
-      continue;
-    // TODO: p_vaddr value has to be adjusted for static-pie executables.
-    app.tls.address = phdr->p_vaddr;
-    app.tls.size = phdr->p_memsz;
-    app.tls.init_size = phdr->p_filesz;
-    app.tls.align = phdr->p_align;
+    Elf64_Phdr &phdr = program_hdr_table[i];
+    if (phdr.p_type == PT_PHDR)
+      base = reinterpret_cast<ptrdiff_t>(program_hdr_table) - phdr.p_vaddr;
+    if (phdr.p_type == PT_DYNAMIC && _DYNAMIC)
----------------
SchrodingerZhu wrote:

_DYNAMIC is declared as `[[gnu::weak]]`. ELF specifies that undefined weak symbols should give NULL

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


More information about the libc-commits mailing list