History

Add -Wl,-I and -Wl,-dynamic-linker options

Compatible with ld.bfd, gold, lld and mold. Also, document existing behaviour of LD_SO environment variable

remph committed 1 year ago

Commit ec60d281 parent f8bd1365 files · +18 −1Browse files

Unified · Split

5 files
  1. libtcc.c +7 −0
  2. tcc-doc.texi +5 −0
  3. tcc.c +2 −0
  4. tcc.h +1 −0
  5. tccelf.c +3 −1
libtcc.c+7−0
@@ -1428,6 +1428,13 @@ static int tcc_set_linker(TCCState *s, const char *option) · 1427 unmodified lines
1428 s->rdynamic = 1;1428 s->rdynamic = 1;
1429 } else if (link_option(option, "rpath=", &p)) {1429 } else if (link_option(option, "rpath=", &p)) {
1430 copy_linker_arg(&s->rpath, p, ':');1430 copy_linker_arg(&s->rpath, p, ':');
1431 } else if (link_option(option, "dynamic-linker=", &p)
1432 || link_option(option, "I=", &p)) {
1433 copy_linker_arg(&s->elfint, p, 0);
1434 } else if (strncmp("-I/", option, 3) == 0
1435 || strncmp("-I.", option, 3) == 0) {
1436 p = option;
1437 copy_linker_arg(&s->elfint, option + 2, 0);
1431 } else if (link_option(option, "enable-new-dtags", &p)) {1438 } else if (link_option(option, "enable-new-dtags", &p)) {
1432 s->enable_new_dtags = 1;1439 s->enable_new_dtags = 1;
1433 } else if (link_option(option, "section-alignment=", &p)) {1440 } else if (link_option(option, "section-alignment=", &p)) {
tcc-doc.texi+5−0
@@ -360,6 +360,11 @@ Generate an object file combining all input files. · 359 unmodified lines
360@item -Wl,-rpath=path360@item -Wl,-rpath=path
361Put custom search path for dynamic libraries into executable.361Put custom search path for dynamic libraries into executable.
362 362
363@item -Wl,-Ipath
364@item -Wl,--dynamic-linker=path
365Set the ELF interpreter (dynamic linker). This defaults to the value of the
366environment variable @env{LD_SO} if set, or a compiled-in default.
367
363@item -Wl,--enable-new-dtags368@item -Wl,--enable-new-dtags
364When putting a custom search path for dynamic libraries into the executable,369When putting a custom search path for dynamic libraries into the executable,
365create the new ELF dynamic tag DT_RUNPATH instead of the old legacy DT_RPATH.370create the new ELF dynamic tag DT_RUNPATH instead of the old legacy DT_RPATH.
tcc.c+2−0
@@ -152,6 +152,8 @@ static const char help2[] = · 151 unmodified lines
152 " -soname= set DT_SONAME elf tag\n"152 " -soname= set DT_SONAME elf tag\n"
153#if defined(TCC_TARGET_MACHO)153#if defined(TCC_TARGET_MACHO)
154 " -install_name= set DT_SONAME elf tag (soname macOS alias)\n"154 " -install_name= set DT_SONAME elf tag (soname macOS alias)\n"
155#else
156 " -Ipath, -dynamic-linker=path set ELF interpreter to path"
155#endif157#endif
156 " -Bsymbolic set DT_SYMBOLIC elf tag\n"158 " -Bsymbolic set DT_SYMBOLIC elf tag\n"
157 " -oformat=[elf32/64-* binary] set executable output format\n"159 " -oformat=[elf32/64-* binary] set executable output format\n"
tcc.h+1−0
@@ -802,6 +802,7 @@ struct TCCState { · 801 unmodified lines
802 char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */802 char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */
803 char *soname; /* as specified on the command line (-soname) */803 char *soname; /* as specified on the command line (-soname) */
804 char *rpath; /* as specified on the command line (-Wl,-rpath=) */804 char *rpath; /* as specified on the command line (-Wl,-rpath=) */
805 char *elfint; /* -Wl,-I on command line, LD_SO in environment, or DEFAULT_ELFINTERP(this) */
805 char *elf_entryname; /* "_start" unless set */806 char *elf_entryname; /* "_start" unless set */
806 char *init_symbol; /* symbols to call at load-time (not used currently) */807 char *init_symbol; /* symbols to call at load-time (not used currently) */
807 char *fini_symbol; /* symbols to call at unload-time (not used currently) */808 char *fini_symbol; /* symbols to call at unload-time (not used currently) */
tccelf.c+3−1
@@ -2850,7 +2850,9 @@ static int elf_output_file(TCCState *s1, const char *filename) · 2849 unmodified lines
2850 if (file_type & TCC_OUTPUT_EXE) {2850 if (file_type & TCC_OUTPUT_EXE) {
2851 char *ptr;2851 char *ptr;
2852 /* allow override the dynamic loader */2852 /* allow override the dynamic loader */
2853 const char *elfint = getenv("LD_SO");2853 const char *elfint = s1->elfint;
2854 if (elfint == NULL)
2855 elfint = getenv("LD_SO");
2854 if (elfint == NULL)2856 if (elfint == NULL)
2855 elfint = DEFAULT_ELFINTERP(s1);2857 elfint = DEFAULT_ELFINTERP(s1);
2856 /* add interpreter section only if executable */2858 /* add interpreter section only if executable */

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