GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libc/dlfcn/dlfcn_stubs.c Lines: 0 14 0.0 %
Date: 2017-11-07 Branches: 0 2 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: dlfcn_stubs.c,v 1.14 2016/09/06 18:49:34 guenther Exp $	*/
2
3
/*
4
 * Copyright (c) 1998 Per Fogelstrom, Opsycon AB
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 * 1. Redistributions of source code must retain the above copyright
10
 *    notice, this list of conditions and the following disclaimer.
11
 * 2. 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
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
 * SUCH DAMAGE.
26
 *
27
 */
28
29
#include <sys/types.h>
30
#include <stddef.h>
31
#include <link.h>
32
33
#include "init.h"
34
35
/*
36
 *	All functions here are just stubs that will be overridden
37
 *	by the real functions in ld.so when dynamic loading is
38
 *	performed at exec. The symbols here are provided as a link
39
 *	helper so we can link a program using the dl functions
40
 *	without getting any unresolved references.
41
 */
42
43
void	*dlopen(const char *libname, int how) __attribute__((weak));
44
int	 dlclose(void *handle) __attribute__((weak));
45
void	*dlsym(void *handle, const char *name) __attribute__((weak));
46
int	 dlctl(void *handle, int command, void *data) __attribute__((weak));
47
char 	*dlerror(void) __attribute__((weak));
48
49
struct dl_info;
50
int	dladdr(const void *addr, struct dl_info *info) __attribute__((weak));
51
52
int	 dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *),	    void *date) __attribute__((weak));
53
54
#include <stdio.h>
55
56
void *
57
dlopen(const char *libname, int how)
58
{
59
	printf("Wrong dl symbols!\n");
60
	return NULL;
61
}
62
63
int
64
dlclose(void *handle)
65
{
66
	printf("Wrong dl symbols!\n");
67
	return 0;
68
}
69
70
void *
71
dlsym(void *handle, const char *name)
72
{
73
	printf("Wrong dl symbols!\n");
74
	return NULL;
75
}
76
77
int
78
dlctl(void *handle, int command, void *data)
79
{
80
	return -1;
81
}
82
83
char *
84
dlerror(void)
85
{
86
	return "Wrong dl symbols!\n";
87
}
88
89
int
90
dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *),
91
	void *data)
92
{
93
#ifndef PIC
94
	if (_static_phdr_info.dlpi_phdr != NULL)
95
		return callback(&_static_phdr_info, sizeof(_static_phdr_info),
96
		    data);
97
#endif /* !PIC */
98
	return -1;
99
}
100
101
int
102
dladdr(const void *addr, struct dl_info *info)
103
{
104
	printf("Wrong dl symbols!\n");
105
	return -1;
106
}
107
108
/* Thread Local Storage argument structure */
109
typedef struct {
110
	unsigned long int ti_module;
111
	unsigned long int ti_offset;
112
} tls_index;
113
114
void	*__tls_get_addr(tls_index *) __attribute__((weak));
115
#ifdef __i386
116
void	*___tls_get_addr(tls_index *) __attribute__((weak, __regparm__(1)));
117
#endif
118
119
#if defined(__amd64) || defined(__i386) || defined(__sparc64)
120
void *
121
__tls_get_addr(tls_index *ti)
122
{
123
	return NULL;
124
}
125
126
#ifdef __i386
127
__attribute__((__regparm__(1))) void *
128
___tls_get_addr(tls_index *ti)
129
{
130
	return NULL;
131
}
132
#endif /* __i386 */
133
#endif /* arch with TLS support enabled */