| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: t_ifunc.c,v 1.7 2018/01/01 06:34:13 maya Exp $ */ | | 1 | /* $NetBSD: t_ifunc.c,v 1.8 2018/03/09 20:15:03 joerg Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2014 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2014 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -43,32 +43,32 @@ | | | @@ -43,32 +43,32 @@ |
43 | | | 43 | |
44 | ATF_TC(rtld_ifunc); | | 44 | ATF_TC(rtld_ifunc); |
45 | | | 45 | |
46 | ATF_TC_HEAD(rtld_ifunc, tc) | | 46 | ATF_TC_HEAD(rtld_ifunc, tc) |
47 | { | | 47 | { |
48 | atf_tc_set_md_var(tc, "descr", "ifunc functions are resolved"); | | 48 | atf_tc_set_md_var(tc, "descr", "ifunc functions are resolved"); |
49 | } | | 49 | } |
50 | | | 50 | |
51 | ATF_TC_BODY(rtld_ifunc, tc) | | 51 | ATF_TC_BODY(rtld_ifunc, tc) |
52 | { | | 52 | { |
53 | const char *envstr[] = { | | 53 | const char *envstr[] = { |
54 | "0", "1" | | 54 | "0", "1" |
55 | }; | | 55 | }; |
56 | int expected_result[] = { | | 56 | long long expected_result[] = { |
57 | 0xdeadbeef, 0xbeefdead | | 57 | 0xdeadbeefll, 0xbeefdeadll |
58 | }; | | 58 | }; |
59 | void *handle; | | 59 | void *handle; |
60 | int (*sym)(void); | | 60 | long long (*sym)(void); |
61 | int result; | | 61 | long long result; |
62 | const char *error; | | 62 | const char *error; |
63 | size_t i; | | 63 | size_t i; |
64 | | | 64 | |
65 | if (!LINKER_SUPPORT) | | 65 | if (!LINKER_SUPPORT) |
66 | atf_tc_skip("Missing linker support for ifunc relocations"); | | 66 | atf_tc_skip("Missing linker support for ifunc relocations"); |
67 | | | 67 | |
68 | for (i = 0; i < __arraycount(envstr); ++i) { | | 68 | for (i = 0; i < __arraycount(envstr); ++i) { |
69 | setenv("USE_IFUNC2", envstr[i], 1); | | 69 | setenv("USE_IFUNC2", envstr[i], 1); |
70 | | | 70 | |
71 | handle = dlopen("libh_helper_ifunc_dso.so", RTLD_LAZY); | | 71 | handle = dlopen("libh_helper_ifunc_dso.so", RTLD_LAZY); |
72 | error = dlerror(); | | 72 | error = dlerror(); |
73 | ATF_CHECK(error == NULL); | | 73 | ATF_CHECK(error == NULL); |
74 | ATF_CHECK(handle != NULL); | | 74 | ATF_CHECK(handle != NULL); |
| @@ -76,53 +76,53 @@ ATF_TC_BODY(rtld_ifunc, tc) | | | @@ -76,53 +76,53 @@ ATF_TC_BODY(rtld_ifunc, tc) |
76 | sym = dlsym(handle, "ifunc"); | | 76 | sym = dlsym(handle, "ifunc"); |
77 | error = dlerror(); | | 77 | error = dlerror(); |
78 | ATF_CHECK(error == NULL); | | 78 | ATF_CHECK(error == NULL); |
79 | ATF_CHECK(sym != NULL); | | 79 | ATF_CHECK(sym != NULL); |
80 | | | 80 | |
81 | result = (*sym)(); | | 81 | result = (*sym)(); |
82 | ATF_CHECK(result == expected_result[i]); | | 82 | ATF_CHECK(result == expected_result[i]); |
83 | | | 83 | |
84 | dlclose(handle); | | 84 | dlclose(handle); |
85 | error = dlerror(); | | 85 | error = dlerror(); |
86 | ATF_CHECK(error == NULL); | | 86 | ATF_CHECK(error == NULL); |
87 | | | 87 | |
88 | char *command; | | 88 | char *command; |
89 | easprintf(&command, "%s/h_ifunc %d", | | 89 | easprintf(&command, "%s/h_ifunc %lld", |
90 | atf_tc_get_config_var(tc, "srcdir"), expected_result[i]); | | 90 | atf_tc_get_config_var(tc, "srcdir"), expected_result[i]); |
91 | if (system(command) != EXIT_SUCCESS) | | 91 | if (system(command) != EXIT_SUCCESS) |
92 | atf_tc_fail("Test failed; see output for details"); | | 92 | atf_tc_fail("Test failed; see output for details"); |
93 | free(command); | | 93 | free(command); |
94 | } | | 94 | } |
95 | } | | 95 | } |
96 | | | 96 | |
97 | ATF_TC(rtld_hidden_ifunc); | | 97 | ATF_TC(rtld_hidden_ifunc); |
98 | | | 98 | |
99 | ATF_TC_HEAD(rtld_hidden_ifunc, tc) | | 99 | ATF_TC_HEAD(rtld_hidden_ifunc, tc) |
100 | { | | 100 | { |
101 | atf_tc_set_md_var(tc, "descr", "hidden ifunc functions are resolved"); | | 101 | atf_tc_set_md_var(tc, "descr", "hidden ifunc functions are resolved"); |
102 | } | | 102 | } |
103 | | | 103 | |
104 | ATF_TC_BODY(rtld_hidden_ifunc, tc) | | 104 | ATF_TC_BODY(rtld_hidden_ifunc, tc) |
105 | { | | 105 | { |
106 | const char *envstr[] = { | | 106 | const char *envstr[] = { |
107 | "0", "1" | | 107 | "0", "1" |
108 | }; | | 108 | }; |
109 | int expected_result[] = { | | 109 | long long expected_result[] = { |
110 | 0xdeadbeef, 0xbeefdead | | 110 | 0xdeadbeefll, 0xbeefdeadll |
111 | }; | | 111 | }; |
112 | void *handle; | | 112 | void *handle; |
113 | int (*sym)(void); | | 113 | long long (*sym)(void); |
114 | int (*(*sym2)(void))(void); | | 114 | long long (*(*sym2)(void))(void); |
115 | int result; | | 115 | long long result; |
116 | const char *error; | | 116 | const char *error; |
117 | size_t i; | | 117 | size_t i; |
118 | | | 118 | |
119 | if (!LINKER_SUPPORT) | | 119 | if (!LINKER_SUPPORT) |
120 | atf_tc_skip("Missing linker support for ifunc relocations"); | | 120 | atf_tc_skip("Missing linker support for ifunc relocations"); |
121 | | | 121 | |
122 | for (i = 0; i < __arraycount(envstr); ++i) { | | 122 | for (i = 0; i < __arraycount(envstr); ++i) { |
123 | setenv("USE_IFUNC2", envstr[i], 1); | | 123 | setenv("USE_IFUNC2", envstr[i], 1); |
124 | | | 124 | |
125 | handle = dlopen("libh_helper_ifunc_dso.so", RTLD_LAZY); | | 125 | handle = dlopen("libh_helper_ifunc_dso.so", RTLD_LAZY); |
126 | error = dlerror(); | | 126 | error = dlerror(); |
127 | ATF_CHECK(error == NULL); | | 127 | ATF_CHECK(error == NULL); |
128 | ATF_CHECK(handle != NULL); | | 128 | ATF_CHECK(handle != NULL); |
| @@ -139,58 +139,58 @@ ATF_TC_BODY(rtld_hidden_ifunc, tc) | | | @@ -139,58 +139,58 @@ ATF_TC_BODY(rtld_hidden_ifunc, tc) |
139 | error = dlerror(); | | 139 | error = dlerror(); |
140 | ATF_CHECK(error == NULL); | | 140 | ATF_CHECK(error == NULL); |
141 | ATF_CHECK(sym2 != NULL); | | 141 | ATF_CHECK(sym2 != NULL); |
142 | | | 142 | |
143 | sym = (*sym2)(); | | 143 | sym = (*sym2)(); |
144 | result = (*sym)(); | | 144 | result = (*sym)(); |
145 | ATF_CHECK(result == expected_result[!i]); | | 145 | ATF_CHECK(result == expected_result[!i]); |
146 | | | 146 | |
147 | dlclose(handle); | | 147 | dlclose(handle); |
148 | error = dlerror(); | | 148 | error = dlerror(); |
149 | ATF_CHECK(error == NULL); | | 149 | ATF_CHECK(error == NULL); |
150 | | | 150 | |
151 | char *command; | | 151 | char *command; |
152 | easprintf(&command, "%s/h_ifunc %d", | | 152 | easprintf(&command, "%s/h_ifunc %lld", |
153 | atf_tc_get_config_var(tc, "srcdir"), expected_result[i]); | | 153 | atf_tc_get_config_var(tc, "srcdir"), expected_result[i]); |
154 | if (system(command) != EXIT_SUCCESS) | | 154 | if (system(command) != EXIT_SUCCESS) |
155 | atf_tc_fail("Test failed; see output for details"); | | 155 | atf_tc_fail("Test failed; see output for details"); |
156 | free(command); | | 156 | free(command); |
157 | } | | 157 | } |
158 | } | | 158 | } |
159 | | | 159 | |
160 | ATF_TC(rtld_main_ifunc); | | 160 | ATF_TC(rtld_main_ifunc); |
161 | ATF_TC_HEAD(rtld_main_ifunc, tc) | | 161 | ATF_TC_HEAD(rtld_main_ifunc, tc) |
162 | { | | 162 | { |
163 | atf_tc_set_md_var(tc, "descr", | | 163 | atf_tc_set_md_var(tc, "descr", |
164 | "ifunc functions are resolved in the executable"); | | 164 | "ifunc functions are resolved in the executable"); |
165 | } | | 165 | } |
166 | | | 166 | |
167 | #if LINKER_SUPPORT | | 167 | #if LINKER_SUPPORT |
168 | static unsigned int | | 168 | static long long |
169 | ifunc_helper(void) | | 169 | ifunc_helper(void) |
170 | { | | 170 | { |
171 | return 0xdeadbeef; | | 171 | return 0xdeadbeefll; |
172 | } | | 172 | } |
173 | | | 173 | |
174 | static __attribute__((used)) | | 174 | static __attribute__((used)) |
175 | unsigned int (*resolve_ifunc(void))(void) | | 175 | long long (*resolve_ifunc(void))(void) |
176 | { | | 176 | { |
177 | return ifunc_helper; | | 177 | return ifunc_helper; |
178 | } | | 178 | } |
179 | __hidden_ifunc(ifunc, resolve_ifunc); | | 179 | __hidden_ifunc(ifunc, resolve_ifunc); |
180 | #endif | | 180 | #endif |
181 | unsigned int ifunc(void); | | 181 | long long ifunc(void); |
182 | | | 182 | |
183 | ATF_TC_BODY(rtld_main_ifunc, tc) | | 183 | ATF_TC_BODY(rtld_main_ifunc, tc) |
184 | { | | 184 | { |
185 | if (!LINKER_SUPPORT) | | 185 | if (!LINKER_SUPPORT) |
186 | atf_tc_skip("Missing linker support for ifunc relocations"); | | 186 | atf_tc_skip("Missing linker support for ifunc relocations"); |
187 | ATF_CHECK(ifunc() == 0xdeadbeef); | | 187 | ATF_CHECK(ifunc() == 0xdeadbeefll); |
188 | } | | 188 | } |
189 | | | 189 | |
190 | ATF_TP_ADD_TCS(tp) | | 190 | ATF_TP_ADD_TCS(tp) |
191 | { | | 191 | { |
192 | ATF_TP_ADD_TC(tp, rtld_ifunc); | | 192 | ATF_TP_ADD_TC(tp, rtld_ifunc); |
193 | ATF_TP_ADD_TC(tp, rtld_hidden_ifunc); | | 193 | ATF_TP_ADD_TC(tp, rtld_hidden_ifunc); |
194 | ATF_TP_ADD_TC(tp, rtld_main_ifunc); | | 194 | ATF_TP_ADD_TC(tp, rtld_main_ifunc); |
195 | return 0; | | 195 | return 0; |
196 | } | | 196 | } |