19351ac6dSMark Johnston /*-
29351ac6dSMark Johnston * Copyright (c) 2014 Mark Johnston <markj@FreeBSD.org>
39351ac6dSMark Johnston * All rights reserved.
49351ac6dSMark Johnston *
59351ac6dSMark Johnston * Redistribution and use in source and binary forms, with or without
69351ac6dSMark Johnston * modification, are permitted provided that the following conditions
79351ac6dSMark Johnston * are met:
89351ac6dSMark Johnston * 1. Redistributions of source code must retain the above copyright
99351ac6dSMark Johnston * notice, this list of conditions and the following disclaimer.
109351ac6dSMark Johnston * 2. Redistributions in binary form must reproduce the above copyright
119351ac6dSMark Johnston * notice, this list of conditions and the following disclaimer in the
129351ac6dSMark Johnston * documentation and/or other materials provided with the distribution.
139351ac6dSMark Johnston *
149351ac6dSMark Johnston * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
159351ac6dSMark Johnston * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
169351ac6dSMark Johnston * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
179351ac6dSMark Johnston * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
189351ac6dSMark Johnston * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199351ac6dSMark Johnston * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
209351ac6dSMark Johnston * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
219351ac6dSMark Johnston * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
229351ac6dSMark Johnston * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
239351ac6dSMark Johnston * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
249351ac6dSMark Johnston * SUCH DAMAGE.
259351ac6dSMark Johnston */
269351ac6dSMark Johnston
279351ac6dSMark Johnston #include <sys/cdefs.h>
289351ac6dSMark Johnston #include <err.h>
299351ac6dSMark Johnston #include <signal.h>
309351ac6dSMark Johnston #include <stdlib.h>
319351ac6dSMark Johnston #include <string.h>
329351ac6dSMark Johnston #include <unistd.h>
339351ac6dSMark Johnston
349351ac6dSMark Johnston static volatile sig_atomic_t saw;
359351ac6dSMark Johnston
369351ac6dSMark Johnston static void
usr1(int sig __unused)379351ac6dSMark Johnston usr1(int sig __unused)
389351ac6dSMark Johnston {
399351ac6dSMark Johnston
409351ac6dSMark Johnston saw = 1;
419351ac6dSMark Johnston }
429351ac6dSMark Johnston
43*1bdc41d2SMark Johnston void foo(void);
44*1bdc41d2SMark Johnston void qux(void);
45*1bdc41d2SMark Johnston
46*1bdc41d2SMark Johnston void
foo(void)47*1bdc41d2SMark Johnston foo(void)
48*1bdc41d2SMark Johnston {
49*1bdc41d2SMark Johnston }
50*1bdc41d2SMark Johnston __weak_reference(foo, _foo);
51*1bdc41d2SMark Johnston
52*1bdc41d2SMark Johnston static void
bar(void)53*1bdc41d2SMark Johnston bar(void)
54*1bdc41d2SMark Johnston {
55*1bdc41d2SMark Johnston }
56*1bdc41d2SMark Johnston __strong_reference(bar, baz);
57*1bdc41d2SMark Johnston
58*1bdc41d2SMark Johnston void
qux(void)59*1bdc41d2SMark Johnston qux(void)
60*1bdc41d2SMark Johnston {
61*1bdc41d2SMark Johnston }
62*1bdc41d2SMark Johnston __strong_reference(qux, $qux);
63*1bdc41d2SMark Johnston
649351ac6dSMark Johnston int
main(int argc,char ** argv)659351ac6dSMark Johnston main(int argc, char **argv)
669351ac6dSMark Johnston {
679351ac6dSMark Johnston
68*1bdc41d2SMark Johnston bar(); /* force the symbol to be emitted */
69*1bdc41d2SMark Johnston
709351ac6dSMark Johnston if (argc == 1)
719351ac6dSMark Johnston return (EXIT_SUCCESS);
729351ac6dSMark Johnston if (argc == 2 && strcmp(argv[1], "-s") == 0) {
739351ac6dSMark Johnston if (signal(SIGUSR1, usr1) == SIG_ERR)
749351ac6dSMark Johnston err(1, "signal");
759351ac6dSMark Johnston if (kill(getpid(), SIGUSR1) != 0)
769351ac6dSMark Johnston err(1, "kill");
779351ac6dSMark Johnston return (saw == 1 ? EXIT_SUCCESS : EXIT_FAILURE);
789351ac6dSMark Johnston }
799351ac6dSMark Johnston return (EXIT_FAILURE);
809351ac6dSMark Johnston }
81