kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

lib_foo.c (864B)


      1 /* test/link/elf-dso-aa64/lib_foo.c — shared-library source fixture.
      2  *
      3  * Exported (appear in .dynsym as GLOBAL DEFAULT defined):
      4  *   foo_add        — function; calls bar_external (undefined import)
      5  *   foo_get_counter — function returning foo_counter
      6  *   foo_counter    — data, initial value 42
      7  *
      8  * Hidden (must NOT appear in .dynsym as a defined exported symbol):
      9  *   foo_hidden     — function with __attribute__((visibility("hidden")))
     10  *
     11  * Undefined import (appears in .dynsym as GLOBAL DEFAULT UND):
     12  *   bar_external   — called by foo_add; left unresolved at DSO link time
     13  */
     14 
     15 extern int bar_external(int x);
     16 
     17 int foo_counter = 42;
     18 
     19 int foo_add(int a, int b)
     20 {
     21     return a + b + bar_external(0);
     22 }
     23 
     24 int foo_get_counter(void)
     25 {
     26     return foo_counter;
     27 }
     28 
     29 __attribute__((visibility("hidden")))
     30 int foo_hidden(int x)
     31 {
     32     return x * 2;
     33 }