TCC treats -nostdlib and -Wl,-nostdlib as equivalent, but on other compilers which call a discrete linker, -nostdlib behaves as on tcc (not adding startfiles/libc/endfiles) by modifying the ld command line, but -Wl,-nostdlib adds -nostdlib to the ld cmdline, which stops the linker searching the default directories for libraries. --- libtcc.c | 5 +++-- tcc-doc.texi | 11 ++++++++--- tcc.c | 3 ++- tcc.h | 1 + 4 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/libtcc.c b/libtcc.c index 1c4b4a55..45133991 100644 --- a/libtcc.c +++ b/libtcc.c @@ -924,7 +924,8 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) return 0; } - tcc_add_library_path(s, CONFIG_TCC_LIBPATHS); + if (!s->nostdlib_paths) + tcc_add_library_path(s, CONFIG_TCC_LIBPATHS); #ifdef TCC_TARGET_PE # ifdef TCC_IS_NATIVE @@ -1383,7 +1384,7 @@ static int tcc_set_linker(TCCState *s, const char *option) if (link_option(option, "Bsymbolic", &p)) { s->symbolic = 1; } else if (link_option(option, "nostdlib", &p)) { - s->nostdlib = 1; + s->nostdlib_paths = 1; } else if (link_option(option, "e=", &p) || link_option(option, "entry=", &p)) { copy_linker_arg(&s->elf_entryname, p, 0); diff --git a/tcc-doc.texi b/tcc-doc.texi index 47acb528..d9df2d1a 100644 --- a/tcc-doc.texi +++ b/tcc-doc.texi @@ -333,9 +333,6 @@ Link your program with dynamic library libxxx.so or static library libxxx.a. The library is searched in the paths specified by the @option{-L} option and @env{LIBRARY_PATH} variable. -@item -nostdlib -Don't implicitly link with libc, the C runtime files, and libtcc1. - @item -Bdir Set the path where the tcc internal libraries (and include files) can be found (default is @file{PREFIX/lib/tcc}). @@ -357,6 +354,14 @@ opened with @code{dlopen()} needs to access executable symbols. @item -r Generate an object file combining all input files. +@item -nostdlib +Don't implicitly link with libc, the C runtime files, and libtcc1. + +@item -Wl,-nostdlib +Don't search the default paths for libraries (@file{/usr/local/lib}, +@file{/usr/lib} and @file{/lib}). Only the paths specified with @option{-L} +and @env{LIBRARY_PATH} are searched. + @item -Wl,-rpath=path Put custom search path for dynamic libraries into executable. diff --git a/tcc.c b/tcc.c index abe1a70a..9b400e71 100644 --- a/tcc.c +++ b/tcc.c @@ -98,6 +98,7 @@ static const char help2[] = " -On same as -D__OPTIMIZE__ for n > 0\n" " -Wp,-opt same as -opt\n" " -include file include 'file' above each input file\n" + " -nostdlib do not link with standard crt/libs\n" " -isystem dir add 'dir' to system include path\n" " -static link to static libraries (not recommended)\n" " -dumpversion print version\n" @@ -132,7 +133,7 @@ static const char help2[] = " no-sse disable floats on x86_64\n" #endif "-Wl,... linker options:\n" - " -nostdlib do not link with standard crt/libs\n" + " -nostdlib do not search standard library paths\n" " -[no-]whole-archive load lib(s) fully/only as needed\n" " -export-all-symbols same as -rdynamic\n" " -export-dynamic same as -rdynamic\n" diff --git a/tcc.h b/tcc.h index 44da52f1..fc4d1b6a 100644 --- a/tcc.h +++ b/tcc.h @@ -729,6 +729,7 @@ struct TCCState { unsigned char verbose; /* if true, display some information during compilation */ unsigned char nostdinc; /* if true, no standard headers are added */ unsigned char nostdlib; /* if true, no standard libraries are added */ + unsigned char nostdlib_paths; /* if true, the default paths are not searched for libraries */ unsigned char nocommon; /* if true, do not use common symbols for .bss data */ unsigned char static_link; /* if true, static linking is performed */ unsigned char rdynamic; /* if true, all symbols are exported */ -- 2.48.1 _______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel