kit

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

a.c (752B)


      1 /* __start_<X> / __stop_<X> retention. Items live in section "custom";
      2  * the test sums them by walking [__start_custom, __stop_custom). The
      3  * linker must (a) synthesize the boundary symbols at the section span,
      4  * (b) keep the section alive under --gc-sections because of those refs. */
      5 
      6 /* No `retain` here: GC retention must come from __start_/__stop_,
      7  * not SHF_GNU_RETAIN. `used` only stops clang from dropping the
      8  * symbol pre-link. */
      9 __attribute__((section("custom"), used)) int item_a = 1;
     10 __attribute__((section("custom"), used)) int item_b = 2;
     11 
     12 extern int __start_custom[];
     13 extern int __stop_custom[];
     14 
     15 int test_main(void) {
     16   int sum = 0;
     17   for (int* p = __start_custom; p != __stop_custom; ++p) sum += *p;
     18   return sum == 3 ? 0 : 1;
     19 }