tccelf: Do not load all referenced libraries when linking a library

Recursive loading of all references can break linking of libraries
(Example: building of netbsd-curses)

Thanks grischka, Michael and Herman for the comments.

--
Regards ... Detlef
This commit is contained in:
Detlef Riekenberg 2023-10-26 17:51:30 +02:00 committed by Detlef Riekenberg
parent 6b967b1285
commit 32c4df1497

View file

@ -3554,9 +3554,9 @@ static void store_version(TCCState *s1, struct versym_info *v, char *dynstr)
#endif #endif
} }
/* load a DLL and all referenced DLLs. 'level = 0' means that the DLL /* load a library / DLL
is referenced by the user (so it should be added as DT_NEEDED in 'level = 0' means that the DLL is referenced by the user
the generated ELF file) */ (so it should be added as DT_NEEDED in the generated ELF file) */
ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level)
{ {
ElfW(Ehdr) ehdr; ElfW(Ehdr) ehdr;
@ -3649,6 +3649,14 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level)
} }
} }
/* do not load all referenced libraries
(recursive loading can break linking of libraries) */
/* following DT_NEEDED is needed for the dynamic loader (libdl.so),
but it is no longer needed, when linking a library or a program.
When tcc output mode is OUTPUT_MEM,
tcc calls dlopen, which handles DT_NEEDED for us */
#if 0
for(i = 0, dt = dynamic; i < nb_dts; i++, dt++) for(i = 0, dt = dynamic; i < nb_dts; i++, dt++)
if (dt->d_tag == DT_RPATH) if (dt->d_tag == DT_RPATH)
tcc_add_library_path(s1, dynstr + dt->d_un.d_val); tcc_add_library_path(s1, dynstr + dt->d_un.d_val);
@ -3666,6 +3674,7 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level)
} }
} }
} }
#endif
ret_success: ret_success:
ret = 0; ret = 0;