From ff17bc61e2247af26441782f9085580ec030ba80 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Tue, 27 Mar 2012 14:10:15 +0000 Subject: [PATCH] Prevent rtld_verify_object_versions() from being called several times for the same object. This can happen when object is a dependency of the dlopen()ed dso. When called several times, we waste time due to unneeded processing, and memory, because obj->vertab is allocated anew on each iteration. Reviewed by: kan MFC after: 2 weeks --- libexec/rtld-elf/rtld.c | 4 ++++ libexec/rtld-elf/rtld.h | 1 + 2 files changed, 5 insertions(+) diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index e081e098461..c4607b2248a 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -4158,6 +4158,10 @@ rtld_verify_object_versions(Obj_Entry *obj) const Obj_Entry *depobj; int maxvernum, vernum; + if (obj->ver_checked) + return (0); + obj->ver_checked = true; + maxvernum = 0; /* * Walk over defined and required version records and figure out diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h index 08d7e991142..6017957e80a 100644 --- a/libexec/rtld-elf/rtld.h +++ b/libexec/rtld-elf/rtld.h @@ -230,6 +230,7 @@ typedef struct Struct_Obj_Entry { bool mainprog : 1; /* True if this is the main program */ bool rtld : 1; /* True if this is the dynamic linker */ bool relocated : 1; /* True if processed by relocate_objects() */ + bool ver_checked : 1; /* True if processed by rtld_verify_object_versions */ bool textrel : 1; /* True if there are relocations to text seg */ bool symbolic : 1; /* True if generated with "-Bsymbolic" */ bool bind_now : 1; /* True if all relocations should be made first */