17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*20c1c355SRod Evans * Common Development and Distribution License (the "License"). 6*20c1c355SRod Evans * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21*20c1c355SRod Evans 227c478bd9Sstevel@tonic-gate /* 23*20c1c355SRod Evans * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate #include <stdio.h> 267c478bd9Sstevel@tonic-gate #include <stdlib.h> 277c478bd9Sstevel@tonic-gate #include <link.h> 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include "env.h" 307c478bd9Sstevel@tonic-gate 31*20c1c355SRod Evans static Elist *bindto_list = NULL; 32*20c1c355SRod Evans static Elist *bindfrom_list = NULL; 337c478bd9Sstevel@tonic-gate static FILE *output = stdout; 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate uint_t 377c478bd9Sstevel@tonic-gate la_version(uint_t version) 387c478bd9Sstevel@tonic-gate { 397c478bd9Sstevel@tonic-gate if (version < LAV_CURRENT) { 407c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 41*20c1c355SRod Evans "symbindrep.so: unexpected version: %d\n", version); 427c478bd9Sstevel@tonic-gate return (0); 437c478bd9Sstevel@tonic-gate } 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate build_env_list(&bindto_list, (const char *)"SYMBINDREP_BINDTO"); 467c478bd9Sstevel@tonic-gate build_env_list(&bindfrom_list, (const char *)"SYMBINDREP_BINDFROM"); 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate #ifdef _LP64 49*20c1c355SRod Evans (void) fprintf(output, 50*20c1c355SRod Evans " Symbol Bindings\n\n" 51*20c1c355SRod Evans "Referencing Defining\n" 52*20c1c355SRod Evans "Object Object Symbol\n" 53*20c1c355SRod Evans "---------------------------------------------------------------" 54*20c1c355SRod Evans "-------------------\n"); 557c478bd9Sstevel@tonic-gate #else 56*20c1c355SRod Evans (void) fprintf(output, 57*20c1c355SRod Evans " Symbol Bindings\n\n" 58*20c1c355SRod Evans "Referencing Defining\n" 59*20c1c355SRod Evans "Object Object Symbol\n" 60*20c1c355SRod Evans "---------------------------------------------------------------" 61*20c1c355SRod Evans "---\n"); 627c478bd9Sstevel@tonic-gate #endif 637c478bd9Sstevel@tonic-gate return (LAV_CURRENT); 647c478bd9Sstevel@tonic-gate } 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate /* ARGSUSED1 */ 677c478bd9Sstevel@tonic-gate uint_t 687c478bd9Sstevel@tonic-gate la_objopen(Link_map *lmp, Lmid_t lmid, uintptr_t *cookie) 697c478bd9Sstevel@tonic-gate { 707c478bd9Sstevel@tonic-gate uint_t flags; 717c478bd9Sstevel@tonic-gate 72*20c1c355SRod Evans if ((bindto_list == NULL) || 737c478bd9Sstevel@tonic-gate (check_list(bindto_list, lmp->l_name))) 747c478bd9Sstevel@tonic-gate flags = LA_FLG_BINDTO; 757c478bd9Sstevel@tonic-gate else 767c478bd9Sstevel@tonic-gate flags = 0; 777c478bd9Sstevel@tonic-gate 78*20c1c355SRod Evans if ((bindfrom_list == NULL) || 797c478bd9Sstevel@tonic-gate (check_list(bindfrom_list, lmp->l_name))) 807c478bd9Sstevel@tonic-gate flags |= LA_FLG_BINDFROM; 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate *cookie = (uintptr_t)lmp->l_name; 837c478bd9Sstevel@tonic-gate return (flags); 847c478bd9Sstevel@tonic-gate } 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate /* ARGSUSED1 */ 887c478bd9Sstevel@tonic-gate #if defined(_LP64) 897c478bd9Sstevel@tonic-gate uintptr_t 907c478bd9Sstevel@tonic-gate la_symbind64(Elf64_Sym *symp, uint_t symndx, uintptr_t *refcook, 917c478bd9Sstevel@tonic-gate uintptr_t *defcook, uint_t *sb_flags, const char *sym_name) 927c478bd9Sstevel@tonic-gate #else 937c478bd9Sstevel@tonic-gate uintptr_t 947c478bd9Sstevel@tonic-gate la_symbind32(Elf32_Sym *symp, uint_t symndx, uintptr_t *refcook, 957c478bd9Sstevel@tonic-gate uintptr_t *defcook, uint_t *sb_flags) 967c478bd9Sstevel@tonic-gate #endif 977c478bd9Sstevel@tonic-gate { 987c478bd9Sstevel@tonic-gate #if !defined(_LP64) 997c478bd9Sstevel@tonic-gate const char *sym_name = (const char *)symp->st_name; 1007c478bd9Sstevel@tonic-gate #endif 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate (void) fprintf(output, "%-28s %-28s %s\n", (char *)(*refcook), 1037c478bd9Sstevel@tonic-gate (char *)(*defcook), sym_name); 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate return (symp->st_value); 1067c478bd9Sstevel@tonic-gate } 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate /* 1097c478bd9Sstevel@tonic-gate * Since we only want to report on the symbol bindings for this 1107c478bd9Sstevel@tonic-gate * process and we *do not* want the actual program to run we exit 1117c478bd9Sstevel@tonic-gate * at this point. 1127c478bd9Sstevel@tonic-gate */ 1137c478bd9Sstevel@tonic-gate /* ARGSUSED0 */ 1147c478bd9Sstevel@tonic-gate void 1157c478bd9Sstevel@tonic-gate la_preinit(uintptr_t *cookie) 1167c478bd9Sstevel@tonic-gate { 1177c478bd9Sstevel@tonic-gate (void) fflush(output); 1187c478bd9Sstevel@tonic-gate exit(0); 1197c478bd9Sstevel@tonic-gate } 120