Hello,

On Sat, 23 Sep 2023, grischka wrote:

 That would be correct, when the target is TCC_OUTPUT_MEMORY
 but i think, in all other cases, tcc should not do that.

I'd suggest to use "grep -nrw tcc_load_dll ." for example.  There is
only one place from where tcc_load_dll() is called:

in libtcc.c:tcc_add_file_internal():

        case AFF_BINTYPE_DYN:
           if (s1->output_type == TCC_OUTPUT_MEMORY) {
#ifdef TCC_IS_NATIVE
                void* dl = dlopen(filename, RTLD_GLOBAL | RTLD_LAZY);
                if (dl)
                   tcc_add_dllref(s1, filename, 0)->handle = dl, ret = 0;
#endif
            } else
                ret = tcc_load_dll(s1, fd, filename, (flags &
            AFF_REFERENCED_DLL) != 0);
            break;

So, for TCC_OUTPUT_MEMORY, tcc does not use tcc_load_dll(),  It calls
"dlopen()" instead.  Where dlopen() would invoke the dynamic linker
(ld.so) and that one then would take care to load any dependencies
(DT_NEEDED tags).

TLDR: the recursive load_dll can be removed.

Long variant:

This all is simply the old way of linking against dynamic libs in the binutils ELF linker. TCC currently does like binutils ld would do with --copy-dt-needed-entries, which once was the only way, and after introduction of that option was the default for some more time. Eventually the default was switched, most software was fixed to work in the new mode (some did break with this change!), and now TCC could switch as well. The behaviour was changed because the new one resembles how linking against static archives works (which don't have dependencies), and consistency between static and dynamic linking is a good thing.

I.e. TCC doesn't need to traverse DT_NEEDED entries of cmdline-mentioned shared libs anymore, it can ignore them while link-editing and have the same behaviour like most other current ELF linkers.

(Of course that just means that the error that now is spit out by TCC while link-editing, needs to be solved in a different way by the build-system or latest at runtime. If TCC can't find foobar.so from DT_NEEDED, then the dynamic linker will also not find it without help, e.g. when the build system uses LD_LIBRARY_PATH, -runpath or other such means, or simply doesn't run uninstalled binaries requiring uninstalled libs (i.e. requires all of these to be installed). ncurses indeed doesn't have that problem)


Ciao,
Michael.

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

Reply via email to