h_helper_ifunc.c revision 302408
190792Sgshapiro/*-
2261194Sgshapiro * Copyright (c) 2014 The NetBSD Foundation, Inc.
390792Sgshapiro * All rights reserved.
490792Sgshapiro *
590792Sgshapiro * This code is derived from software contributed to The NetBSD Foundation
690792Sgshapiro * by Joerg Sonnenberger.
790792Sgshapiro *
890792Sgshapiro * Redistribution and use in source and binary forms, with or without
990792Sgshapiro * modification, are permitted provided that the following conditions
1090792Sgshapiro * are met:
11261194Sgshapiro * 1. Redistributions of source code must retain the above copyright
1290792Sgshapiro *    notice, this list of conditions and the following disclaimer.
1390792Sgshapiro * 2. Redistributions in binary form must reproduce the above copyright
1490792Sgshapiro *    notice, this list of conditions and the following disclaimer in the
1590792Sgshapiro *    documentation and/or other materials provided with the distribution.
1690792Sgshapiro *
1790792Sgshapiro * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1890792Sgshapiro * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1990792Sgshapiro * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2090792Sgshapiro * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2190792Sgshapiro * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2290792Sgshapiro * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2394334Sgshapiro * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2490792Sgshapiro * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2590792Sgshapiro * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2690792Sgshapiro * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2790792Sgshapiro * POSSIBILITY OF SUCH DAMAGE.
2890792Sgshapiro */
2990792Sgshapiro
3090792Sgshapiro#include <stdlib.h>
3190792Sgshapiro#include <string.h>
3294334Sgshapiro
3394334Sgshapirostatic int
3494334Sgshapiroifunc1(void)
3590792Sgshapiro{
3690792Sgshapiro	return 0xdeadbeef;
3790792Sgshapiro}
3890792Sgshapiro
39static int
40ifunc2(void)
41{
42	return 0xbeefdead;
43}
44
45static __attribute__((used))
46int (*resolve_ifunc(void))(void)
47{
48	const char *e = getenv("USE_IFUNC2");
49	return e && strcmp(e, "1") == 0 ? ifunc2 : ifunc1;
50}
51
52__ifunc(ifunc, resolve_ifunc);
53