1 /* $OpenBSD: bb.c,v 1.2 2010/06/20 17:57:09 phessler Exp $ */
2
3 /*
4 * Copyright (c) 2005 Kurt Miller <kurt@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include <stdio.h>
20
21 int weakFunction1(void) __attribute__((weak));
22 int weakFunction2(void) __attribute__((weak));
23
24 /* this function should be called */
25 int
weakFunction1()26 weakFunction1()
27 {
28 return 0;
29 }
30
31 /* this function should be not be called, the one it libaa should */
32 int
weakFunction2()33 weakFunction2()
34 {
35 return 1;
36 }
37
38 int
bbTest1()39 bbTest1()
40 {
41 int ret = 0;
42
43 /*
44 * make sure weakFunction1 from libaa (undefined weak) doesn't
45 * interfere with calling weakFunction1 here
46 */
47 if (weakFunction1) {
48 weakFunction1();
49 } else {
50 printf("weakFunction1() overwritten by undefined weak "
51 "in libaa\n");
52 ret = 1;
53 }
54
55 /*
56 * make sure weakFunction2 from libaa is called instead of the
57 * one here
58 */
59 if (weakFunction2()) {
60 printf("wrong weakFunction2() called\n");
61 ret = 1;
62 }
63
64 return (ret);
65 }
66