11.1Sjoerg/*- 21.1Sjoerg * Copyright (c) 2014 The NetBSD Foundation, Inc. 31.1Sjoerg * All rights reserved. 41.1Sjoerg * 51.1Sjoerg * This code is derived from software contributed to The NetBSD Foundation 61.1Sjoerg * by Joerg Sonnenberger. 71.1Sjoerg * 81.1Sjoerg * Redistribution and use in source and binary forms, with or without 91.1Sjoerg * modification, are permitted provided that the following conditions 101.1Sjoerg * are met: 111.1Sjoerg * 1. Redistributions of source code must retain the above copyright 121.1Sjoerg * notice, this list of conditions and the following disclaimer. 131.1Sjoerg * 2. Redistributions in binary form must reproduce the above copyright 141.1Sjoerg * notice, this list of conditions and the following disclaimer in the 151.1Sjoerg * documentation and/or other materials provided with the distribution. 161.1Sjoerg * 171.1Sjoerg * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 181.1Sjoerg * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 191.1Sjoerg * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 201.1Sjoerg * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 211.1Sjoerg * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 221.1Sjoerg * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 231.1Sjoerg * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 241.1Sjoerg * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 251.1Sjoerg * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 261.1Sjoerg * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 271.1Sjoerg * POSSIBILITY OF SUCH DAMAGE. 281.1Sjoerg */ 291.1Sjoerg 301.1Sjoerg#include <stdlib.h> 311.1Sjoerg#include <string.h> 321.1Sjoerg 331.8Sskrll/* 341.10Schristos * Not supported on hppa 351.8Sskrll */ 361.10Schristos#if !defined(__hppa__) 371.8Sskrll 381.7Sjoergstatic long long 391.1Sjoergifunc1(void) 401.1Sjoerg{ 411.7Sjoerg return 0xdeadbeefll; 421.1Sjoerg} 431.1Sjoerg 441.7Sjoergstatic long long 451.1Sjoergifunc2(void) 461.1Sjoerg{ 471.7Sjoerg return 0xbeefdeadll; 481.1Sjoerg} 491.1Sjoerg 501.1Sjoergstatic __attribute__((used)) 511.7Sjoerglong long (*resolve_ifunc(void))(void) 521.1Sjoerg{ 531.1Sjoerg const char *e = getenv("USE_IFUNC2"); 541.1Sjoerg return e && strcmp(e, "1") == 0 ? ifunc2 : ifunc1; 551.1Sjoerg} 561.1Sjoerg 571.5Sjoergstatic __attribute__((used)) 581.7Sjoerglong long (*resolve_ifunc2(void))(void) 591.5Sjoerg{ 601.5Sjoerg const char *e = getenv("USE_IFUNC2"); 611.5Sjoerg return e && strcmp(e, "1") == 0 ? ifunc1 : ifunc2; 621.5Sjoerg} 631.5Sjoerg 641.4Sjoerg__ifunc(ifunc, resolve_ifunc); 651.5Sjoerg__hidden_ifunc(ifunc_hidden, resolve_ifunc2); 661.5Sjoerg 671.7Sjoerglong long ifunc_hidden(void); 681.7Sjoerglong long ifunc_plt(void); 691.5Sjoerg 701.7Sjoerglong long ifunc_plt(void) 711.5Sjoerg{ 721.5Sjoerg return ifunc_hidden(); 731.5Sjoerg} 741.6Sjoerg 751.7Sjoerglong long (*ifunc_indirect(void))(void); 761.6Sjoerg 771.7Sjoerglong long (*ifunc_indirect(void))(void) 781.6Sjoerg{ 791.6Sjoerg return ifunc_hidden; 801.6Sjoerg} 811.8Sskrll#endif 82