From bf692af31b93ca14b63211bd508b4b8bf1179b50 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Sat, 12 Nov 2016 23:16:03 +0800 Subject: [PATCH] Fix error logic for undefined reference in library Prior to this patch, an error would only be given when a library has an unresolved undefined symbol if there is no undefined reference for the same symbol in the executable itself. This patch changes the logic to check both that the executable has the symbol in its static symbol table *and* that it is defined to decide if the error path should be followed. --- tccelf.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tccelf.c b/tccelf.c index ac8fd0f2..9b019a2c 100644 --- a/tccelf.c +++ b/tccelf.c @@ -2077,14 +2077,13 @@ static void bind_libs_dynsyms(TCCState *s1) for_each_elem(s1->dynsymtab_section, 1, esym, ElfW(Sym)) { name = (char *) s1->dynsymtab_section->link->data + esym->st_name; sym_index = find_elf_sym(symtab_section, name); - if (sym_index) { - /* XXX: avoid adding a symbol if already present because of - -rdynamic ? */ - sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; - if (sym->st_shndx != SHN_UNDEF) - put_elf_sym(s1->dynsym, sym->st_value, sym->st_size, - sym->st_info, 0, sym->st_shndx, name); - } else if (esym->st_shndx == SHN_UNDEF) { + /* XXX: avoid adding a symbol if already present because of + -rdynamic ? */ + sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; + if (sym_index && sym->st_shndx != SHN_UNDEF) + put_elf_sym(s1->dynsym, sym->st_value, sym->st_size, sym->st_info, + 0, sym->st_shndx, name); + else if (esym->st_shndx == SHN_UNDEF) { /* weak symbols can stay undefined */ if (ELFW(ST_BIND)(esym->st_info) != STB_WEAK) tcc_warning("undefined dynamic symbol '%s'", name); -- 2.11.4.GIT