source: mainline/uspace/lib/dltest/dltest.c@ bf22cb78

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since bf22cb78 was 8e3bc063, checked in by Jiri Svoboda <jiri@…>, 6 years ago

dltest needs test that calls a function

During bringup of dynamic linking on a platform it is difficult to test
dynamic function calls (via PLT) if the binaries (including dltest)
are statically linked. We can do that by adding a function to libdltest
that calls another function. Since we don't use -Bsymbolic, the call
will be made via PLT.

  • Property mode set to 100644
File size: 4.5 KB
RevLine 
[9182e86f]1/*
2 * Copyright (c) 2016 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libdltest
30 * @{
31 */
32/** @file
33 */
34
[0dc9a474]35#include <fibril.h>
[9182e86f]36#include "libdltest.h"
37
38/** Private initialized variable */
39static int private_var = dl_private_var_val;
40/** Private uninitialized variable */
41static int private_uvar;
42
43/** Public initialized variable */
44int dl_public_var = dl_public_var_val;
45/** Public uninitialized variable */
46int dl_public_uvar;
47
[0dc9a474]48/** Private initialized fibril-local variable */
49static fibril_local int dl_private_fib_var = dl_private_fib_var_val;
50/** Private uninitialized fibril-local variable */
51static fibril_local int dl_private_fib_uvar;
52
53/** Public initialized fibril-local variable */
54fibril_local int dl_public_fib_var = dl_public_fib_var_val;
55/** Public uninitialized fibril-local variable */
56fibril_local int dl_public_fib_uvar;
57
[9182e86f]58/** Return constant value. */
59int dl_get_constant(void)
60{
61 return dl_constant;
62}
63
[8e3bc063]64/** Return constant value by calling another function.
65 *
66 * This can be used to test dynamically linked call (via PLT) even in case
67 * binaries are statically linked.
68 */
69int dl_get_constant_via_call(void)
70{
71 return dl_get_constant();
72}
73
[9182e86f]74/** Return value of private initialized variable */
75int dl_get_private_var(void)
76{
77 return private_var;
78}
79
[97696ab]80/** Return address of private initialized variable */
81int *dl_get_private_var_addr(void)
82{
83 return &private_var;
84}
85
[9182e86f]86/** Return value of private uninitialized variable */
87int dl_get_private_uvar(void)
88{
89 return private_uvar;
90}
91
[97696ab]92/** Return vaddress of private uninitialized variable */
93int *dl_get_private_uvar_addr(void)
94{
95 return &private_uvar;
96}
97
[9182e86f]98/** Return value of public initialized variable */
99int dl_get_public_var(void)
100{
101 return dl_public_var;
102}
103
[97696ab]104/** Return address of public initialized variable */
105int *dl_get_public_var_addr(void)
106{
107 return &dl_public_var;
108}
109
[9182e86f]110/** Return value of public uninitialized variable */
111int dl_get_public_uvar(void)
112{
113 return dl_public_uvar;
114}
115
[97696ab]116/** Return address of public uninitialized variable */
117int *dl_get_public_uvar_addr(void)
118{
119 return &dl_public_uvar;
120}
121
[0dc9a474]122/** Return value of private initialized fibril-local variable */
123int dl_get_private_fib_var(void)
124{
125 return dl_private_fib_var;
126}
127
[97696ab]128/** Return address of private initialized fibril-local variable */
129int *dl_get_private_fib_var_addr(void)
130{
131 return &dl_private_fib_var;
132}
133
[0dc9a474]134/** Return value of private uninitialized fibril-local variable */
135int dl_get_private_fib_uvar(void)
136{
137 return dl_private_fib_uvar;
138}
139
[97696ab]140/** Return address of private uninitialized fibril-local variable */
141int *dl_get_private_fib_uvar_addr(void)
142{
143 return &dl_private_fib_uvar;
144}
145
[0dc9a474]146/** Return value of public initialized fibril-local variable */
147int dl_get_public_fib_var(void)
148{
149 return dl_public_fib_var;
150}
151
[97696ab]152/** Return value of public initialized fibril-local variable */
153int *dl_get_public_fib_var_addr(void)
154{
155 return &dl_public_fib_var;
156}
157
[0dc9a474]158/** Return value of public uninitialized fibril-local variable */
159int dl_get_public_fib_uvar(void)
160{
161 return dl_public_fib_uvar;
162}
163
[97696ab]164/** Return value of public uninitialized fibril-local variable */
165int *dl_get_public_fib_uvar_addr(void)
166{
167 return &dl_public_fib_uvar;
168}
169
[9182e86f]170/**
171 * @}
172 */
Note: See TracBrowser for help on using the repository browser.