Unified · Split
| @@ -2069,16 +2069,17 @@ static void bind_exe_dynsyms(TCCState *s1) · 2068 unmodified lines | ||
| 2069 | 2069 | } |
| 2070 | 2070 | } |
| 2071 | 2071 | |
| 2072 | −/* Bind symbols of libraries: export non local symbols of executable that | |
| 2073 | − resolve undefined symbols of shared libraries */ | |
| 2072 | +/* Bind symbols of libraries: export all non local symbols of executable that | |
| 2073 | + are referenced by shared libraries. The reason is that the dynamic loader | |
| 2074 | + search symbol first in executable and then in libraries. Therefore a | |
| 2075 | + reference to a symbol already defined by a library can still be resolved by | |
| 2076 | + a symbol in the executable. */ | |
| 2074 | 2077 | static void bind_libs_dynsyms(TCCState *s1) |
| 2075 | 2078 | { |
| 2076 | 2079 | const char *name; |
| 2077 | 2080 | int sym_index; |
| 2078 | 2081 | ElfW(Sym) *sym, *esym; |
| 2079 | 2082 | |
| 2080 | − /* now look at unresolved dynamic symbols and export | |
| 2081 | − corresponding symbol */ | |
| 2082 | 2083 | for_each_elem(s1->dynsymtab_section, 1, esym, ElfW(Sym)) { |
| 2083 | 2084 | name = (char *) s1->dynsymtab_section->link->data + esym->st_name; |
| 2084 | 2085 | sym_index = find_elf_sym(symtab_section, name); |
| @@ -2096,7 +2097,10 @@ static void bind_libs_dynsyms(TCCState *s1) · 11 unmodified lines | ||
| 2096 | 2097 | } |
| 2097 | 2098 | } |
| 2098 | 2099 | |
| 2099 | −/* Export all non local symbols (for shared libraries) */ | |
| 2100 | +/* Export all non local symbols. This is used by shared libraries so that the | |
| 2101 | + non local symbols they define can resolve a reference in another shared | |
| 2102 | + library or in the executable. Correspondingly, it allows undefined local | |
| 2103 | + symbols to be resolved by other shared libraries or by the executable. */ | |
| 2100 | 2104 | static void export_global_syms(TCCState *s1) |
| 2101 | 2105 | { |
| 2102 | 2106 | int nb_syms, dynindex, index; |