A C string lacks alignment so use aligned arrays to avoid potential alignment problems. Switch to using sizeof (less 1 for the \0 terminator) rather than a hardcode size constant.
Unified · Split
| @@ -708,17 +708,22 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h · 707 unmodified lines | ||
| 708 | 708 | |
| 709 | 709 | codegen("\ |
| 710 | 710 | \n\ |
| 711 | − skel->%1$s = skel_prep_map_data((void *)\"\\ \n\ | |
| 712 | − ", ident); | |
| 711 | + { \n\ | |
| 712 | + static const char data[] __attribute__((__aligned__(8))) = \"\\\n\ | |
| 713 | + "); | |
| 713 | 714 | mmap_data = bpf_map__initial_value(map, &mmap_size); |
| 714 | 715 | print_hex(mmap_data, mmap_size); |
| 715 | 716 | codegen("\ |
| 716 | 717 | \n\ |
| 717 | − \", %1$zd, %2$zd); \n\ | |
| 718 | − if (!skel->%3$s) \n\ | |
| 719 | − goto cleanup; \n\ | |
| 720 | − skel->maps.%3$s.initial_value = (__u64) (long) skel->%3$s;\n\ | |
| 721 | − ", bpf_map_mmap_sz(map), mmap_size, ident); | |
| 718 | + \"; \n\ | |
| 719 | + \n\ | |
| 720 | + skel->%1$s = skel_prep_map_data((void *)data, %2$zd,\n\ | |
| 721 | + sizeof(data) - 1);\n\ | |
| 722 | + if (!skel->%1$s) \n\ | |
| 723 | + goto cleanup; \n\ | |
| 724 | + skel->maps.%1$s.initial_value = (__u64) (long) skel->%1$s;\n\ | |
| 725 | + } \n\ | |
| 726 | + ", ident, bpf_map_mmap_sz(map)); | |
| 722 | 727 | } |
| 723 | 728 | codegen("\ |
| 724 | 729 | \n\ |
| @@ -733,32 +738,30 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h · 8 unmodified lines | ||
| 733 | 738 | { \n\ |
| 734 | 739 | struct bpf_load_and_run_opts opts = {}; \n\ |
| 735 | 740 | int err; \n\ |
| 736 | − \n\ | |
| 737 | − opts.ctx = (struct bpf_loader_ctx *)skel; \n\ | |
| 738 | − opts.data_sz = %2$d; \n\ | |
| 739 | − opts.data = (void *)\"\\ \n\ | |
| 741 | + static const char opts_data[] __attribute__((__aligned__(8))) = \"\\\n\ | |
| 740 | 742 | ", |
| 741 | − obj_name, opts.data_sz); | |
| 743 | + obj_name); | |
| 742 | 744 | print_hex(opts.data, opts.data_sz); |
| 743 | 745 | codegen("\ |
| 744 | 746 | \n\ |
| 745 | 747 | \"; \n\ |
| 748 | + static const char opts_insn[] __attribute__((__aligned__(8))) = \"\\\n\ | |
| 746 | 749 | "); |
| 747 | − | |
| 748 | − codegen("\ | |
| 749 | − \n\ | |
| 750 | − opts.insns_sz = %d; \n\ | |
| 751 | − opts.insns = (void *)\"\\ \n\ | |
| 752 | − ", | |
| 753 | − opts.insns_sz); | |
| 754 | 750 | print_hex(opts.insns, opts.insns_sz); |
| 755 | 751 | codegen("\ |
| 756 | 752 | \n\ |
| 757 | 753 | \"; \n\ |
| 754 | + \n\ | |
| 755 | + opts.ctx = (struct bpf_loader_ctx *)skel; \n\ | |
| 756 | + opts.data_sz = sizeof(opts_data) - 1; \n\ | |
| 757 | + opts.data = (void *)opts_data; \n\ | |
| 758 | + opts.insns_sz = sizeof(opts_insn) - 1; \n\ | |
| 759 | + opts.insns = (void *)opts_insn; \n\ | |
| 760 | + \n\ | |
| 758 | 761 | err = bpf_load_and_run(&opts); \n\ |
| 759 | 762 | if (err < 0) \n\ |
| 760 | 763 | return err; \n\ |
| 761 | − ", obj_name); | |
| 764 | + "); | |
| 762 | 765 | bpf_object__for_each_map(map, obj) { |
| 763 | 766 | const char *mmap_flags; |
| 764 | 767 | |