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
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_PE930#ifdef TCC_TARGET_PE
930# ifdef TCC_IS_NATIVE931# 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);
tcc-doc.texi+8−3
@@ -333,9 +333,6 @@ Link your program with dynamic library libxxx.so or static library · 332 unmodified lines
333libxxx.a. The library is searched in the paths specified by the333libxxx.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
337Don't implicitly link with libc, the C runtime files, and libtcc1.
338
339@item -Bdir336@item -Bdir
340Set the path where the tcc internal libraries (and include files) can be337Set the path where the tcc internal libraries (and include files) can be
341found (default is @file{PREFIX/lib/tcc}).338found (default is @file{PREFIX/lib/tcc}).
@@ -357,6 +354,14 @@ opened with @code{dlopen()} needs to access executable symbols. · 15 unmodified lines
357@item -r354@item -r
358Generate an object file combining all input files.355Generate an object file combining all input files.
359 356
357@item -nostdlib
358Don't implicitly link with libc, the C runtime files, and libtcc1.
359
360@item -Wl,-nostdlib
361Don'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}
363and @env{LIBRARY_PATH} are searched.
364
360@item -Wl,-rpath=path365@item -Wl,-rpath=path
361Put custom search path for dynamic libraries into executable.366Put custom search path for dynamic libraries into executable.
362 367
tcc.c+2−1
@@ -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#endif134#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"
tcc.h+1−0
@@ -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 */

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