kit

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

lib_foo_libc.c (904B)


      1 /* test/link/elf-dso-aa64/lib_foo_libc.c — DSO fixture with a libc dependency.
      2  *
      3  * This is intentionally headerless so the compile step does not need a sysroot:
      4  * the link step supplies libc.so as a DSO input, and the produced shared object
      5  * must carry libc's DT_NEEDED SONAME plus UND dynsym imports for malloc/free.
      6  * The allocation is deliberately large enough to go through libc's syscall-
      7  * backed allocator path on musl.
      8  */
      9 
     10 extern void* malloc(__SIZE_TYPE__ size);
     11 extern void free(void* p);
     12 extern int bar_external(int x);
     13 
     14 int foo_counter = 42;
     15 
     16 int foo_add(int a, int b)
     17 {
     18     char* p = (char*)malloc(256u * 1024u);
     19     int ok;
     20     if (!p)
     21         return -1;
     22     p[0] = 'k';
     23     p[256u * 1024u - 1u] = 't';
     24     ok = (p[0] == 'k' && p[256u * 1024u - 1u] == 't');
     25     free(p);
     26     return a + b + bar_external(0) + (ok ? 0 : -1);
     27 }
     28 
     29 int foo_get_counter(void)
     30 {
     31     return foo_counter;
     32 }