Fri Mar 9 20:15:03 2018 UTC ()
Avoid casting fun by switching ifunc helper functions to return
long long. Dead beef is too useful to switch to a different constant.


(joerg)
diff -r1.1 -r1.2 src/tests/libexec/ld.elf_so/h_ifunc.c
diff -r1.7 -r1.8 src/tests/libexec/ld.elf_so/t_ifunc.c
diff -r1.6 -r1.7 src/tests/libexec/ld.elf_so/helper_ifunc_dso/h_helper_ifunc.c

cvs diff -r1.1 -r1.2 src/tests/libexec/ld.elf_so/h_ifunc.c (expand / switch to unified diff)

--- src/tests/libexec/ld.elf_so/h_ifunc.c 2014/08/25 20:40:53 1.1
+++ src/tests/libexec/ld.elf_so/h_ifunc.c 2018/03/09 20:15:03 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: h_ifunc.c,v 1.1 2014/08/25 20:40:53 joerg Exp $ */ 1/* $NetBSD: h_ifunc.c,v 1.2 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 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Joerg Sonnenberger. 8 * by Joerg Sonnenberger.
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.
@@ -21,23 +21,23 @@ @@ -21,23 +21,23 @@
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <stdlib.h> 32#include <stdlib.h>
33 33
34extern int ifunc(void); 34extern long long ifunc(void);
35 35
36int 36int
37main(int argc, char **argv) 37main(int argc, char **argv)
38{ 38{
39 39
40 if (argc != 2) 40 if (argc != 2)
41 return 1; 41 return 1;
42 return ifunc() != atoi(argv[1]); 42 return ifunc() != atoll(argv[1]);
43} 43}

cvs diff -r1.7 -r1.8 src/tests/libexec/ld.elf_so/t_ifunc.c (expand / switch to unified diff)

--- src/tests/libexec/ld.elf_so/t_ifunc.c 2018/01/01 06:34:13 1.7
+++ src/tests/libexec/ld.elf_so/t_ifunc.c 2018/03/09 20:15:03 1.8
@@ -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
44ATF_TC(rtld_ifunc); 44ATF_TC(rtld_ifunc);
45 45
46ATF_TC_HEAD(rtld_ifunc, tc) 46ATF_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
51ATF_TC_BODY(rtld_ifunc, tc) 51ATF_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
97ATF_TC(rtld_hidden_ifunc); 97ATF_TC(rtld_hidden_ifunc);
98 98
99ATF_TC_HEAD(rtld_hidden_ifunc, tc) 99ATF_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
104ATF_TC_BODY(rtld_hidden_ifunc, tc) 104ATF_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
160ATF_TC(rtld_main_ifunc); 160ATF_TC(rtld_main_ifunc);
161ATF_TC_HEAD(rtld_main_ifunc, tc) 161ATF_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
168static unsigned int 168static long long
169ifunc_helper(void) 169ifunc_helper(void)
170{ 170{
171 return 0xdeadbeef; 171 return 0xdeadbeefll;
172} 172}
173 173
174static __attribute__((used)) 174static __attribute__((used))
175unsigned int (*resolve_ifunc(void))(void) 175long 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
181unsigned int ifunc(void); 181long long ifunc(void);
182 182
183ATF_TC_BODY(rtld_main_ifunc, tc) 183ATF_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
190ATF_TP_ADD_TCS(tp) 190ATF_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}

cvs diff -r1.6 -r1.7 src/tests/libexec/ld.elf_so/helper_ifunc_dso/h_helper_ifunc.c (expand / switch to unified diff)

--- src/tests/libexec/ld.elf_so/helper_ifunc_dso/h_helper_ifunc.c 2017/08/12 09:03:28 1.6
+++ src/tests/libexec/ld.elf_so/helper_ifunc_dso/h_helper_ifunc.c 2018/03/09 20:15:03 1.7
@@ -20,56 +20,56 @@ @@ -20,56 +20,56 @@
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE. 27 * POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30#include <stdlib.h> 30#include <stdlib.h>
31#include <string.h> 31#include <string.h>
32 32
33static int 33static long long
34ifunc1(void) 34ifunc1(void)
35{ 35{
36 return 0xdeadbeef; 36 return 0xdeadbeefll;
37} 37}
38 38
39static int 39static long long
40ifunc2(void) 40ifunc2(void)
41{ 41{
42 return 0xbeefdead; 42 return 0xbeefdeadll;
43} 43}
44 44
45static __attribute__((used)) 45static __attribute__((used))
46int (*resolve_ifunc(void))(void) 46long long (*resolve_ifunc(void))(void)
47{ 47{
48 const char *e = getenv("USE_IFUNC2"); 48 const char *e = getenv("USE_IFUNC2");
49 return e && strcmp(e, "1") == 0 ? ifunc2 : ifunc1; 49 return e && strcmp(e, "1") == 0 ? ifunc2 : ifunc1;
50} 50}
51 51
52static __attribute__((used)) 52static __attribute__((used))
53int (*resolve_ifunc2(void))(void) 53long long (*resolve_ifunc2(void))(void)
54{ 54{
55 const char *e = getenv("USE_IFUNC2"); 55 const char *e = getenv("USE_IFUNC2");
56 return e && strcmp(e, "1") == 0 ? ifunc1 : ifunc2; 56 return e && strcmp(e, "1") == 0 ? ifunc1 : ifunc2;
57} 57}
58 58
59__ifunc(ifunc, resolve_ifunc); 59__ifunc(ifunc, resolve_ifunc);
60__hidden_ifunc(ifunc_hidden, resolve_ifunc2); 60__hidden_ifunc(ifunc_hidden, resolve_ifunc2);
61 61
62int ifunc_hidden(void); 62long long ifunc_hidden(void);
63int ifunc_plt(void); 63long long ifunc_plt(void);
64 64
65int ifunc_plt(void) 65long long ifunc_plt(void)
66{ 66{
67 return ifunc_hidden(); 67 return ifunc_hidden();
68} 68}
69 69
70int (*ifunc_indirect(void))(void); 70long long (*ifunc_indirect(void))(void);
71 71
72int (*ifunc_indirect(void))(void) 72long long (*ifunc_indirect(void))(void)
73{ 73{
74 return ifunc_hidden; 74 return ifunc_hidden;
75} 75}