1 #include <stdint.h> 2 #include <stdbool.h> 3 4 void preserce_ptr_sz_fn(long x) {} 5 6 #define __bpf_aligned __attribute__((aligned(8))) 7 8 /* 9 * KERNEL 10 */ 11 12 struct core_reloc_kernel_output { 13 int valid[10]; 14 char comm[sizeof("test_progs")]; 15 int comm_len; 16 bool local_task_struct_matches; 17 }; 18 19 /* 20 * MODULE 21 */ 22 23 struct core_reloc_module_output { 24 long long len; 25 long long off; 26 int read_ctx_sz; 27 bool read_ctx_exists; 28 bool buf_exists; 29 bool len_exists; 30 bool off_exists; 31 /* we have test_progs[-flavor], so cut flavor part */ 32 char comm[sizeof("test_progs")]; 33 int comm_len; 34 }; 35 36 /* 37 * FLAVORS 38 */ 39 struct core_reloc_flavors { 40 int a; 41 int b; 42 int c; 43 }; 44 45 /* this is not a flavor, as it doesn't have triple underscore */ 46 struct core_reloc_flavors__err_wrong_name { 47 int a; 48 int b; 49 int c; 50 }; 51 52 /* 53 * NESTING 54 */ 55 /* original set up, used to record relocations in BPF program */ 56 struct core_reloc_nesting_substruct { 57 int a; 58 }; 59 60 union core_reloc_nesting_subunion { 61 int b; 62 }; 63 64 struct core_reloc_nesting { 65 union { 66 struct core_reloc_nesting_substruct a; 67 } a; 68 struct { 69 union core_reloc_nesting_subunion b; 70 } b; 71 }; 72 73 /* inlined anonymous struct/union instead of named structs in original */ 74 struct core_reloc_nesting___anon_embed { 75 int __just_for_padding; 76 union { 77 struct { 78 int a; 79 } a; 80 } a; 81 struct { 82 union { 83 int b; 84 } b; 85 } b; 86 }; 87 88 /* different mix of nested structs/unions than in original */ 89 struct core_reloc_nesting___struct_union_mixup { 90 int __a; 91 struct { 92 int __a; 93 union { 94 char __a; 95 int a; 96 } a; 97 } a; 98 int __b; 99 union { 100 int __b; 101 union { 102 char __b; 103 int b; 104 } b; 105 } b; 106 }; 107 108 /* extra anon structs/unions, but still valid a.a.a and b.b.b accessors */ 109 struct core_reloc_nesting___extra_nesting { 110 int __padding; 111 struct { 112 struct { 113 struct { 114 struct { 115 union { 116 int a; 117 } a; 118 }; 119 }; 120 } a; 121 int __some_more; 122 struct { 123 union { 124 union { 125 union { 126 struct { 127 int b; 128 }; 129 } b; 130 }; 131 } b; 132 }; 133 }; 134 }; 135 136 /* three flavors of same struct with different structure but same layout for 137 * a.a.a and b.b.b, thus successfully resolved and relocatable */ 138 struct core_reloc_nesting___dup_compat_types { 139 char __just_for_padding; 140 /* 3 more bytes of padding */ 141 struct { 142 struct { 143 int a; /* offset 4 */ 144 } a; 145 } a; 146 long long __more_padding; 147 struct { 148 struct { 149 int b; /* offset 16 */ 150 } b; 151 } b; 152 }; 153 154 struct core_reloc_nesting___dup_compat_types__2 { 155 int __aligned_padding; 156 struct { 157 int __trickier_noop[0]; 158 struct { 159 char __some_more_noops[0]; 160 int a; /* offset 4 */ 161 } a; 162 } a; 163 int __more_padding; 164 struct { 165 struct { 166 struct { 167 int __critical_padding; 168 int b; /* offset 16 */ 169 } b; 170 int __does_not_matter; 171 }; 172 } b; 173 int __more_irrelevant_stuff; 174 }; 175 176 struct core_reloc_nesting___dup_compat_types__3 { 177 char __correct_padding[4]; 178 struct { 179 struct { 180 int a; /* offset 4 */ 181 } a; 182 } a; 183 /* 8 byte padding due to next struct's alignment */ 184 struct { 185 struct { 186 int b; 187 } b; 188 } b __attribute__((aligned(16))); 189 }; 190 191 /* b.b.b field is missing */ 192 struct core_reloc_nesting___err_missing_field { 193 struct { 194 struct { 195 int a; 196 } a; 197 } a; 198 struct { 199 struct { 200 int x; 201 } b; 202 } b; 203 }; 204 205 /* b.b.b field is an array of integers instead of plain int */ 206 struct core_reloc_nesting___err_array_field { 207 struct { 208 struct { 209 int a; 210 } a; 211 } a; 212 struct { 213 struct { 214 int b[1]; 215 } b; 216 } b; 217 }; 218 219 /* middle b container is missing */ 220 struct core_reloc_nesting___err_missing_container { 221 struct { 222 struct { 223 int a; 224 } a; 225 } a; 226 struct { 227 int x; 228 } b; 229 }; 230 231 /* middle b container is referenced through pointer instead of being embedded */ 232 struct core_reloc_nesting___err_nonstruct_container { 233 struct { 234 struct { 235 int a; 236 } a; 237 } a; 238 struct { 239 struct { 240 int b; 241 } *b; 242 } b; 243 }; 244 245 /* middle b container is an array of structs instead of plain struct */ 246 struct core_reloc_nesting___err_array_container { 247 struct { 248 struct { 249 int a; 250 } a; 251 } a; 252 struct { 253 struct { 254 int b; 255 } b[1]; 256 } b; 257 }; 258 259 /* two flavors of same struct with incompatible layout for b.b.b */ 260 struct core_reloc_nesting___err_dup_incompat_types__1 { 261 struct { 262 struct { 263 int a; /* offset 0 */ 264 } a; 265 } a; 266 struct { 267 struct { 268 int b; /* offset 4 */ 269 } b; 270 } b; 271 }; 272 273 struct core_reloc_nesting___err_dup_incompat_types__2 { 274 struct { 275 struct { 276 int a; /* offset 0 */ 277 } a; 278 } a; 279 int __extra_padding; 280 struct { 281 struct { 282 int b; /* offset 8 (!) */ 283 } b; 284 } b; 285 }; 286 287 /* two flavors of same struct having one of a.a.a and b.b.b, but not both */ 288 struct core_reloc_nesting___err_partial_match_dups__a { 289 struct { 290 struct { 291 int a; 292 } a; 293 } a; 294 }; 295 296 struct core_reloc_nesting___err_partial_match_dups__b { 297 struct { 298 struct { 299 int b; 300 } b; 301 } b; 302 }; 303 304 struct core_reloc_nesting___err_too_deep { 305 struct { 306 struct { 307 int a; 308 } a; 309 } a; 310 /* 65 levels of nestedness for b.b.b */ 311 struct { 312 struct { 313 struct { struct { struct { struct { struct { 314 struct { struct { struct { struct { struct { 315 struct { struct { struct { struct { struct { 316 struct { struct { struct { struct { struct { 317 struct { struct { struct { struct { struct { 318 struct { struct { struct { struct { struct { 319 struct { struct { struct { struct { struct { 320 struct { struct { struct { struct { struct { 321 struct { struct { struct { struct { struct { 322 struct { struct { struct { struct { struct { 323 struct { struct { struct { struct { struct { 324 struct { struct { struct { struct { struct { 325 /* this one is one too much */ 326 struct { 327 int b; 328 }; 329 }; }; }; }; }; 330 }; }; }; }; }; 331 }; }; }; }; }; 332 }; }; }; }; }; 333 }; }; }; }; }; 334 }; }; }; }; }; 335 }; }; }; }; }; 336 }; }; }; }; }; 337 }; }; }; }; }; 338 }; }; }; }; }; 339 }; }; }; }; }; 340 }; }; }; }; }; 341 } b; 342 } b; 343 }; 344 345 /* 346 * ARRAYS 347 */ 348 struct core_reloc_arrays_output { 349 int a2; 350 char b123; 351 int c1c; 352 int d00d; 353 int f10c; 354 }; 355 356 struct core_reloc_arrays_substruct { 357 int c; 358 int d; 359 }; 360 361 struct core_reloc_arrays { 362 int a[5]; 363 char b[2][3][4]; 364 struct core_reloc_arrays_substruct c[3]; 365 struct core_reloc_arrays_substruct d[1][2]; 366 struct core_reloc_arrays_substruct f[][2]; 367 }; 368 369 /* bigger array dimensions */ 370 struct core_reloc_arrays___diff_arr_dim { 371 int a[7]; 372 char b[3][4][5]; 373 struct core_reloc_arrays_substruct c[4]; 374 struct core_reloc_arrays_substruct d[2][3]; 375 struct core_reloc_arrays_substruct f[1][3]; 376 }; 377 378 /* different size of array's value (struct) */ 379 struct core_reloc_arrays___diff_arr_val_sz { 380 int a[5]; 381 char b[2][3][4]; 382 struct { 383 int __padding1; 384 int c; 385 int __padding2; 386 } c[3]; 387 struct { 388 int __padding1; 389 int d; 390 int __padding2; 391 } d[1][2]; 392 struct { 393 int __padding1; 394 int c; 395 int __padding2; 396 } f[][2]; 397 }; 398 399 struct core_reloc_arrays___equiv_zero_sz_arr { 400 int a[5]; 401 char b[2][3][4]; 402 struct core_reloc_arrays_substruct c[3]; 403 struct core_reloc_arrays_substruct d[1][2]; 404 /* equivalent to flexible array */ 405 struct core_reloc_arrays_substruct f[][2]; 406 }; 407 408 struct core_reloc_arrays___fixed_arr { 409 int a[5]; 410 char b[2][3][4]; 411 struct core_reloc_arrays_substruct c[3]; 412 struct core_reloc_arrays_substruct d[1][2]; 413 /* not a flexible array anymore, but within access bounds */ 414 struct core_reloc_arrays_substruct f[1][2]; 415 }; 416 417 struct core_reloc_arrays___err_too_small { 418 int a[2]; /* this one is too small */ 419 char b[2][3][4]; 420 struct core_reloc_arrays_substruct c[3]; 421 struct core_reloc_arrays_substruct d[1][2]; 422 struct core_reloc_arrays_substruct f[][2]; 423 }; 424 425 struct core_reloc_arrays___err_too_shallow { 426 int a[5]; 427 char b[2][3]; /* this one lacks one dimension */ 428 struct core_reloc_arrays_substruct c[3]; 429 struct core_reloc_arrays_substruct d[1][2]; 430 struct core_reloc_arrays_substruct f[][2]; 431 }; 432 433 struct core_reloc_arrays___err_non_array { 434 int a; /* not an array */ 435 char b[2][3][4]; 436 struct core_reloc_arrays_substruct c[3]; 437 struct core_reloc_arrays_substruct d[1][2]; 438 struct core_reloc_arrays_substruct f[][2]; 439 }; 440 441 struct core_reloc_arrays___err_wrong_val_type { 442 int a[5]; 443 char b[2][3][4]; 444 int c[3]; /* value is not a struct */ 445 struct core_reloc_arrays_substruct d[1][2]; 446 struct core_reloc_arrays_substruct f[][2]; 447 }; 448 449 struct core_reloc_arrays___err_bad_zero_sz_arr { 450 /* zero-sized array, but not at the end */ 451 struct core_reloc_arrays_substruct f[0][2]; 452 int a[5]; 453 char b[2][3][4]; 454 struct core_reloc_arrays_substruct c[3]; 455 struct core_reloc_arrays_substruct d[1][2]; 456 }; 457 458 /* 459 * PRIMITIVES 460 */ 461 enum core_reloc_primitives_enum { 462 A = 0, 463 B = 1, 464 }; 465 466 struct core_reloc_primitives { 467 char a; 468 int b; 469 enum core_reloc_primitives_enum c; 470 void *d __bpf_aligned; 471 int (*f)(const char *) __bpf_aligned; 472 }; 473 474 struct core_reloc_primitives___diff_enum_def { 475 char a; 476 int b; 477 void *d __bpf_aligned; 478 int (*f)(const char *) __bpf_aligned; 479 enum { 480 X = 100, 481 Y = 200, 482 } c __bpf_aligned; /* inline enum def with differing set of values */ 483 }; 484 485 struct core_reloc_primitives___diff_func_proto { 486 void (*f)(int) __bpf_aligned; /* incompatible function prototype */ 487 void *d __bpf_aligned; 488 enum core_reloc_primitives_enum c __bpf_aligned; 489 int b; 490 char a; 491 }; 492 493 struct core_reloc_primitives___diff_ptr_type { 494 const char * const d __bpf_aligned; /* different pointee type + modifiers */ 495 char a __bpf_aligned; 496 int b; 497 enum core_reloc_primitives_enum c; 498 int (*f)(const char *) __bpf_aligned; 499 }; 500 501 struct core_reloc_primitives___err_non_enum { 502 char a[1]; 503 int b; 504 int c; /* int instead of enum */ 505 void *d __bpf_aligned; 506 int (*f)(const char *) __bpf_aligned; 507 }; 508 509 struct core_reloc_primitives___err_non_int { 510 char a[1]; 511 int *b __bpf_aligned; /* ptr instead of int */ 512 enum core_reloc_primitives_enum c __bpf_aligned; 513 void *d __bpf_aligned; 514 int (*f)(const char *) __bpf_aligned; 515 }; 516 517 struct core_reloc_primitives___err_non_ptr { 518 char a[1]; 519 int b; 520 enum core_reloc_primitives_enum c; 521 int d; /* int instead of ptr */ 522 int (*f)(const char *) __bpf_aligned; 523 }; 524 525 /* 526 * MODS 527 */ 528 struct core_reloc_mods_output { 529 int a, b, c, d, e, f, g, h; 530 }; 531 532 typedef const int int_t; 533 typedef const char *char_ptr_t __bpf_aligned; 534 typedef const int arr_t[7]; 535 536 struct core_reloc_mods_substruct { 537 int x; 538 int y; 539 }; 540 541 typedef struct { 542 int x; 543 int y; 544 } core_reloc_mods_substruct_t; 545 546 struct core_reloc_mods { 547 int a; 548 int_t b; 549 char *c __bpf_aligned; 550 char_ptr_t d; 551 int e[3] __bpf_aligned; 552 arr_t f; 553 struct core_reloc_mods_substruct g; 554 core_reloc_mods_substruct_t h; 555 }; 556 557 /* a/b, c/d, e/f, and g/h pairs are swapped */ 558 struct core_reloc_mods___mod_swap { 559 int b; 560 int_t a; 561 char *d __bpf_aligned; 562 char_ptr_t c; 563 int f[3] __bpf_aligned; 564 arr_t e; 565 struct { 566 int y; 567 int x; 568 } h; 569 core_reloc_mods_substruct_t g; 570 }; 571 572 typedef int int1_t; 573 typedef int1_t int2_t; 574 typedef int2_t int3_t; 575 576 typedef int arr1_t[5]; 577 typedef arr1_t arr2_t; 578 typedef arr2_t arr3_t; 579 typedef arr3_t arr4_t; 580 581 typedef const char * const volatile fancy_char_ptr_t __bpf_aligned; 582 583 typedef core_reloc_mods_substruct_t core_reloc_mods_substruct_tt; 584 585 /* we need more typedefs */ 586 struct core_reloc_mods___typedefs { 587 core_reloc_mods_substruct_tt g; 588 core_reloc_mods_substruct_tt h; 589 arr4_t f; 590 arr4_t e; 591 fancy_char_ptr_t d; 592 fancy_char_ptr_t c; 593 int3_t b __bpf_aligned; 594 int3_t a; 595 }; 596 597 /* 598 * PTR_AS_ARR 599 */ 600 struct core_reloc_ptr_as_arr { 601 int a; 602 }; 603 604 struct core_reloc_ptr_as_arr___diff_sz { 605 int :32; /* padding */ 606 char __some_more_padding; 607 int a; 608 }; 609 610 /* 611 * INTS 612 */ 613 struct core_reloc_ints { 614 uint8_t u8_field; 615 int8_t s8_field; 616 uint16_t u16_field; 617 int16_t s16_field; 618 uint32_t u32_field; 619 int32_t s32_field; 620 uint64_t u64_field; 621 int64_t s64_field; 622 }; 623 624 /* signed/unsigned types swap */ 625 struct core_reloc_ints___reverse_sign { 626 int8_t u8_field; 627 uint8_t s8_field; 628 int16_t u16_field; 629 uint16_t s16_field; 630 int32_t u32_field; 631 uint32_t s32_field; 632 int64_t u64_field; 633 uint64_t s64_field; 634 }; 635 636 struct core_reloc_ints___bool { 637 bool u8_field; /* bool instead of uint8 */ 638 int8_t s8_field; 639 uint16_t u16_field; 640 int16_t s16_field; 641 uint32_t u32_field; 642 int32_t s32_field; 643 uint64_t u64_field; 644 int64_t s64_field; 645 }; 646 647 /* 648 * MISC 649 */ 650 struct core_reloc_misc_output { 651 int a, b, c; 652 }; 653 654 struct core_reloc_misc___a { 655 int a1; 656 int a2; 657 }; 658 659 struct core_reloc_misc___b { 660 int b1; 661 int b2; 662 }; 663 664 /* this one extends core_reloc_misc_extensible struct from BPF prog */ 665 struct core_reloc_misc_extensible { 666 int a; 667 int b; 668 int c; 669 int d; 670 }; 671 672 /* 673 * FIELD EXISTENCE 674 */ 675 struct core_reloc_existence_output { 676 int a_exists; 677 int a_value; 678 int b_exists; 679 int b_value; 680 int c_exists; 681 int c_value; 682 int arr_exists; 683 int arr_value; 684 int s_exists; 685 int s_value; 686 }; 687 688 struct core_reloc_existence { 689 int a; 690 struct { 691 int b; 692 }; 693 int c; 694 int arr[1]; 695 struct { 696 int x; 697 } s; 698 }; 699 700 struct core_reloc_existence___minimal { 701 int a; 702 }; 703 704 struct core_reloc_existence___wrong_field_defs { 705 void *a; 706 int b[1]; 707 struct{ int x; } c; 708 int arr; 709 int s; 710 }; 711 712 /* 713 * BITFIELDS 714 */ 715 /* bitfield read results, all as plain integers */ 716 struct core_reloc_bitfields_output { 717 int64_t ub1; 718 int64_t ub2; 719 int64_t ub7; 720 int64_t sb4; 721 int64_t sb20; 722 int64_t u32; 723 int64_t s32; 724 }; 725 726 struct core_reloc_bitfields { 727 /* unsigned bitfields */ 728 uint8_t ub1: 1; 729 uint8_t ub2: 2; 730 uint32_t ub7: 7; 731 /* signed bitfields */ 732 int8_t sb4: 4; 733 int32_t sb20: 20; 734 /* non-bitfields */ 735 uint32_t u32; 736 int32_t s32; 737 }; 738 739 /* different bit sizes (both up and down) */ 740 struct core_reloc_bitfields___bit_sz_change { 741 /* unsigned bitfields */ 742 uint16_t ub1: 3; /* 1 -> 3 */ 743 uint32_t ub2: 20; /* 2 -> 20 */ 744 uint8_t ub7: 1; /* 7 -> 1 */ 745 /* signed bitfields */ 746 int8_t sb4: 1; /* 4 -> 1 */ 747 int32_t sb20: 30; /* 20 -> 30 */ 748 /* non-bitfields */ 749 uint16_t u32; /* 32 -> 16 */ 750 int64_t s32 __bpf_aligned; /* 32 -> 64 */ 751 }; 752 753 /* turn bitfield into non-bitfield and vice versa */ 754 struct core_reloc_bitfields___bitfield_vs_int { 755 uint64_t ub1; /* 3 -> 64 non-bitfield */ 756 uint8_t ub2; /* 20 -> 8 non-bitfield */ 757 int64_t ub7 __bpf_aligned; /* 7 -> 64 non-bitfield signed */ 758 int64_t sb4 __bpf_aligned; /* 4 -> 64 non-bitfield signed */ 759 uint64_t sb20 __bpf_aligned; /* 20 -> 16 non-bitfield unsigned */ 760 int32_t u32: 20; /* 32 non-bitfield -> 20 bitfield */ 761 uint64_t s32: 60 __bpf_aligned; /* 32 non-bitfield -> 60 bitfield */ 762 }; 763 764 struct core_reloc_bitfields___just_big_enough { 765 uint64_t ub1: 4; 766 uint64_t ub2: 60; /* packed tightly */ 767 uint32_t ub7; 768 uint32_t sb4; 769 uint32_t sb20; 770 uint32_t u32; 771 uint32_t s32; 772 } __attribute__((packed)) ; 773 774 struct core_reloc_bitfields___err_too_big_bitfield { 775 uint64_t ub1: 4; 776 uint64_t ub2: 61; /* packed tightly */ 777 uint32_t ub7; 778 uint32_t sb4; 779 uint32_t sb20; 780 uint32_t u32; 781 uint32_t s32; 782 } __attribute__((packed)) ; 783 784 /* 785 * SIZE 786 */ 787 struct core_reloc_size_output { 788 int int_sz; 789 int int_off; 790 int struct_sz; 791 int struct_off; 792 int union_sz; 793 int union_off; 794 int arr_sz; 795 int arr_off; 796 int arr_elem_sz; 797 int arr_elem_off; 798 int ptr_sz; 799 int ptr_off; 800 int enum_sz; 801 int enum_off; 802 int float_sz; 803 int float_off; 804 }; 805 806 struct core_reloc_size { 807 int int_field; 808 struct { int x; } struct_field; 809 union { int x; } union_field; 810 int arr_field[4]; 811 void *ptr_field; 812 enum { VALUE = 123 } enum_field; 813 float float_field; 814 }; 815 816 struct core_reloc_size___diff_sz { 817 uint64_t int_field; 818 struct { int x; int y; int z; } struct_field; 819 union { int x; char bla[123]; } union_field; 820 char arr_field[10]; 821 void *ptr_field; 822 enum { OTHER_VALUE = 0xFFFFFFFFFFFFFFFF } enum_field; 823 double float_field; 824 }; 825 826 struct core_reloc_size___diff_offs { 827 float float_field; 828 enum { YET_OTHER_VALUE = 123 } enum_field; 829 void *ptr_field; 830 int arr_field[4]; 831 union { int x; } union_field; 832 struct { int x; } struct_field; 833 int int_field; 834 }; 835 836 /* Error case of two candidates with the fields (int_field) at the same 837 * offset, but with differing final relocation values: size 4 vs size 1 838 */ 839 struct core_reloc_size___err_ambiguous1 { 840 /* int at offset 0 */ 841 int int_field; 842 843 struct { int x; } struct_field; 844 union { int x; } union_field; 845 int arr_field[4]; 846 void *ptr_field; 847 enum { VALUE___1 = 123 } enum_field; 848 float float_field; 849 }; 850 851 struct core_reloc_size___err_ambiguous2 { 852 /* char at offset 0 */ 853 char int_field; 854 855 struct { int x; } struct_field; 856 union { int x; } union_field; 857 int arr_field[4]; 858 void *ptr_field; 859 enum { VALUE___2 = 123 } enum_field; 860 float float_field; 861 }; 862 863 /* 864 * TYPE EXISTENCE, MATCH & SIZE 865 */ 866 struct core_reloc_type_based_output { 867 bool struct_exists; 868 bool complex_struct_exists; 869 bool union_exists; 870 bool enum_exists; 871 bool typedef_named_struct_exists; 872 bool typedef_anon_struct_exists; 873 bool typedef_struct_ptr_exists; 874 bool typedef_int_exists; 875 bool typedef_enum_exists; 876 bool typedef_void_ptr_exists; 877 bool typedef_func_proto_exists; 878 bool typedef_arr_exists; 879 880 bool struct_matches; 881 bool complex_struct_matches; 882 bool union_matches; 883 bool enum_matches; 884 bool typedef_named_struct_matches; 885 bool typedef_anon_struct_matches; 886 bool typedef_struct_ptr_matches; 887 bool typedef_int_matches; 888 bool typedef_enum_matches; 889 bool typedef_void_ptr_matches; 890 bool typedef_func_proto_matches; 891 bool typedef_arr_matches; 892 893 int struct_sz; 894 int union_sz; 895 int enum_sz; 896 int typedef_named_struct_sz; 897 int typedef_anon_struct_sz; 898 int typedef_struct_ptr_sz; 899 int typedef_int_sz; 900 int typedef_enum_sz; 901 int typedef_void_ptr_sz; 902 int typedef_func_proto_sz; 903 int typedef_arr_sz; 904 }; 905 906 struct a_struct { 907 int x; 908 }; 909 910 struct a_complex_struct { 911 union { 912 struct a_struct * restrict a; 913 void *b; 914 } x; 915 volatile long y; 916 }; 917 918 union a_union { 919 int y; 920 int z; 921 }; 922 923 typedef struct a_struct named_struct_typedef; 924 925 typedef struct { int x, y, z; } anon_struct_typedef; 926 927 typedef struct { 928 int a, b, c; 929 } *struct_ptr_typedef; 930 931 enum an_enum { 932 AN_ENUM_VAL1 = 1, 933 AN_ENUM_VAL2 = 2, 934 AN_ENUM_VAL3 = 3, 935 }; 936 937 typedef int int_typedef; 938 939 typedef enum { TYPEDEF_ENUM_VAL1, TYPEDEF_ENUM_VAL2 } enum_typedef; 940 941 typedef void *void_ptr_typedef; 942 943 typedef int (*func_proto_typedef)(long); 944 945 typedef char arr_typedef[20]; 946 947 struct core_reloc_type_based { 948 struct a_struct f1; 949 struct a_complex_struct f2; 950 union a_union f3; 951 enum an_enum f4; 952 named_struct_typedef f5; 953 anon_struct_typedef f6; 954 struct_ptr_typedef f7; 955 int_typedef f8; 956 enum_typedef f9; 957 void_ptr_typedef f10; 958 func_proto_typedef f11; 959 arr_typedef f12; 960 }; 961 962 /* no types in target */ 963 struct core_reloc_type_based___all_missing { 964 }; 965 966 /* different member orders, enum variant values, signedness, etc */ 967 struct a_struct___diff { 968 int x; 969 int a; 970 }; 971 972 struct a_struct___forward; 973 974 struct a_complex_struct___diff { 975 union { 976 struct a_struct___forward *a; 977 void *b; 978 } x; 979 volatile long y; 980 }; 981 982 union a_union___diff { 983 int z; 984 int y; 985 }; 986 987 typedef struct a_struct___diff named_struct_typedef___diff; 988 989 typedef struct { int z, x, y; } anon_struct_typedef___diff; 990 991 typedef struct { 992 int c; 993 int b; 994 int a; 995 } *struct_ptr_typedef___diff; 996 997 enum an_enum___diff { 998 AN_ENUM_VAL2___diff = 0, 999 AN_ENUM_VAL1___diff = 42, 1000 AN_ENUM_VAL3___diff = 1, 1001 }; 1002 1003 typedef unsigned int int_typedef___diff; 1004 1005 typedef enum { TYPEDEF_ENUM_VAL2___diff, TYPEDEF_ENUM_VAL1___diff = 50 } enum_typedef___diff; 1006 1007 typedef const void *void_ptr_typedef___diff; 1008 1009 typedef int_typedef___diff (*func_proto_typedef___diff)(long); 1010 1011 typedef char arr_typedef___diff[3]; 1012 1013 struct core_reloc_type_based___diff { 1014 struct a_struct___diff f1; 1015 struct a_complex_struct___diff f2; 1016 union a_union___diff f3; 1017 enum an_enum___diff f4; 1018 named_struct_typedef___diff f5; 1019 anon_struct_typedef___diff f6; 1020 struct_ptr_typedef___diff f7; 1021 int_typedef___diff f8; 1022 enum_typedef___diff f9; 1023 void_ptr_typedef___diff f10; 1024 func_proto_typedef___diff f11; 1025 arr_typedef___diff f12; 1026 }; 1027 1028 /* different type sizes, extra modifiers, anon vs named enums, etc */ 1029 struct a_struct___diff_sz { 1030 long x; 1031 int y; 1032 char z; 1033 }; 1034 1035 union a_union___diff_sz { 1036 char yy; 1037 char zz; 1038 }; 1039 1040 typedef struct a_struct___diff_sz named_struct_typedef___diff_sz; 1041 1042 typedef struct { long xx, yy, zzz; } anon_struct_typedef___diff_sz; 1043 1044 typedef struct { 1045 char aa[1], bb[2], cc[3]; 1046 } *struct_ptr_typedef___diff_sz; 1047 1048 enum an_enum___diff_sz { 1049 AN_ENUM_VAL1___diff_sz = 0x123412341234, 1050 AN_ENUM_VAL2___diff_sz = 2, 1051 }; 1052 1053 typedef unsigned long int_typedef___diff_sz; 1054 1055 typedef enum an_enum___diff_sz enum_typedef___diff_sz; 1056 1057 typedef const void * const void_ptr_typedef___diff_sz; 1058 1059 typedef int_typedef___diff_sz (*func_proto_typedef___diff_sz)(char); 1060 1061 typedef int arr_typedef___diff_sz[2]; 1062 1063 struct core_reloc_type_based___diff_sz { 1064 struct a_struct___diff_sz f1; 1065 union a_union___diff_sz f2; 1066 enum an_enum___diff_sz f3; 1067 named_struct_typedef___diff_sz f4; 1068 anon_struct_typedef___diff_sz f5; 1069 struct_ptr_typedef___diff_sz f6; 1070 int_typedef___diff_sz f7; 1071 enum_typedef___diff_sz f8; 1072 void_ptr_typedef___diff_sz f9; 1073 func_proto_typedef___diff_sz f10; 1074 arr_typedef___diff_sz f11; 1075 }; 1076 1077 /* incompatibilities between target and local types */ 1078 union a_struct___incompat { /* union instead of struct */ 1079 int x; 1080 }; 1081 1082 struct a_union___incompat { /* struct instead of union */ 1083 int y; 1084 int z; 1085 }; 1086 1087 /* typedef to union, not to struct */ 1088 typedef union a_struct___incompat named_struct_typedef___incompat; 1089 1090 /* typedef to void pointer, instead of struct */ 1091 typedef void *anon_struct_typedef___incompat; 1092 1093 /* extra pointer indirection */ 1094 typedef struct { 1095 int a, b, c; 1096 } **struct_ptr_typedef___incompat; 1097 1098 /* typedef of a struct with int, instead of int */ 1099 typedef struct { int x; } int_typedef___incompat; 1100 1101 /* typedef to func_proto, instead of enum */ 1102 typedef int (*enum_typedef___incompat)(void); 1103 1104 /* pointer to char instead of void */ 1105 typedef char *void_ptr_typedef___incompat; 1106 1107 /* void return type instead of int */ 1108 typedef void (*func_proto_typedef___incompat)(long); 1109 1110 /* multi-dimensional array instead of a single-dimensional */ 1111 typedef int arr_typedef___incompat[20][2]; 1112 1113 struct core_reloc_type_based___incompat { 1114 union a_struct___incompat f1; 1115 struct a_union___incompat f2; 1116 /* the only valid one is enum, to check that something still succeeds */ 1117 enum an_enum f3; 1118 named_struct_typedef___incompat f4; 1119 anon_struct_typedef___incompat f5; 1120 struct_ptr_typedef___incompat f6; 1121 int_typedef___incompat f7; 1122 enum_typedef___incompat f8; 1123 void_ptr_typedef___incompat f9; 1124 func_proto_typedef___incompat f10; 1125 arr_typedef___incompat f11; 1126 }; 1127 1128 /* func_proto with incompatible signature */ 1129 typedef void (*func_proto_typedef___fn_wrong_ret1)(long); 1130 typedef int * (*func_proto_typedef___fn_wrong_ret2)(long); 1131 typedef struct { int x; } int_struct_typedef; 1132 typedef int_struct_typedef (*func_proto_typedef___fn_wrong_ret3)(long); 1133 typedef int (*func_proto_typedef___fn_wrong_arg)(void *); 1134 typedef int (*func_proto_typedef___fn_wrong_arg_cnt1)(long, long); 1135 typedef int (*func_proto_typedef___fn_wrong_arg_cnt2)(void); 1136 1137 struct core_reloc_type_based___fn_wrong_args { 1138 /* one valid type to make sure relos still work */ 1139 struct a_struct f1; 1140 func_proto_typedef___fn_wrong_ret1 f2; 1141 func_proto_typedef___fn_wrong_ret2 f3; 1142 func_proto_typedef___fn_wrong_ret3 f4; 1143 func_proto_typedef___fn_wrong_arg f5; 1144 func_proto_typedef___fn_wrong_arg_cnt1 f6; 1145 func_proto_typedef___fn_wrong_arg_cnt2 f7; 1146 }; 1147 1148 /* 1149 * TYPE ID MAPPING (LOCAL AND TARGET) 1150 */ 1151 struct core_reloc_type_id_output { 1152 int local_anon_struct; 1153 int local_anon_union; 1154 int local_anon_enum; 1155 int local_anon_func_proto_ptr; 1156 int local_anon_void_ptr; 1157 int local_anon_arr; 1158 1159 int local_struct; 1160 int local_union; 1161 int local_enum; 1162 int local_int; 1163 int local_struct_typedef; 1164 int local_func_proto_typedef; 1165 int local_arr_typedef; 1166 1167 int targ_struct; 1168 int targ_union; 1169 int targ_enum; 1170 int targ_int; 1171 int targ_struct_typedef; 1172 int targ_func_proto_typedef; 1173 int targ_arr_typedef; 1174 }; 1175 1176 struct core_reloc_type_id { 1177 struct a_struct f1; 1178 union a_union f2; 1179 enum an_enum f3; 1180 named_struct_typedef f4; 1181 func_proto_typedef f5; 1182 arr_typedef f6; 1183 }; 1184 1185 struct core_reloc_type_id___missing_targets { 1186 /* nothing */ 1187 }; 1188 1189 /* 1190 * ENUMERATOR VALUE EXISTENCE AND VALUE RELOCATION 1191 */ 1192 struct core_reloc_enumval_output { 1193 bool named_val1_exists; 1194 bool named_val2_exists; 1195 bool named_val3_exists; 1196 bool anon_val1_exists; 1197 bool anon_val2_exists; 1198 bool anon_val3_exists; 1199 1200 int named_val1; 1201 int named_val2; 1202 int anon_val1; 1203 int anon_val2; 1204 }; 1205 1206 struct core_reloc_enum64val_output { 1207 bool unsigned_val1_exists; 1208 bool unsigned_val2_exists; 1209 bool unsigned_val3_exists; 1210 bool signed_val1_exists; 1211 bool signed_val2_exists; 1212 bool signed_val3_exists; 1213 1214 long unsigned_val1; 1215 long unsigned_val2; 1216 long signed_val1; 1217 long signed_val2; 1218 }; 1219 1220 enum named_enum { 1221 NAMED_ENUM_VAL1 = 1, 1222 NAMED_ENUM_VAL2 = 2, 1223 NAMED_ENUM_VAL3 = 3, 1224 }; 1225 1226 typedef enum { 1227 ANON_ENUM_VAL1 = 0x10, 1228 ANON_ENUM_VAL2 = 0x20, 1229 ANON_ENUM_VAL3 = 0x30, 1230 } anon_enum; 1231 1232 struct core_reloc_enumval { 1233 enum named_enum f1; 1234 anon_enum f2; 1235 }; 1236 1237 enum named_unsigned_enum64 { 1238 UNSIGNED_ENUM64_VAL1 = 0x1ffffffffULL, 1239 UNSIGNED_ENUM64_VAL2 = 0x2, 1240 UNSIGNED_ENUM64_VAL3 = 0x3ffffffffULL, 1241 }; 1242 1243 enum named_signed_enum64 { 1244 SIGNED_ENUM64_VAL1 = 0x1ffffffffLL, 1245 SIGNED_ENUM64_VAL2 = -2, 1246 SIGNED_ENUM64_VAL3 = 0x3ffffffffLL, 1247 }; 1248 1249 struct core_reloc_enum64val { 1250 enum named_unsigned_enum64 f1; 1251 enum named_signed_enum64 f2; 1252 }; 1253 1254 /* differing enumerator values */ 1255 enum named_enum___diff { 1256 NAMED_ENUM_VAL1___diff = 101, 1257 NAMED_ENUM_VAL2___diff = 202, 1258 NAMED_ENUM_VAL3___diff = 303, 1259 }; 1260 1261 typedef enum { 1262 ANON_ENUM_VAL1___diff = 0x11, 1263 ANON_ENUM_VAL2___diff = 0x22, 1264 ANON_ENUM_VAL3___diff = 0x33, 1265 } anon_enum___diff; 1266 1267 struct core_reloc_enumval___diff { 1268 enum named_enum___diff f1; 1269 anon_enum___diff f2; 1270 }; 1271 1272 enum named_unsigned_enum64___diff { 1273 UNSIGNED_ENUM64_VAL1___diff = 0x101ffffffffULL, 1274 UNSIGNED_ENUM64_VAL2___diff = 0x202ffffffffULL, 1275 UNSIGNED_ENUM64_VAL3___diff = 0x303ffffffffULL, 1276 }; 1277 1278 enum named_signed_enum64___diff { 1279 SIGNED_ENUM64_VAL1___diff = -101, 1280 SIGNED_ENUM64_VAL2___diff = -202, 1281 SIGNED_ENUM64_VAL3___diff = -303, 1282 }; 1283 1284 struct core_reloc_enum64val___diff { 1285 enum named_unsigned_enum64___diff f1; 1286 enum named_signed_enum64___diff f2; 1287 }; 1288 1289 /* missing (optional) third enum value */ 1290 enum named_enum___val3_missing { 1291 NAMED_ENUM_VAL1___val3_missing = 111, 1292 NAMED_ENUM_VAL2___val3_missing = 222, 1293 }; 1294 1295 typedef enum { 1296 ANON_ENUM_VAL1___val3_missing = 0x111, 1297 ANON_ENUM_VAL2___val3_missing = 0x222, 1298 } anon_enum___val3_missing; 1299 1300 struct core_reloc_enumval___val3_missing { 1301 enum named_enum___val3_missing f1; 1302 anon_enum___val3_missing f2; 1303 }; 1304 1305 enum named_unsigned_enum64___val3_missing { 1306 UNSIGNED_ENUM64_VAL1___val3_missing = 0x111ffffffffULL, 1307 UNSIGNED_ENUM64_VAL2___val3_missing = 0x222, 1308 }; 1309 1310 enum named_signed_enum64___val3_missing { 1311 SIGNED_ENUM64_VAL1___val3_missing = 0x111ffffffffLL, 1312 SIGNED_ENUM64_VAL2___val3_missing = -222, 1313 }; 1314 1315 struct core_reloc_enum64val___val3_missing { 1316 enum named_unsigned_enum64___val3_missing f1; 1317 enum named_signed_enum64___val3_missing f2; 1318 }; 1319 1320 /* missing (mandatory) second enum value, should fail */ 1321 enum named_enum___err_missing { 1322 NAMED_ENUM_VAL1___err_missing = 1, 1323 NAMED_ENUM_VAL3___err_missing = 3, 1324 }; 1325 1326 typedef enum { 1327 ANON_ENUM_VAL1___err_missing = 0x111, 1328 ANON_ENUM_VAL3___err_missing = 0x222, 1329 } anon_enum___err_missing; 1330 1331 struct core_reloc_enumval___err_missing { 1332 enum named_enum___err_missing f1; 1333 anon_enum___err_missing f2; 1334 }; 1335 1336 enum named_unsigned_enum64___err_missing { 1337 UNSIGNED_ENUM64_VAL1___err_missing = 0x1ffffffffULL, 1338 UNSIGNED_ENUM64_VAL3___err_missing = 0x3ffffffffULL, 1339 }; 1340 1341 enum named_signed_enum64___err_missing { 1342 SIGNED_ENUM64_VAL1___err_missing = 0x1ffffffffLL, 1343 SIGNED_ENUM64_VAL3___err_missing = -3, 1344 }; 1345 1346 struct core_reloc_enum64val___err_missing { 1347 enum named_unsigned_enum64___err_missing f1; 1348 enum named_signed_enum64___err_missing f2; 1349 }; 1350