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 55aefb655Srie * Common Development and Distribution License (the "License"). 65aefb655Srie * 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 */ 215aefb655Srie 227c478bd9Sstevel@tonic-gate /* 23*f441771bSRod Evans * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #include <stdio.h> 277c478bd9Sstevel@tonic-gate #include <strings.h> 287c478bd9Sstevel@tonic-gate #include <sys/elf.h> 297c478bd9Sstevel@tonic-gate #include <sys/elf_SPARC.h> 307c478bd9Sstevel@tonic-gate #include <alloca.h> 317c478bd9Sstevel@tonic-gate #include "_rtld.h" 327c478bd9Sstevel@tonic-gate #include "_elf.h" 337c478bd9Sstevel@tonic-gate #include "msg.h" 347c478bd9Sstevel@tonic-gate #include "conv.h" 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate /* 377c478bd9Sstevel@tonic-gate * 387c478bd9Sstevel@tonic-gate * Matrix of legal combinations of usage of a given register: 397c478bd9Sstevel@tonic-gate * 407c478bd9Sstevel@tonic-gate * Obj1\Obj2 Scratch Named 417c478bd9Sstevel@tonic-gate * Scratch OK NO 427c478bd9Sstevel@tonic-gate * Named NO * 437c478bd9Sstevel@tonic-gate * 447c478bd9Sstevel@tonic-gate * * OK if the symbols are identical, NO if they are not. Two symbols 457c478bd9Sstevel@tonic-gate * are identical if and only if one of the following is true: 467c478bd9Sstevel@tonic-gate * A. They are both global and have the same name. 477c478bd9Sstevel@tonic-gate * B. They are both local, have the same name, and are defined in 487c478bd9Sstevel@tonic-gate * the same object. (Note that a local symbol in one object is 497c478bd9Sstevel@tonic-gate * never identical to a local symbol in another object, even if the 507c478bd9Sstevel@tonic-gate * name is the same.) 517c478bd9Sstevel@tonic-gate * 527c478bd9Sstevel@tonic-gate * Matrix of legal combinations of st_shndx for the same register symbol: 537c478bd9Sstevel@tonic-gate * 547c478bd9Sstevel@tonic-gate * Obj1\Obj2 UNDEF ABS 557c478bd9Sstevel@tonic-gate * UNDEF OK OK 567c478bd9Sstevel@tonic-gate * ABS OK NO 577c478bd9Sstevel@tonic-gate */ 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate /* 607c478bd9Sstevel@tonic-gate * Test the compatiblity of two register symbols, 0 pass, >0 fail 617c478bd9Sstevel@tonic-gate */ 627c478bd9Sstevel@tonic-gate static uintptr_t 637c478bd9Sstevel@tonic-gate check_regsyms(Sym *sym1, const char *name1, Sym *sym2, const char *name2) 647c478bd9Sstevel@tonic-gate { 657c478bd9Sstevel@tonic-gate if ((sym1->st_name == 0) && (sym2->st_name == 0)) 667c478bd9Sstevel@tonic-gate return (0); /* scratches are always compatible */ 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate if ((ELF_ST_BIND(sym1->st_info) == STB_LOCAL) || 697c478bd9Sstevel@tonic-gate (ELF_ST_BIND(sym2->st_info) == STB_LOCAL)) { 707c478bd9Sstevel@tonic-gate if (sym1->st_value == sym2->st_value) 717c478bd9Sstevel@tonic-gate return (1); /* local symbol incompat */ 727c478bd9Sstevel@tonic-gate return (0); /* no other prob from locals */ 737c478bd9Sstevel@tonic-gate } 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate if (sym1->st_value == sym2->st_value) { 767c478bd9Sstevel@tonic-gate /* NOTE this just avoids strcmp */ 777c478bd9Sstevel@tonic-gate if ((sym1->st_name == 0) || (sym2->st_name == 0)) 787c478bd9Sstevel@tonic-gate return (2); /* can't match scratch to named */ 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate if (strcmp(name1, name2) != 0) 817c478bd9Sstevel@tonic-gate return (4); /* diff name, same register value */ 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate if ((sym1->st_shndx == SHN_ABS) && (sym2->st_shndx == SHN_ABS)) 847c478bd9Sstevel@tonic-gate return (3); /* multiply defined */ 857c478bd9Sstevel@tonic-gate } else if (strcmp(name1, name2) == 0) 867c478bd9Sstevel@tonic-gate return (5); /* same name, diff register value */ 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate return (0); 897c478bd9Sstevel@tonic-gate } 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate int 927c478bd9Sstevel@tonic-gate elf_regsyms(Rt_map *lmp) 937c478bd9Sstevel@tonic-gate { 947c478bd9Sstevel@tonic-gate Dyn *dyn; 95*f441771bSRod Evans Dyninfo *dip; 967c478bd9Sstevel@tonic-gate Sym *symdef; 977c478bd9Sstevel@tonic-gate ulong_t rsymndx; 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate /* 1007c478bd9Sstevel@tonic-gate * Scan through the .dynamic section of this object looking for all 1017c478bd9Sstevel@tonic-gate * DT_REGISTER entries. For each DT_REGISTER entry found identify the 1027c478bd9Sstevel@tonic-gate * register symbol it identifies and confirm that it doesn't conflict 1037c478bd9Sstevel@tonic-gate * with any other register symbols. 1047c478bd9Sstevel@tonic-gate */ 105*f441771bSRod Evans for (dyn = DYN(lmp), dip = DYNINFO(lmp); 106*f441771bSRod Evans !(dip->di_flags & FLG_DI_IGNORE); dyn++, dip++) { 1077c478bd9Sstevel@tonic-gate Reglist *rp; 1087c478bd9Sstevel@tonic-gate 109*f441771bSRod Evans if ((dip->di_flags & FLG_DI_REGISTER) == 0) 1107c478bd9Sstevel@tonic-gate continue; 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate /* 1137c478bd9Sstevel@tonic-gate * Get the local symbol table entry. 1147c478bd9Sstevel@tonic-gate */ 1157c478bd9Sstevel@tonic-gate rsymndx = dyn->d_un.d_val; 1167c478bd9Sstevel@tonic-gate symdef = (Sym *)((unsigned long)SYMTAB(lmp) + 1177c478bd9Sstevel@tonic-gate (rsymndx * SYMENT(lmp))); 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate for (rp = reglist; rp; rp = rp->rl_next) { 120de777a60Sab196087 Conv_inv_buf_t inv_buf; 1217c478bd9Sstevel@tonic-gate const char *str, *sym1, *sym2; 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate if (rp->rl_sym == symdef) { 1247c478bd9Sstevel@tonic-gate /* 1257c478bd9Sstevel@tonic-gate * Same symbol definition - everything is a-ok. 1267c478bd9Sstevel@tonic-gate */ 1277c478bd9Sstevel@tonic-gate return (1); 1287c478bd9Sstevel@tonic-gate } 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate sym1 = (STRTAB(rp->rl_lmp) + rp->rl_sym->st_name); 1317c478bd9Sstevel@tonic-gate sym2 = (STRTAB(lmp) + symdef->st_name); 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate if (check_regsyms(rp->rl_sym, sym1, symdef, sym2) == 0) 1347c478bd9Sstevel@tonic-gate continue; 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate if ((str = demangle(sym1)) != sym1) { 1377c478bd9Sstevel@tonic-gate char *_str = alloca(strlen(str) + 1); 1387c478bd9Sstevel@tonic-gate (void) strcpy(_str, str); 1397c478bd9Sstevel@tonic-gate sym1 = (const char *)_str; 1407c478bd9Sstevel@tonic-gate } 1417c478bd9Sstevel@tonic-gate sym2 = demangle(sym2); 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate if (LIST(lmp)->lm_flags & LML_FLG_TRC_WARN) { 1447c478bd9Sstevel@tonic-gate (void) printf(MSG_INTL(MSG_LDD_REG_SYMCONF), 145de777a60Sab196087 conv_sym_SPARC_value(symdef->st_value, 146de777a60Sab196087 0, &inv_buf), NAME(rp->rl_lmp), 147de777a60Sab196087 sym1, NAME(lmp), sym2); 1487c478bd9Sstevel@tonic-gate } else { 1495aefb655Srie eprintf(LIST(lmp), ERR_FATAL, 1505aefb655Srie MSG_INTL(MSG_REG_SYMCONF), 151de777a60Sab196087 conv_sym_SPARC_value(symdef->st_value, 152de777a60Sab196087 0, &inv_buf), NAME(rp->rl_lmp), 153de777a60Sab196087 sym1, NAME(lmp), sym2); 1547c478bd9Sstevel@tonic-gate return (0); 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate } 15756deab07SRod Evans if ((rp = calloc(sizeof (Reglist), 1)) == NULL) 1587c478bd9Sstevel@tonic-gate return (0); 1597c478bd9Sstevel@tonic-gate rp->rl_lmp = lmp; 1607c478bd9Sstevel@tonic-gate rp->rl_sym = symdef; 1617c478bd9Sstevel@tonic-gate rp->rl_next = reglist; 1627c478bd9Sstevel@tonic-gate reglist = rp; 1637c478bd9Sstevel@tonic-gate } 1647c478bd9Sstevel@tonic-gate return (1); 1657c478bd9Sstevel@tonic-gate } 166