rtld.c (16fc3635f7aec3852abfc6dd77f89baef91f22fa) rtld.c (c905e45dc0e7ad2da0748371ba8921ca48134a01)
1/*-
2 * Copyright 1996, 1997, 1998, 1999, 2000 John D. Polstra.
3 * Copyright 2003 Alexander Kabaev <kan@FreeBSD.ORG>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 40 unchanged lines hidden (view full) ---

49#include <stdlib.h>
50#include <string.h>
51#include <unistd.h>
52
53#include "debug.h"
54#include "rtld.h"
55#include "libmap.h"
56
1/*-
2 * Copyright 1996, 1997, 1998, 1999, 2000 John D. Polstra.
3 * Copyright 2003 Alexander Kabaev <kan@FreeBSD.ORG>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 40 unchanged lines hidden (view full) ---

49#include <stdlib.h>
50#include <string.h>
51#include <unistd.h>
52
53#include "debug.h"
54#include "rtld.h"
55#include "libmap.h"
56
57#ifndef COMPAT_32BIT
57#define PATH_RTLD "/libexec/ld-elf.so.1"
58#define PATH_RTLD "/libexec/ld-elf.so.1"
59#else
60#define PATH_RTLD "/libexec/ld-elf32.so.1"
61#endif
58
59/* Types. */
60typedef void (*func_ptr_type)();
61typedef void * (*path_enum_proc) (const char *path, size_t len, void *arg);
62
63/*
64 * This structure provides a reentrant way to keep a list of objects and
65 * check which ones have already been processed in some way.

--- 190 unchanged lines hidden (view full) ---

256 init_rtld((caddr_t) aux_info[AT_BASE]->a_un.a_ptr);
257
258 __progname = obj_rtld.path;
259 argv0 = argv[0] != NULL ? argv[0] : "(null)";
260 environ = env;
261
262 trust = !issetugid();
263
62
63/* Types. */
64typedef void (*func_ptr_type)();
65typedef void * (*path_enum_proc) (const char *path, size_t len, void *arg);
66
67/*
68 * This structure provides a reentrant way to keep a list of objects and
69 * check which ones have already been processed in some way.

--- 190 unchanged lines hidden (view full) ---

260 init_rtld((caddr_t) aux_info[AT_BASE]->a_un.a_ptr);
261
262 __progname = obj_rtld.path;
263 argv0 = argv[0] != NULL ? argv[0] : "(null)";
264 environ = env;
265
266 trust = !issetugid();
267
264 ld_bind_now = getenv("LD_BIND_NOW");
268 ld_bind_now = getenv(LD_ "BIND_NOW");
265 if (trust) {
269 if (trust) {
266 ld_debug = getenv("LD_DEBUG");
267 libmap_disable = getenv("LD_LIBMAP_DISABLE") != NULL;
268 ld_library_path = getenv("LD_LIBRARY_PATH");
269 ld_preload = getenv("LD_PRELOAD");
270 ld_debug = getenv(LD_ "DEBUG");
271 libmap_disable = getenv(LD_ "LIBMAP_DISABLE") != NULL;
272 ld_library_path = getenv(LD_ "LIBRARY_PATH");
273 ld_preload = getenv(LD_ "PRELOAD");
270 }
274 }
271 ld_tracing = getenv("LD_TRACE_LOADED_OBJECTS");
275 ld_tracing = getenv(LD_ "TRACE_LOADED_OBJECTS");
272
273 if (ld_debug != NULL && *ld_debug != '\0')
274 debug = 1;
275 dbg("%s is initialized, base address = %p", __progname,
276 (caddr_t) aux_info[AT_BASE]->a_un.a_ptr);
277 dbg("RTLD dynamic = %p", obj_rtld.dynamic);
278 dbg("RTLD pltgot = %p", obj_rtld.pltgot);
279

--- 75 unchanged lines hidden (view full) ---

355 obj->refcount++;
356 }
357
358 if (ld_tracing) { /* We're done */
359 trace_loaded_objects(obj_main);
360 exit(0);
361 }
362
276
277 if (ld_debug != NULL && *ld_debug != '\0')
278 debug = 1;
279 dbg("%s is initialized, base address = %p", __progname,
280 (caddr_t) aux_info[AT_BASE]->a_un.a_ptr);
281 dbg("RTLD dynamic = %p", obj_rtld.dynamic);
282 dbg("RTLD pltgot = %p", obj_rtld.pltgot);
283

--- 75 unchanged lines hidden (view full) ---

