ehdr->e_phnum, ehdr->e_phentsize));
decode_dyn(lib);
- /* Assume base address of 0 for the main program. This is not
- * valid for PIE code; we will have to search the PHDR to get
- * the correct load address in the PIE case (not yet supported). */
+ /* Find load address of the main program, via AT_PHDR vs PT_PHDR. */
app->base = 0;
+ phdr = (void *)aux[AT_PHDR];
+ for (i=aux[AT_PHNUM]; i; i--, phdr=(void *)((char *)phdr + aux[AT_PHENT])) {
+ if (phdr->p_type == PT_PHDR)
+ app->base = (void *)(aux[AT_PHDR] - phdr->p_vaddr);
+ }
app->name = argv[0];
app->global = 1;
app->dynv = (void *)(app->base + find_dyn(
ehdr->e_phentsize, ehdr->e_phnum);
/* Load preload/needed libraries, add their symbols to the global
- * namespace, and perform all remaining relocations. */
+ * namespace, and perform all remaining relocations. The main
+ * program must be relocated LAST since it may contain copy
+ * relocations which depend on libraries' relocations. */
if (env_preload) load_preload(env_preload);
load_deps(app);
make_global(app);
+ reloc_all(app->next);
reloc_all(app);
/* Switch to runtime mode: any further failures in the dynamic
pthread_rwlock_unlock(&lock);
return res;
}
+#else
+void *dlopen(const char *file, int mode)
+{
+ return 0;
+}
+void *__dlsym(void *p, const char *s, void *ra)
+{
+ return 0;
+}
+#endif
char *dlerror()
{
{
return 0;
}
-#endif