From 32c4df1497e887eb77f5663c7b656aad70475325 Mon Sep 17 00:00:00 2001 From: Detlef Riekenberg Date: Thu, 26 Oct 2023 17:51:30 +0200 Subject: [PATCH] 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 --- tccelf.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tccelf.c b/tccelf.c index 6f2fd6a4..0110152d 100644 --- a/tccelf.c +++ b/tccelf.c @@ -3554,9 +3554,9 @@ static void store_version(TCCState *s1, struct versym_info *v, char *dynstr) #endif } -/* load a DLL and all referenced DLLs. 'level = 0' means that the DLL - is referenced by the user (so it should be added as DT_NEEDED in - the generated ELF file) */ +/* load a library / DLL + 'level = 0' means that the DLL is referenced by the user + (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) { 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++) if (dt->d_tag == DT_RPATH) 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 = 0;