kit

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

jumptable.c (888B)


      1 /* A dense switch lowered to a jump table — the .rodata table is a vector of
      2  * absolute target addresses (R_ABS64 against the function). codegen renders it
      3  * as raw bytes with relocations; the symbolizer must emit `.quad f+off` so
      4  * cc -S | as reproduces those data relocations (L1) and the linked table
      5  * actually dispatches (L2). The register-indirect `br` plus the adrp/add table
      6  * base also exercise the .Lkit_jt.0 local-symbol reference. Exit: case 7. */
      7 int sel(int x) {
      8   switch (x) {
      9     case 0:
     10       return 10;
     11     case 1:
     12       return 11;
     13     case 2:
     14       return 12;
     15     case 3:
     16       return 13;
     17     case 4:
     18       return 14;
     19     case 5:
     20       return 15;
     21     case 6:
     22       return 16;
     23     case 7:
     24       return 42;
     25     case 8:
     26       return 18;
     27     case 9:
     28       return 19;
     29     default:
     30       return 99;
     31   }
     32 }
     33 int test_main(void) {
     34   volatile int x = 7;
     35   return sel(x);
     36 }