Skip to content

Commit

Permalink
tccelf: Do not load all referenced libraries when linking a library
Browse files Browse the repository at this point in the history
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
  • Loading branch information
winspool committed Oct 26, 2023
1 parent 6b967b1 commit 32c4df1
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tccelf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -3666,6 +3674,7 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level)
}
}
}
#endif

ret_success:
ret = 0;
Expand Down

0 comments on commit 32c4df1

Please sign in to comment.