@@ -97,14 +97,14 @@ struct btf_encoder_func_state {
9797struct elf_function_sym {
9898 const char * name ;
9999 uint64_t addr ;
100- uint8_t non_fn :1 ;
101100};
102101
103102struct elf_function {
104103 char * name ;
105104 struct elf_function_sym * syms ;
106105 uint16_t sym_cnt ;
107- uint8_t kfunc :1 ;
106+ uint16_t ambiguous_addr :1 ;
107+ uint16_t kfunc :1 ;
108108 uint32_t kfunc_flags ;
109109};
110110
@@ -168,7 +168,7 @@ struct btf_kfunc_set_range {
168168 uint64_t end ;
169169};
170170
171- static inline void elf_function__free_content (struct elf_function * func )
171+ static inline void elf_function__clear (struct elf_function * func )
172172{
173173 free (func -> name );
174174 if (func -> sym_cnt )
@@ -179,7 +179,7 @@ static inline void elf_function__free_content(struct elf_function *func)
179179static inline void elf_functions__delete (struct elf_functions * funcs )
180180{
181181 for (int i = 0 ; i < funcs -> cnt ; i ++ )
182- elf_function__free_content (& funcs -> entries [i ]);
182+ elf_function__clear (& funcs -> entries [i ]);
183183 free (funcs -> entries );
184184 elf_symtab__delete (funcs -> symtab );
185185 free (funcs );
@@ -1214,21 +1214,20 @@ static bool str_contains_non_fn_suffix(const char *str) {
12141214static bool elf_function__has_ambiguous_address (struct elf_function * func )
12151215{
12161216 struct elf_function_sym * sym ;
1217- uint64_t addr = 0 ;
1218- int i ;
1217+ uint64_t addr ;
12191218
12201219 if (func -> sym_cnt <= 1 )
12211220 return false;
12221221
1223- for (i = 0 ; i < func -> sym_cnt ; i ++ ) {
1222+ addr = 0 ;
1223+ for (int i = 0 ; i < func -> sym_cnt ; i ++ ) {
12241224 sym = & func -> syms [i ];
1225- if (!sym -> non_fn ) {
1226- if (addr && addr != sym -> addr )
1227- return true;
1228- else
1229- addr = sym -> addr ;
1230- }
1225+ if (addr && addr != sym -> addr )
1226+ return true;
1227+ else
1228+ addr = sym -> addr ;
12311229 }
1230+
12321231 return false;
12331232}
12341233
@@ -1247,7 +1246,6 @@ static int32_t btf_encoder__save_func(struct btf_encoder *encoder, struct functi
12471246
12481247 state -> encoder = encoder ;
12491248 state -> elf = func ;
1250- state -> ambiguous_addr = elf_function__has_ambiguous_address (func );
12511249 state -> nr_parms = ftype -> nr_parms + (ftype -> unspec_parms ? 1 : 0 );
12521250 state -> ret_type_id = ftype -> tag .type == 0 ? 0 : encoder -> type_id_off + ftype -> tag .type ;
12531251 if (state -> nr_parms > 0 ) {
@@ -1414,7 +1412,7 @@ static int saved_functions_cmp(const void *_a, const void *_b)
14141412
14151413static int saved_functions_combine (struct btf_encoder_func_state * a , struct btf_encoder_func_state * b )
14161414{
1417- uint8_t optimized , unexpected , inconsistent , uncertain_parm_loc , ambiguous_addr ;
1415+ uint8_t optimized , unexpected , inconsistent , uncertain_parm_loc ;
14181416
14191417 if (a -> elf != b -> elf )
14201418 return 1 ;
@@ -1423,14 +1421,12 @@ static int saved_functions_combine(struct btf_encoder_func_state *a, struct btf_
14231421 unexpected = a -> unexpected_reg | b -> unexpected_reg ;
14241422 inconsistent = a -> inconsistent_proto | b -> inconsistent_proto ;
14251423 uncertain_parm_loc = a -> uncertain_parm_loc | b -> uncertain_parm_loc ;
1426- ambiguous_addr = a -> ambiguous_addr | b -> ambiguous_addr ;
1427- if (!unexpected && !inconsistent && !ambiguous_addr && !funcs__match (a , b ))
1424+ if (!unexpected && !inconsistent && !funcs__match (a , b ))
14281425 inconsistent = 1 ;
14291426 a -> optimized_parms = b -> optimized_parms = optimized ;
14301427 a -> unexpected_reg = b -> unexpected_reg = unexpected ;
14311428 a -> inconsistent_proto = b -> inconsistent_proto = inconsistent ;
14321429 a -> uncertain_parm_loc = b -> uncertain_parm_loc = uncertain_parm_loc ;
1433- a -> ambiguous_addr = b -> ambiguous_addr = ambiguous_addr ;
14341430
14351431 return 0 ;
14361432}
@@ -1484,7 +1480,7 @@ static int btf_encoder__add_saved_funcs(struct btf_encoder *encoder, bool skip_e
14841480 * unexpected register use, multiple inconsistent prototypes or
14851481 * uncertain parameters location
14861482 */
1487- add_to_btf |= !state -> unexpected_reg && !state -> inconsistent_proto && !state -> uncertain_parm_loc && !state -> ambiguous_addr ;
1483+ add_to_btf |= !state -> unexpected_reg && !state -> inconsistent_proto && !state -> uncertain_parm_loc && !state -> elf -> ambiguous_addr ;
14881484
14891485 if (state -> uncertain_parm_loc )
14901486 btf_encoder__log_func_skip (encoder , saved_fns [i ].elf ,
@@ -2216,9 +2212,11 @@ static int elf_functions__collect(struct elf_functions *functions)
22162212 if (!sym_name )
22172213 continue ;
22182214
2219- func = & functions -> entries [functions -> cnt ];
2220-
22212215 suffix = strchr (sym_name , '.' );
2216+ if (str_contains_non_fn_suffix (sym_name ))
2217+ continue ;
2218+
2219+ func = & functions -> entries [functions -> cnt ];
22222220 if (suffix )
22232221 func -> name = strndup (sym_name , suffix - sym_name );
22242222 else
@@ -2231,7 +2229,7 @@ static int elf_functions__collect(struct elf_functions *functions)
22312229
22322230 func_sym .name = sym_name ;
22332231 func_sym .addr = sym .st_value ;
2234- func_sym . non_fn = str_contains_non_fn_suffix ( sym_name );
2232+
22352233 err = elf_function__push_sym (func , & func_sym );
22362234 if (err )
22372235 goto out_free ;
@@ -2259,8 +2257,11 @@ static int elf_functions__collect(struct elf_functions *functions)
22592257
22602258 if (!strcmp (a -> name , b -> name )) {
22612259 elf_function__push_sym (a , & b -> syms [0 ]);
2262- elf_function__free_content (b );
2260+ elf_function__clear (b );
22632261 } else {
2262+ // at this point all syms for `a` have been collected
2263+ // check for ambiguous addresses before moving on
2264+ a -> ambiguous_addr = elf_function__has_ambiguous_address (a );
22642265 i ++ ;
22652266 if (i != j )
22662267 functions -> entries [i ] = functions -> entries [j ];
0 commit comments