359 obj->refcount++;
360 }
361
362 if (ld_tracing) { /* We're done */
363 trace_loaded_objects(obj_main);
364 exit(0);
365 }
366
363 if (getenv("LD_DUMP_REL_PRE") != NULL) {
367 if (getenv(LD_ "DUMP_REL_PRE") != NULL) {
364 dump_relocations(obj_main);
365 exit (0);
366 }
367
368 if (relocate_objects(obj_main,
369 ld_bind_now != NULL && *ld_bind_now != '\0', &obj_rtld) == -1)
370 die();
371
372 dbg("doing copy relocations");
373 if (do_copy_relocations(obj_main) == -1)
374 die();
375
368 dump_relocations(obj_main);
369 exit (0);
370 }
371
372 if (relocate_objects(obj_main,
373 ld_bind_now != NULL && *ld_bind_now != '\0', &obj_rtld) == -1)
374 die();
375
376 dbg("doing copy relocations");
377 if (do_copy_relocations(obj_main) == -1)
378 die();
379
376 if (getenv("LD_DUMP_REL_POST") != NULL) {
380 if (getenv(LD_ "DUMP_REL_POST") != NULL) {
377 dump_relocations(obj_main);
378 exit (0);
379 }
380
381 dbg("initializing key program variables");
382 set_program_var("__progname", argv[0] != NULL ? basename(argv[0]) : "");
383 set_program_var("environ", env);
384

--- 1070 unchanged lines hidden (view full) ---

1455 /* No need to remove the items from the list, since we are exiting. */
1456 if (!libmap_disable)
1457 lm_fini();
1458}
1459
1460static void *
1461path_enumerate(const char *path, path_enum_proc callback, void *arg)
1462{
381 dump_relocations(obj_main);
382 exit (0);
383 }
384
385 dbg("initializing key program variables");
386 set_program_var("__progname", argv[0] != NULL ? basename(argv[0]) : "");
387 set_program_var("environ", env);
388

--- 1070 unchanged lines hidden (view full) ---

1459 /* No need to remove the items from the list, since we are exiting. */
1460 if (!libmap_disable)
1461 lm_fini();
1462}
1463
1464static void *
1465path_enumerate(const char *path, path_enum_proc callback, void *arg)
1466{
1467#ifdef COMPAT_32BIT
1468 const char *trans;
1469#endif
1463 if (path == NULL)
1464 return (NULL);
1465
1466 path += strspn(path, ":;");
1467 while (*path != '\0') {
1468 size_t len;
1469 char *res;
1470
1471 len = strcspn(path, ":;");
1470 if (path == NULL)
1471 return (NULL);
1472
1473 path += strspn(path, ":;");
1474 while (*path != '\0') {
1475 size_t len;
1476 char *res;
1477
1478 len = strcspn(path, ":;");
1479#ifdef COMPAT_32BIT
1480 trans = lm_findn(NULL, path, len);
1481 if (trans)
1482 res = callback(trans, strlen(trans), arg);
1483 else
1484#endif
1472 res = callback(path, len, arg);
1473
1474 if (res != NULL)
1475 return (res);
1476
1477 path += len;
1478 path += strspn(path, ":;");
1479 }

--- 774 unchanged lines hidden (view full) ---

2254}
2255
2256static void
2257trace_loaded_objects(Obj_Entry *obj)
2258{
2259 char *fmt1, *fmt2, *fmt, *main_local, *list_containers;
2260 int c;
2261
1485 res = callback(path, len, arg);
1486
1487 if (res != NULL)
1488 return (res);
1489
1490 path += len;
1491 path += strspn(path, ":;");
1492 }

--- 774 unchanged lines hidden (view full) ---

2267}
2268
2269static void
2270trace_loaded_objects(Obj_Entry *obj)
2271{
2272 char *fmt1, *fmt2, *fmt, *main_local, *list_containers;
2273 int c;
2274
2262 if ((main_local = getenv("LD_TRACE_LOADED_OBJECTS_PROGNAME")) == NULL)
2275 if ((main_local = getenv(LD_ "TRACE_LOADED_OBJECTS_PROGNAME")) == NULL)
2263 main_local = "";
2264
2276 main_local = "";
2277
2265 if ((fmt1 = getenv("LD_TRACE_LOADED_OBJECTS_FMT1")) == NULL)
2278 if ((fmt1 = getenv(LD_ "TRACE_LOADED_OBJECTS_FMT1")) == NULL)
2266 fmt1 = "\t%o => %p (%x)\n";
2267
2279 fmt1 = "\t%o => %p (%x)\n";
2280
2268 if ((fmt2 = getenv("LD_TRACE_LOADED_OBJECTS_FMT2")) == NULL)
2281 if ((fmt2 = getenv(LD_ "TRACE_LOADED_OBJECTS_FMT2")) == NULL)
2269 fmt2 = "\t%o (%x)\n";
2270
2282 fmt2 = "\t%o (%x)\n";
2283
2271 list_containers = getenv("LD_TRACE_LOADED_OBJECTS_ALL");
2284 list_containers = getenv(LD_ "TRACE_LOADED_OBJECTS_ALL");
2272
2273 for (; obj; obj = obj->next) {
2274 Needed_Entry *needed;
2275 char *name, *path;
2276 bool is_lib;
2277
2278 if (list_containers && obj->needed != NULL)
2279 printf("%s:\n", obj->path);

--- 143 unchanged lines hidden ---
2285
2286 for (; obj; obj = obj->next) {
2287 Needed_Entry *needed;
2288 char *name, *path;
2289 bool is_lib;
2290
2291 if (list_containers && obj->needed != NULL)
2292 printf("%s:\n", obj->path);

--- 143 unchanged lines hidden ---