gen.c (98817a84ff1c755c347ac633ff017a623a631fad) | gen.c (0b20933d8cfe2bf6473e9b581b5d1ed9a2117ecc) |
---|---|
1// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2/* Copyright (C) 2019 Facebook */ 3 4#ifndef _GNU_SOURCE 5#define _GNU_SOURCE 6#endif 7#include <ctype.h> 8#include <errno.h> --- 74 unchanged lines hidden (view full) --- 83 else if (str_has_suffix(name, ".bss")) 84 return "bss"; 85 else if (str_has_suffix(name, ".kconfig")) 86 return "kconfig"; 87 else 88 return NULL; 89} 90 | 1// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2/* Copyright (C) 2019 Facebook */ 3 4#ifndef _GNU_SOURCE 5#define _GNU_SOURCE 6#endif 7#include <ctype.h> 8#include <errno.h> --- 74 unchanged lines hidden (view full) --- 83 else if (str_has_suffix(name, ".bss")) 84 return "bss"; 85 else if (str_has_suffix(name, ".kconfig")) 86 return "kconfig"; 87 else 88 return NULL; 89} 90 |
91static void codegen_btf_dump_printf(void *ct, const char *fmt, va_list args) | 91static void codegen_btf_dump_printf(void *ctx, const char *fmt, va_list args) |
92{ 93 vprintf(fmt, args); 94} 95 96static int codegen_datasec_def(struct bpf_object *obj, 97 struct btf *btf, 98 struct btf_dump *d, 99 const struct btf_type *sec, 100 const char *obj_name) 101{ 102 const char *sec_name = btf__name_by_offset(btf, sec->name_off); 103 const struct btf_var_secinfo *sec_var = btf_var_secinfos(sec); 104 int i, err, off = 0, pad_cnt = 0, vlen = btf_vlen(sec); 105 const char *sec_ident; 106 char var_ident[256]; | 92{ 93 vprintf(fmt, args); 94} 95 96static int codegen_datasec_def(struct bpf_object *obj, 97 struct btf *btf, 98 struct btf_dump *d, 99 const struct btf_type *sec, 100 const char *obj_name) 101{ 102 const char *sec_name = btf__name_by_offset(btf, sec->name_off); 103 const struct btf_var_secinfo *sec_var = btf_var_secinfos(sec); 104 int i, err, off = 0, pad_cnt = 0, vlen = btf_vlen(sec); 105 const char *sec_ident; 106 char var_ident[256]; |
107 bool strip_mods = false; |
|
107 | 108 |
108 if (strcmp(sec_name, ".data") == 0) | 109 if (strcmp(sec_name, ".data") == 0) { |
109 sec_ident = "data"; | 110 sec_ident = "data"; |
110 else if (strcmp(sec_name, ".bss") == 0) | 111 } else if (strcmp(sec_name, ".bss") == 0) { |
111 sec_ident = "bss"; | 112 sec_ident = "bss"; |
112 else if (strcmp(sec_name, ".rodata") == 0) | 113 } else if (strcmp(sec_name, ".rodata") == 0) { |
113 sec_ident = "rodata"; | 114 sec_ident = "rodata"; |
114 else if (strcmp(sec_name, ".kconfig") == 0) | 115 strip_mods = true; 116 } else if (strcmp(sec_name, ".kconfig") == 0) { |
115 sec_ident = "kconfig"; | 117 sec_ident = "kconfig"; |
116 else | 118 } else { |
117 return 0; | 119 return 0; |
120 } |
|
118 119 printf(" struct %s__%s {\n", obj_name, sec_ident); 120 for (i = 0; i < vlen; i++, sec_var++) { 121 const struct btf_type *var = btf__type_by_id(btf, sec_var->type); 122 const char *var_name = btf__name_by_offset(btf, var->name_off); 123 DECLARE_LIBBPF_OPTS(btf_dump_emit_type_decl_opts, opts, 124 .field_name = var_ident, 125 .indent_level = 2, | 121 122 printf(" struct %s__%s {\n", obj_name, sec_ident); 123 for (i = 0; i < vlen; i++, sec_var++) { 124 const struct btf_type *var = btf__type_by_id(btf, sec_var->type); 125 const char *var_name = btf__name_by_offset(btf, var->name_off); 126 DECLARE_LIBBPF_OPTS(btf_dump_emit_type_decl_opts, opts, 127 .field_name = var_ident, 128 .indent_level = 2, |
129 .strip_mods = strip_mods, |
|
126 ); 127 int need_off = sec_var->offset, align_off, align; 128 __u32 var_type_id = var->type; | 130 ); 131 int need_off = sec_var->offset, align_off, align; 132 __u32 var_type_id = var->type; |
129 const struct btf_type *t; | |
130 | 133 |
131 t = btf__type_by_id(btf, var_type_id); 132 while (btf_is_mod(t)) { 133 var_type_id = t->type; 134 t = btf__type_by_id(btf, var_type_id); 135 } 136 | |
137 if (off > need_off) { 138 p_err("Something is wrong for %s's variable #%d: need offset %d, already at %d.\n", 139 sec_name, i, need_off, off); 140 return -EINVAL; 141 } 142 143 align = btf__align_of(btf, var->type); 144 if (align <= 0) { --- 465 unchanged lines hidden --- | 134 if (off > need_off) { 135 p_err("Something is wrong for %s's variable #%d: need offset %d, already at %d.\n", 136 sec_name, i, need_off, off); 137 return -EINVAL; 138 } 139 140 align = btf__align_of(btf, var->type); 141 if (align <= 0) { --- 465 unchanged lines hidden --- |