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.
Unified · Split
| @@ -924,7 +924,8 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 923 unmodified lines | |||
| 924 | return 0; | 924 | return 0; |
| 925 | } | 925 | } |
| 926 | 926 | ||
| 927 | tcc_add_library_path(s, CONFIG_TCC_LIBPATHS); | 927 | if (!s->nostdlib_paths) |
| 928 | tcc_add_library_path(s, CONFIG_TCC_LIBPATHS); | ||
| 928 | 929 | ||
| 929 | #ifdef TCC_TARGET_PE | 930 | #ifdef TCC_TARGET_PE |
| 930 | # ifdef TCC_IS_NATIVE | 931 | # ifdef TCC_IS_NATIVE |
| @@ -1383,7 +1384,7 @@ static int tcc_set_linker(TCCState *s, const char *option) · 452 unmodified lines | |||
| 1383 | if (link_option(option, "Bsymbolic", &p)) { | 1384 | if (link_option(option, "Bsymbolic", &p)) { |
| 1384 | s->symbolic = 1; | 1385 | s->symbolic = 1; |
| 1385 | } else if (link_option(option, "nostdlib", &p)) { | 1386 | } else if (link_option(option, "nostdlib", &p)) { |
| 1386 | s->nostdlib = 1; | 1387 | s->nostdlib_paths = 1; |
| 1387 | } else if (link_option(option, "e=", &p) | 1388 | } else if (link_option(option, "e=", &p) |
| 1388 | || link_option(option, "entry=", &p)) { | 1389 | || link_option(option, "entry=", &p)) { |
| 1389 | copy_linker_arg(&s->elf_entryname, p, 0); | 1390 | copy_linker_arg(&s->elf_entryname, p, 0); |
| @@ -333,9 +333,6 @@ Link your program with dynamic library libxxx.so or static library · 332 unmodified lines | |||
| 333 | libxxx.a. The library is searched in the paths specified by the | 333 | libxxx.a. The library is searched in the paths specified by the |
| 334 | @option{-L} option and @env{LIBRARY_PATH} variable. | 334 | @option{-L} option and @env{LIBRARY_PATH} variable. |
| 335 | 335 | ||
| 336 | @item -nostdlib | ||
| 337 | Don't implicitly link with libc, the C runtime files, and libtcc1. | ||
| 338 | |||
| 339 | @item -Bdir | 336 | @item -Bdir |
| 340 | Set the path where the tcc internal libraries (and include files) can be | 337 | Set the path where the tcc internal libraries (and include files) can be |
| 341 | found (default is @file{PREFIX/lib/tcc}). | 338 | found (default is @file{PREFIX/lib/tcc}). |
| @@ -357,6 +354,14 @@ opened with @code{dlopen()} needs to access executable symbols. · 15 unmodified lines | |||
| 357 | @item -r | 354 | @item -r |
| 358 | Generate an object file combining all input files. | 355 | Generate an object file combining all input files. |
| 359 | 356 | ||
| 357 | @item -nostdlib | ||
| 358 | Don't implicitly link with libc, the C runtime files, and libtcc1. | ||
| 359 | |||
| 360 | @item -Wl,-nostdlib | ||
| 361 | Don't search the default paths for libraries (@file{/usr/local/lib}, | ||
| 362 | @file{/usr/lib} and @file{/lib}). Only the paths specified with @option{-L} | ||
| 363 | and @env{LIBRARY_PATH} are searched. | ||
| 364 | |||
| 360 | @item -Wl,-rpath=path | 365 | @item -Wl,-rpath=path |
| 361 | Put custom search path for dynamic libraries into executable. | 366 | Put custom search path for dynamic libraries into executable. |
| 362 | 367 | ||
| @@ -98,6 +98,7 @@ static const char help2[] = · 97 unmodified lines | |||
| 98 | " -On same as -D__OPTIMIZE__ for n > 0\n" | 98 | " -On same as -D__OPTIMIZE__ for n > 0\n" |
| 99 | " -Wp,-opt same as -opt\n" | 99 | " -Wp,-opt same as -opt\n" |
| 100 | " -include file include 'file' above each input file\n" | 100 | " -include file include 'file' above each input file\n" |
| 101 | " -nostdlib do not link with standard crt/libs\n" | ||
| 101 | " -isystem dir add 'dir' to system include path\n" | 102 | " -isystem dir add 'dir' to system include path\n" |
| 102 | " -static link to static libraries (not recommended)\n" | 103 | " -static link to static libraries (not recommended)\n" |
| 103 | " -dumpversion print version\n" | 104 | " -dumpversion print version\n" |
| @@ -132,7 +133,7 @@ static const char help2[] = · 28 unmodified lines | |||
| 132 | " no-sse disable floats on x86_64\n" | 133 | " no-sse disable floats on x86_64\n" |
| 133 | #endif | 134 | #endif |
| 134 | "-Wl,... linker options:\n" | 135 | "-Wl,... linker options:\n" |
| 135 | " -nostdlib do not link with standard crt/libs\n" | 136 | " -nostdlib do not search standard library paths\n" |
| 136 | " -[no-]whole-archive load lib(s) fully/only as needed\n" | 137 | " -[no-]whole-archive load lib(s) fully/only as needed\n" |
| 137 | " -export-all-symbols same as -rdynamic\n" | 138 | " -export-all-symbols same as -rdynamic\n" |
| 138 | " -export-dynamic same as -rdynamic\n" | 139 | " -export-dynamic same as -rdynamic\n" |
| @@ -729,6 +729,7 @@ struct TCCState { · 728 unmodified lines | |||
| 729 | unsigned char verbose; /* if true, display some information during compilation */ | 729 | unsigned char verbose; /* if true, display some information during compilation */ |
| 730 | unsigned char nostdinc; /* if true, no standard headers are added */ | 730 | unsigned char nostdinc; /* if true, no standard headers are added */ |
| 731 | unsigned char nostdlib; /* if true, no standard libraries are added */ | 731 | unsigned char nostdlib; /* if true, no standard libraries are added */ |
| 732 | unsigned char nostdlib_paths; /* if true, the default paths are not searched for libraries */ | ||
| 732 | unsigned char nocommon; /* if true, do not use common symbols for .bss data */ | 733 | unsigned char nocommon; /* if true, do not use common symbols for .bss data */ |
| 733 | unsigned char static_link; /* if true, static linking is performed */ | 734 | unsigned char static_link; /* if true, static linking is performed */ |
| 734 | unsigned char rdynamic; /* if true, all symbols are exported */ | 735 | unsigned char rdynamic; /* if true, all symbols are exported */ |