Le mardi 14 avril 2015, 15:46:28 Michael Matz a écrit :
> Hi,

Hi Michael,

> >
> > Nope. Try it for yourself:
> Huh, indeed.  IMHO that's inconsistent with the symbol resolution
> behaviour of GNU ld (only looking in level0 libs for symbols, not in those
> DT_NEEDED by them, unless --copy-dt-needed-entries is active), but so be
> it.

I did the test with gcc so I was describing ld's behavior. Ld will export
everything that solve an exported symbol in any library. Note that I'm only
talking about what symbols are exported in the program, not what DT_NEEDED are
added. DT_NEEDED are added based on -lfoo specified on the command line, even
if no symbol is used as shown with the following setup:

% cat foo.c
int
foo (void)
{
  return 0;
}


% cat main.c
int
main (void)
{
  return 0;
}

Compile foo.c as libfoo.so and make main with main.c and -lfoo and you'll see
a DT_NEEDED added. If libfoo.so were to depend on another library this is not
added to the program (only library explicitely linked are added). I believe
that's what tcc does, but I didn't check.

>
> > Thanks for teaching me, I really appreciate. It seems that despite what
> > you told, you understand tcc's linker at least as well as me. Anyway, if
> > you don't mind I'd still like to be the one to improve its organisation.
> > I'll appreciate any review of my changes though.

Got a patch and would appreciate some feedback. Only tested on x86-64 so far
[1] so I would also appreciate testing on other targets (even i386).

[1] I know it's a shame, but my desktop machine is (still) an x86_64 so it's
easier to test this one. I'll give it a try on my AC100 (ARMv7-a) later in the
week but I'm hoping Christian and/or Edmund can give the patch a try.

Best regards,

Thomas
diff --git a/tccelf.c b/tccelf.c
index b9ca8b7..2c6f349 100644
--- a/tccelf.c
+++ b/tccelf.c
@@ -1875,20 +1875,19 @@ static void bind_libs_dynsyms(TCCState *s1)
     /* now look at unresolved dynamic symbols and export
        corresponding symbol */
     for_each_elem(s1->dynsymtab_section, 1, esym, ElfW(Sym)) {
-        if (esym->st_shndx == SHN_UNDEF) {
-            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];
+        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 {
-                /* weak symbols can stay undefined */
-                if (ELFW(ST_BIND)(esym->st_info) != STB_WEAK)
-                    tcc_warning("undefined dynamic symbol '%s'", 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);
         }
     }
 }

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to