@@ -668,6 +668,7 @@ void *xdl_sym(void *handle, const char *symbol, size_t *symbol_size) {
668
668
* symbol name in .symtab lookup is match
669
669
* ---------------------- ---------------- --------
670
670
* abcd abc N
671
+ * abcd abcde N
671
672
* abcd abcd Y
672
673
* abcd.llvm.10190306339727611508 abc N
673
674
* abcd.llvm.10190306339727611508 abcd Y
@@ -678,17 +679,19 @@ void *xdl_sym(void *handle, const char *symbol, size_t *symbol_size) {
678
679
* abcd.__uniq.513291356003753 abcd.__uniq.513291356003753 Y
679
680
*/
680
681
// clang-format on
681
- static inline bool xdl_dsym_is_match (const char * str , const char * sym , size_t str_len ) {
682
- if (__predict_false (0 == str_len )) return false;
682
+ static inline bool xdl_dsym_is_match (const char * str , const char * sym , size_t sym_len ) {
683
+ size_t str_len = strlen (str );
684
+ if (0 == str_len ) return false;
683
685
684
- do {
685
- if (* str != * sym ) return __predict_false ('.' == * str && '\0' == * sym );
686
- str ++ ;
687
- sym ++ ;
688
- if ('\0' == * str ) break ;
689
- } while (0 != -- str_len );
690
-
691
- return true;
686
+ if (str_len < sym_len ) {
687
+ return false;
688
+ } else {
689
+ bool sym_len_match = (0 == memcmp (str , sym , sym_len ));
690
+ if (str_len == sym_len )
691
+ return sym_len_match ;
692
+ else // str_len > sym_len
693
+ return sym_len_match && (str [sym_len ] == '.' );
694
+ }
692
695
}
693
696
694
697
void * xdl_dsym (void * handle , const char * symbol , size_t * symbol_size ) {
@@ -705,12 +708,13 @@ void *xdl_dsym(void *handle, const char *symbol, size_t *symbol_size) {
705
708
706
709
// find symbol
707
710
if (NULL == self -> symtab ) return NULL ;
711
+ size_t symbol_len = strlen (symbol );
708
712
for (size_t i = 0 ; i < self -> symtab_cnt ; i ++ ) {
709
713
ElfW (Sym ) * sym = self -> symtab + i ;
710
714
711
715
if (!XDL_SYMTAB_IS_EXPORT_SYM (sym -> st_shndx )) continue ;
712
716
// if (0 != strncmp(self->strtab + sym->st_name, symbol, self->strtab_sz - sym->st_name)) continue;
713
- if (!xdl_dsym_is_match (self -> strtab + sym -> st_name , symbol , self -> strtab_sz - sym -> st_name )) continue ;
717
+ if (!xdl_dsym_is_match (self -> strtab + sym -> st_name , symbol , symbol_len )) continue ;
714
718
715
719
if (NULL != symbol_size ) * symbol_size = sym -> st_size ;
716
720
return (void * )(self -> load_bias + sym -> st_value );
0 commit comments