History

Fix -Wl,-nostdlib behaviour for compatibility with other compilers

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.

remph committed 1 year ago

Commit 1747b451 parent ec60d284 files · +14 −6Browse files

Unified · Split

4 files
  1. libtcc.c +3 −2
  2. tcc-doc.texi +8 −3
  3. tcc.c +2 −1
  4. tcc.h +1 −0
libtcc.c+3−2
@@ -924,7 +924,8 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 923 unmodified lines
924924 return 0;
925925 }
926926
927− tcc_add_library_path(s, CONFIG_TCC_LIBPATHS);
927+ if (!s->nostdlib_paths)
928+ tcc_add_library_path(s, CONFIG_TCC_LIBPATHS);
928929
929930 #ifdef TCC_TARGET_PE
930931 # ifdef TCC_IS_NATIVE
@@ -1383,7 +1384,7 @@ static int tcc_set_linker(TCCState *s, const char *option) · 452 unmodified lines
13831384 if (link_option(option, "Bsymbolic", &p)) {
13841385 s->symbolic = 1;
13851386 } else if (link_option(option, "nostdlib", &p)) {
1386− s->nostdlib = 1;
1387+ s->nostdlib_paths = 1;
13871388 } else if (link_option(option, "e=", &p)
13881389 || link_option(option, "entry=", &p)) {
13891390 copy_linker_arg(&s->elf_entryname, p, 0);
tcc-doc.texi+8−3
@@ -333,9 +333,6 @@ Link your program with dynamic library libxxx.so or static library · 332 unmodified lines
333333 libxxx.a. The library is searched in the paths specified by the
334334 @option{-L} option and @env{LIBRARY_PATH} variable.
335335
336−@item -nostdlib
337−Don't implicitly link with libc, the C runtime files, and libtcc1.
338−
339336 @item -Bdir
340337 Set the path where the tcc internal libraries (and include files) can be
341338 found (default is @file{PREFIX/lib/tcc}).
@@ -357,6 +354,14 @@ opened with @code{dlopen()} needs to access executable symbols. · 15 unmodified lines
357354 @item -r
358355 Generate an object file combining all input files.
359356
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+
360365 @item -Wl,-rpath=path
361366 Put custom search path for dynamic libraries into executable.
362367
tcc.c+2−1
@@ -98,6 +98,7 @@ static const char help2[] = · 97 unmodified lines
9898 " -On same as -D__OPTIMIZE__ for n > 0\n"
9999 " -Wp,-opt same as -opt\n"
100100 " -include file include 'file' above each input file\n"
101+ " -nostdlib do not link with standard crt/libs\n"
101102 " -isystem dir add 'dir' to system include path\n"
102103 " -static link to static libraries (not recommended)\n"
103104 " -dumpversion print version\n"
@@ -132,7 +133,7 @@ static const char help2[] = · 28 unmodified lines
132133 " no-sse disable floats on x86_64\n"
133134 #endif
134135 "-Wl,... linker options:\n"
135− " -nostdlib do not link with standard crt/libs\n"
136+ " -nostdlib do not search standard library paths\n"
136137 " -[no-]whole-archive load lib(s) fully/only as needed\n"
137138 " -export-all-symbols same as -rdynamic\n"
138139 " -export-dynamic same as -rdynamic\n"
tcc.h+1−0
@@ -729,6 +729,7 @@ struct TCCState { · 728 unmodified lines
729729 unsigned char verbose; /* if true, display some information during compilation */
730730 unsigned char nostdinc; /* if true, no standard headers are added */
731731 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 */
732733 unsigned char nocommon; /* if true, do not use common symbols for .bss data */
733734 unsigned char static_link; /* if true, static linking is performed */
734735 unsigned char rdynamic; /* if true, all symbols are exported */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t