Page MenuHomeFreeBSD

D26352.id93700.diff
No OneTemporary

D26352.id93700.diff

Index: libexec/rtld-elf/rtld.1
===================================================================
--- libexec/rtld-elf/rtld.1
+++ libexec/rtld-elf/rtld.1
@@ -143,6 +143,13 @@
.Nm
will print a table containing all relocations before symbol
binding and relocation.
+.It Ev LD_DYNAMIC_WEAK
+If set to 0, use the standard symbol lookup behavior: resolve to the first
+definition, regardless of whether it is weak.
+By default the non-standard traditional symbol lookup behavior is used: when a
+weak definition is found, remember the definition and keep searching in the
+remaining shared objects for a non-weak definition. If found, the non-weak
+definition is returned, otherwise the remembered weak definition is returned.
.It Ev LD_LIBMAP
A library replacement list in the same format as
.Xr libmap.conf 5 .
Index: libexec/rtld-elf/rtld.c
===================================================================
--- libexec/rtld-elf/rtld.c
+++ libexec/rtld-elf/rtld.c
@@ -209,6 +209,7 @@
bool ld_bind_not; /* Disable PLT update */
static char *ld_bind_now; /* Environment variable for immediate binding */
static char *ld_debug; /* Environment variable for debugging */
+static bool ld_dynamic_weak; /* True if non-weak definition overrides weak definition */
static char *ld_library_path; /* Environment variable for search path */
static char *ld_library_dirs; /* Environment variable for library descriptors */
static char *ld_preload; /* Environment variable for libraries to
@@ -385,7 +386,7 @@
RtldLockState lockstate;
struct stat st;
Elf_Addr *argcp;
- char **argv, **env, **envp, *kexecpath, *library_path_rpath;
+ char **argv, **env, **envp, *kexecpath, *dynamic_weak, *library_path_rpath;
const char *argv0, *binpath;
caddr_t imgentry;
char buf[MAXPATHLEN];
@@ -591,6 +592,9 @@
ld_debug = getenv(_LD("DEBUG"));
if (ld_bind_now == NULL)
ld_bind_not = getenv(_LD("BIND_NOT")) != NULL;
+ dynamic_weak = getenv(_LD("DYNAMIC_WEAK"));
+ if (dynamic_weak != NULL)
+ ld_dynamic_weak = dynamic_weak[0] == '0' || dynamic_weak[0] == 'n';
libmap_disable = getenv(_LD("LIBMAP_DISABLE")) != NULL;
libmap_override = getenv(_LD("LIBMAP"));
ld_library_path = getenv(_LD("LIBRARY_PATH"));
@@ -3673,11 +3677,11 @@
continue;
res = symlook_obj(&req, obj);
if (res == 0) {
- if (def == NULL ||
- ELF_ST_BIND(req.sym_out->st_info) != STB_WEAK) {
+ if (def == NULL || (ld_dynamic_weak &&
+ ELF_ST_BIND(req.sym_out->st_info) != STB_WEAK)) {
def = req.sym_out;
defobj = req.defobj_out;
- if (ELF_ST_BIND(def->st_info) != STB_WEAK)
+ if (!ld_dynamic_weak || ELF_ST_BIND(def->st_info) != STB_WEAK)
break;
}
}
@@ -4288,10 +4292,10 @@
symlook_init_from_req(&req1, req);
/* Search all objects loaded at program start up. */
- if (req->defobj_out == NULL ||
- ELF_ST_BIND(req->sym_out->st_info) == STB_WEAK) {
+ if (req->defobj_out == NULL || (ld_dynamic_weak &&
+ ELF_ST_BIND(req->sym_out->st_info) == STB_WEAK)) {
res = symlook_list(&req1, &list_main, donelist);
- if (res == 0 && (req->defobj_out == NULL ||
+ if (res == 0 && (!ld_dynamic_weak || req->defobj_out == NULL ||
ELF_ST_BIND(req1.sym_out->st_info) != STB_WEAK)) {
req->sym_out = req1.sym_out;
req->defobj_out = req1.defobj_out;
@@ -4301,8 +4305,8 @@
/* Search all DAGs whose roots are RTLD_GLOBAL objects. */
STAILQ_FOREACH(elm, &list_global, link) {
- if (req->defobj_out != NULL &&
- ELF_ST_BIND(req->sym_out->st_info) != STB_WEAK)
+ if (req->defobj_out != NULL && (!ld_dynamic_weak ||
+ ELF_ST_BIND(req->sym_out->st_info) != STB_WEAK))
break;
res = symlook_list(&req1, &elm->obj->dagmembers, donelist);
if (res == 0 && (req->defobj_out == NULL ||
@@ -4351,8 +4355,8 @@
/* Search all dlopened DAGs containing the referencing object. */
STAILQ_FOREACH(elm, &refobj->dldags, link) {
- if (req->sym_out != NULL &&
- ELF_ST_BIND(req->sym_out->st_info) != STB_WEAK)
+ if (req->sym_out != NULL && (!ld_dynamic_weak ||
+ ELF_ST_BIND(req->sym_out->st_info) != STB_WEAK))
break;
res = symlook_list(&req1, &elm->obj->dagmembers, &donelist);
if (res == 0 && (req->sym_out == NULL ||
@@ -4397,10 +4401,11 @@
continue;
symlook_init_from_req(&req1, req);
if ((res = symlook_obj(&req1, elm->obj)) == 0) {
- if (def == NULL || ELF_ST_BIND(req1.sym_out->st_info) != STB_WEAK) {
+ if (def == NULL || (ld_dynamic_weak &&
+ ELF_ST_BIND(req1.sym_out->st_info) != STB_WEAK)) {
def = req1.sym_out;
defobj = req1.defobj_out;
- if (ELF_ST_BIND(def->st_info) != STB_WEAK)
+ if (!ld_dynamic_weak || ELF_ST_BIND(def->st_info) != STB_WEAK)
break;
}
}
@@ -4435,10 +4440,11 @@
if (n->obj == NULL ||
(res = symlook_list(&req1, &n->obj->dagmembers, dlp)) != 0)
continue;
- if (def == NULL || ELF_ST_BIND(req1.sym_out->st_info) != STB_WEAK) {
+ if (def == NULL || (ld_dynamic_weak &&
+ ELF_ST_BIND(req1.sym_out->st_info) != STB_WEAK)) {
def = req1.sym_out;
defobj = req1.defobj_out;
- if (ELF_ST_BIND(def->st_info) != STB_WEAK)
+ if (!ld_dynamic_weak || ELF_ST_BIND(def->st_info) != STB_WEAK)
break;
}
}

File Metadata

Mime Type
text/plain
Expires
Tue, Feb 4, 11:06 AM (5 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16452467
Default Alt Text
D26352.id93700.diff (5 KB)

Event Timeline