| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: subr_kobj.c,v 1.66 2018/06/23 14:22:30 jakllsch Exp $ */ | | 1 | /* $NetBSD: subr_kobj.c,v 1.67 2020/06/27 17:27:59 christos Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software developed for The NetBSD Foundation | | 7 | * This code is derived from software developed for The NetBSD Foundation |
8 | * by Andrew Doran. | | 8 | * by Andrew Doran. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -53,27 +53,27 @@ | | | @@ -53,27 +53,27 @@ |
53 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 53 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
54 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 54 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
55 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 55 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
56 | * SUCH DAMAGE. | | 56 | * SUCH DAMAGE. |
57 | */ | | 57 | */ |
58 | | | 58 | |
59 | /* | | 59 | /* |
60 | * Kernel loader for ELF objects. | | 60 | * Kernel loader for ELF objects. |
61 | * | | 61 | * |
62 | * TODO: adjust kmem_alloc() calls to avoid needless fragmentation. | | 62 | * TODO: adjust kmem_alloc() calls to avoid needless fragmentation. |
63 | */ | | 63 | */ |
64 | | | 64 | |
65 | #include <sys/cdefs.h> | | 65 | #include <sys/cdefs.h> |
66 | __KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.66 2018/06/23 14:22:30 jakllsch Exp $"); | | 66 | __KERNEL_RCSID(0, "$NetBSD: subr_kobj.c,v 1.67 2020/06/27 17:27:59 christos Exp $"); |
67 | | | 67 | |
68 | #ifdef _KERNEL_OPT | | 68 | #ifdef _KERNEL_OPT |
69 | #include "opt_modular.h" | | 69 | #include "opt_modular.h" |
70 | #endif | | 70 | #endif |
71 | | | 71 | |
72 | #include <sys/kobj_impl.h> | | 72 | #include <sys/kobj_impl.h> |
73 | | | 73 | |
74 | #ifdef MODULAR | | 74 | #ifdef MODULAR |
75 | | | 75 | |
76 | #include <sys/param.h> | | 76 | #include <sys/param.h> |
77 | #include <sys/kernel.h> | | 77 | #include <sys/kernel.h> |
78 | #include <sys/kmem.h> | | 78 | #include <sys/kmem.h> |
79 | #include <sys/proc.h> | | 79 | #include <sys/proc.h> |
| @@ -879,65 +879,72 @@ kobj_sym_lookup(kobj_t ko, uintptr_t sym | | | @@ -879,65 +879,72 @@ kobj_sym_lookup(kobj_t ko, uintptr_t sym |
879 | const Elf_Sym *sym; | | 879 | const Elf_Sym *sym; |
880 | const char *symbol; | | 880 | const char *symbol; |
881 | | | 881 | |
882 | sym = ko->ko_symtab + symidx; | | 882 | sym = ko->ko_symtab + symidx; |
883 | | | 883 | |
884 | if (symidx == SHN_ABS) { | | 884 | if (symidx == SHN_ABS) { |
885 | *val = (uintptr_t)sym->st_value; | | 885 | *val = (uintptr_t)sym->st_value; |
886 | return 0; | | 886 | return 0; |
887 | } else if (symidx >= ko->ko_symcnt) { | | 887 | } else if (symidx >= ko->ko_symcnt) { |
888 | /* | | 888 | /* |
889 | * Don't even try to lookup the symbol if the index is | | 889 | * Don't even try to lookup the symbol if the index is |
890 | * bogus. | | 890 | * bogus. |
891 | */ | | 891 | */ |
892 | kobj_error(ko, "symbol index out of range"); | | 892 | kobj_error(ko, "symbol index %ju out of range", |
| | | 893 | (uintmax_t)symidx); |
893 | return EINVAL; | | 894 | return EINVAL; |
894 | } | | 895 | } |
895 | | | 896 | |
896 | /* Quick answer if there is a definition included. */ | | 897 | /* Quick answer if there is a definition included. */ |
897 | if (sym->st_shndx != SHN_UNDEF) { | | 898 | if (sym->st_shndx != SHN_UNDEF) { |
898 | *val = (uintptr_t)sym->st_value; | | 899 | *val = (uintptr_t)sym->st_value; |
899 | return 0; | | 900 | return 0; |
900 | } | | 901 | } |
901 | | | 902 | |
902 | /* If we get here, then it is undefined and needs a lookup. */ | | 903 | /* If we get here, then it is undefined and needs a lookup. */ |
903 | switch (ELF_ST_BIND(sym->st_info)) { | | 904 | switch (ELF_ST_BIND(sym->st_info)) { |
904 | case STB_LOCAL: | | 905 | case STB_LOCAL: |
905 | /* Local, but undefined? huh? */ | | 906 | /* Local, but undefined? huh? */ |
906 | kobj_error(ko, "local symbol undefined"); | | 907 | kobj_error(ko, "local symbol @%ju undefined", |
| | | 908 | (uintmax_t)symidx); |
907 | return EINVAL; | | 909 | return EINVAL; |
908 | | | 910 | |
909 | case STB_GLOBAL: | | 911 | case STB_GLOBAL: |
910 | /* Relative to Data or Function name */ | | 912 | /* Relative to Data or Function name */ |
911 | symbol = ko->ko_strtab + sym->st_name; | | 913 | symbol = ko->ko_strtab + sym->st_name; |
912 | | | 914 | |
913 | /* Force a lookup failure if the symbol name is bogus. */ | | 915 | /* Force a lookup failure if the symbol name is bogus. */ |
914 | if (*symbol == 0) { | | 916 | if (*symbol == 0) { |
915 | kobj_error(ko, "bad symbol name"); | | 917 | kobj_error(ko, "bad symbol @%ju name", |
| | | 918 | (uintmax_t)symidx); |
916 | return EINVAL; | | 919 | return EINVAL; |
917 | } | | 920 | } |
918 | if (sym->st_value == 0) { | | 921 | if (sym->st_value == 0) { |
919 | kobj_error(ko, "bad value"); | | 922 | kobj_error(ko, "%s @%ju: bad value", symbol, |
| | | 923 | (uintmax_t)symidx); |
920 | return EINVAL; | | 924 | return EINVAL; |
921 | } | | 925 | } |
922 | | | 926 | |
923 | *val = (uintptr_t)sym->st_value; | | 927 | *val = (uintptr_t)sym->st_value; |
924 | return 0; | | 928 | return 0; |
925 | | | 929 | |
926 | case STB_WEAK: | | 930 | case STB_WEAK: |
927 | kobj_error(ko, "weak symbols not supported"); | | 931 | kobj_error(ko, "weak symbol @%ju not supported", |
| | | 932 | (uintmax_t)symidx); |
928 | return EINVAL; | | 933 | return EINVAL; |
929 | | | 934 | |
930 | default: | | 935 | default: |
| | | 936 | kobj_error(ko, "bad binding %#x for symbol @%ju", |
| | | 937 | ELF_ST_BIND(sym->st_info), (uintmax_t)symidx); |
931 | return EINVAL; | | 938 | return EINVAL; |
932 | } | | 939 | } |
933 | } | | 940 | } |
934 | | | 941 | |
935 | /* | | 942 | /* |
936 | * kobj_findbase: | | 943 | * kobj_findbase: |
937 | * | | 944 | * |
938 | * Return base address of the given section. | | 945 | * Return base address of the given section. |
939 | */ | | 946 | */ |
940 | static uintptr_t | | 947 | static uintptr_t |
941 | kobj_findbase(kobj_t ko, int sec) | | 948 | kobj_findbase(kobj_t ko, int sec) |
942 | { | | 949 | { |
943 | int i; | | 950 | int i; |