Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / toolchain / wrap_main.c
1 /*
2  * Copyright (c) 2014 The Native Client Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6
7 /*
8  * Ensure that linker symbol name rewriting works.
9  *
10  * When using ``-Wl,--wrap=sym``, the ``sym`` definition is rewritten to
11  * ``__real_sym`` and all calls/declarations of ``sym`` are rewritten to
12  * `__wrap_sym``. Note that this only applies across object files,
13  * direct calls within an object file are unaffected.
14  *
15  * The wrap_lib{1,2}.c files are built as an archive and linked with
16  * wrap_main.c. They contain the ``foo`` and ``bar`` definitions as well
17  * as their wrapped equivalents. wrap_main.c calls ``foo`` and ``bar``,
18  * which are rewritten to calls to the ``__wrap_*`` functions
19  * instead. The ``__wrap_*`` functions then call the ``__real_*`` ones,
20  * which are the now-renamed ``foo`` and ``bar``.
21  *
22  * The golden file expects the four functions to get called, and as an
23  * extra check we expect the sum of the return value of the functions to
24  * be 2+3+5+7 (the return value of each of the four functions).
25  */
26
27 #include <stdlib.h>
28
29 extern int foo(void);
30 extern int bar(void);
31
32 int main(void) {
33   int f = foo();
34   int b = bar();
35   return f + b == 17 ? EXIT_SUCCESS : EXIT_FAILURE;
36 }